New User Special Price Expires in

Let's log you in.

Sign in with Facebook


Don't have a StudySoup account? Create one here!


Create a StudySoup account

Be part of our community, it's free to join!

Sign up with Facebook


Create your account
By creating an account you agree to StudySoup's terms and conditions and privacy policy

Already have a StudySoup account? Login here

Mechatronic Systems

by: Halie Berge

Mechatronic Systems ME 430

Halie Berge
GPA 3.79

David Fisher

Almost Ready


These notes were just uploaded, and will be ready to view shortly.

Purchase these notes here, or revisit this page.

Either way, we'll remind you when they're ready :)

Preview These Notes for FREE

Get a free preview of these Notes, just enter your email below.

Unlock Preview
Unlock Preview

Preview these materials now for free

Why put in your email? Get access to more of this material and other relevant free materials for your school

View Preview

About this Document

David Fisher
Class Notes
25 ?




Popular in Course

Popular in Mechanical Engineering

This 5 page Class Notes was uploaded by Halie Berge on Monday October 19, 2015. The Class Notes belongs to ME 430 at Rose-Hulman Institute of Technology taught by David Fisher in Fall. Since its upload, it has received 10 views. For similar materials see /class/225094/me-430-rose-hulman-institute-of-technology in Mechanical Engineering at Rose-Hulman Institute of Technology.


Reviews for Mechatronic Systems


Report this Material


What is Karma?


Karma is the currency of StudySoup.

You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!

Date Created: 10/19/15
ME430 Mechatronic Systems Using the Timer Peripheral Timers are a PIC peripheral function that can run in the background without interfering with the rest of the program Other peripherals we ll use include the PWM peripheral and ADC peripheral On the 18F4520 there are 4 timers that you can use which run via hardware in the background These timers are numbered TimerO Timerl Timer2 Timer3 Timers 0 1 and 3 are 16 bit timers that store a int value that counts from 0 to 65535 You can setup the timer using the timerh library functions In this example code I setup the timer 0 zero Setup the timer with a 14 prescaler with 16 bits resolution Therefore the timerO freq is clock frequency 4 4 OpenTimer0 TIMERilNTioFF amp T0716BIT amp ToisOURCEilNT amp T033474 There is only one line of code there and the rest are comments note for big commands you can go to the next line without any problems In much the same way that the instruction cycle frequency runs slower than the clock frequency the timer frequency can run slower than the instruction cycle frequency The instruction cycle is always 14th of the clock frequency but the timer can be setup to different values Table 1 Timer Prescaler Options Library con g Statement Divides the instruction cycle frequency by how much ToiPsilil 11 prescale T07P87172 12 prescale ToiPsilitl 14 prescale T07P87178 18 prescale T07P871716 116 prescale T07P871732 132 prescale T07P571764 164 prescale ToiPsililZS 1128 prescale T07P5717256 1256 prescale So for the example code earlier we used T035374 So that made Timer 0 run at 14th the speed of the instruction cycle The timer frequency slow down can be set to many di erent values This can be handy for keeping the instruction cycle frequency very fast but still timing things that are slow a subtle but key difference The library functions do an excellent job of making the timers very easy to use Go look at the C18 library section 29 If you look at the example code below you can see some of the commands that might get used with a timer This is not a complete program but it shows you some of the timer commands 292 Example of Use include ltp18F4520hgt include lttimershgt void main void T int result ADCONl OXOF A configure timerO OpenTimer0 TIMERilNTiOFF amp ToisOURCEilNT amp T07P571732 while 1 l whilePORTAbitsRA4 Wait for RA4 to get pushed result ReadTimer0 read timer could send the result to the LCD WriteTimer0 0 restart timer l CloseTimer0 Close modules For an example with a complete program you can download Timers Democ off the course website That code is also shown on the next few pages FileName timer democ Processor PIC18F4520 Compiler MPLAB C18 v306 gtxlt This le displays the timer 0 on the PICDEM 2 LCD screen gtxlt As a bonus it increments the PORTB LEDs using an interrupt when the timer over ows gtxlt Author Date Comment WWWWWWWWWWNWWM David Fisher10307 Processor Header Files include ltp18f4520hgt include quotPICDEM 2 LCD modulehquot include ltstdiohgt include lttimershgt De ne Constants Here de ne delayTime 100 Local Function Prototypes void lowiisrvoid void highiisrvoid Configuration Bits For details on PIC18F con guration bit settings see PIC18 Con guration Settings in MPLABIDE Help pragma con g OSC EC EXtemal 4MHz crystal necessary for LCD pragma con g WDT OFF pragma con g LVP OFF pragma con g BOREN OFF gtxltgtxlt Declare Interrupt Vector sections gtk pragma code highivector0X08 void interruptiatihighivectorvoid iasm goto highiisr iendasm pragma code lowivector0Xl 8 void interruptiatilowivectorvoid iasm goto lowiisr iendasm Global Variables char tempString5 char linel quotTimer 0 readingquot unsigned int result Function void mainvoid pragma code void main void ADCONl OXOF TRISB OXFO PORTB 0X00 LCDInit DisplayClr LCDLine l textidisplayline l A con gure timer0 OpenTimer0 TIMERilNTioN amp T0716BIT amp T07SOURCE71NT amp T07PS717128 Clock Frequency 4 MHZ Instruction cycle Frequency l MHZ Timer 0 Frequency l MHZ 128 78125 HZ Timer 0 Period 128 uSeconds Period in microseconds always equals prescaler when clock is 4 MHZ Over ow every 128 uSecond 2Al6 ticks 84 seconds This code is only necessary for the interrupt only INTCON2bitsTMROIP 0 Make Timer Interrupt High Priority INTCONbitsTMROIE l Enable the Timer zero interrupt INTCONbitsGIEH l Enable High priority interrupt while 1 result ReadTimer0 read timer sprintftempStringquot u ticksquotresult LCDLine2 textidisplaytempString CloseTimer0 close modules Function void highiisrvoid Input Occurs on a timer over ow Output Modify the PORTB LEDs Overview The interrupt counts over ows using LEDs pragma interrupt highiisr declare function as high priority isr void highiisrvoid INTCONbitsTMROIF 0 PORTB Function void lowiisrvoid Input Output Overview pragma interruptlow lowiisr declare function as low priority isr void lowiisrvoid


Buy Material

Are you sure you want to buy this material for

25 Karma

Buy Material

BOOM! Enjoy Your Free Notes!

We've added these Notes to your profile, click here to view them now.


You're already Subscribed!

Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'

Why people love StudySoup

Jim McGreen Ohio University

"Knowing I can count on the Elite Notetaker in my class allows me to focus on what the professor is saying instead of just scribbling notes the whole time and falling behind."

Jennifer McGill UCSF Med School

"Selling my MCAT study guides and notes has been a great source of side revenue while I'm in school. Some months I'm making over $500! Plus, it makes me happy knowing that I'm helping future med students with their MCAT."

Bentley McCaw University of Florida

"I was shooting for a perfect 4.0 GPA this semester. Having StudySoup as a study aid was critical to helping me achieve my goal...and I nailed it!"


"Their 'Elite Notetakers' are making over $1,200/month in sales by creating high quality content that helps their classmates in a time of need."

Become an Elite Notetaker and start selling your notes online!

Refund Policy


All subscriptions to StudySoup are paid in full at the time of subscribing. To change your credit card information or to cancel your subscription, go to "Edit Settings". All credit card information will be available there. If you should decide to cancel your subscription, it will continue to be valid until the next payment period, as all payments for the current period were made in advance. For special circumstances, please email


StudySoup has more than 1 million course-specific study resources to help students study smarter. If you’re having trouble finding what you’re looking for, our customer support team can help you find what you need! Feel free to contact them here:

Recurring Subscriptions: If you have canceled your recurring subscription on the day of renewal and have not downloaded any documents, you may request a refund by submitting an email to

Satisfaction Guarantee: If you’re not satisfied with your subscription, you can contact us for further help. Contact must be made within 3 business days of your subscription purchase and your refund request will be subject for review.

Please Note: Refunds can never be provided more than 30 days after the initial purchase date regardless of your activity on the site.