60 likes | 175 Views
Self study assignment Timer0. Prepare a presentation for 5-10 minutes about the subject Timer. Explain in detail how to use Timer0 module as timer. What you need to study?. At least: Reference Manuals for the mid-range MCU Family Section 11=> study 11.1, 11.2, 11.3, 11.6,
E N D
Self study assignmentTimer0 Prepare a presentation for 5-10 minutes about the subject Timer. Explain in detail how to useTimer0 module as timer.
What you need to study? At least: • Reference Manuals for the mid-range MCU FamilySection 11=> study 11.1, 11.2, 11.3, 11.6, • Data sheet PIC16F684=>study 5 until 5.1.2 includedYou are using the C-language, so it is not necessary to understand the macro instruction in detail.
Include in your presentation at least the next topics • fig 11.6 (sheet 4) • Limitation • Only the timer mode • Not the Watch dog mode or counter mode • Registers/Bits • TMR0 • T0CS • PSA • T0IF flag • Prescaler • Range of delays • Code snip example (1) (sheet 5)
From Reference Manuals for the mid-range MCU Family(document 33023a)
Example (1)code snippolling of the T0IF flag register /* Example of polling the T0IF flag (on overflow) A delay of multi * 0.256 msec; param uns8 multi <=0xFF */ void delayPolling(uns8 multi) { TMR0=0; //clear timer T0CS=0; //OPTION_REG.5 see data sheet PSA =0; //OPTION_REG.3 see data sheet OPTION_REG &=0b.1111.1000; //bit 2-0 prescaler ??? OPTION_REG |=0b.0000.0111; //bit 2-0 prescaler ??? //prescaler 1:256, Fosc/4 =1 MHz=> 3906 KHz=> 0.256 msec TMR0= 255-multi+1; //Explane! T0IF=0; //clear overflow flag while (T0IF!=1)/*wait loop*/ ; T0IF=0; }
Example (2)code snip polling of the TMR0 register /* * A delay of milliSec msec; * param uns16 milliSec * CC5X compiler C notation */ void delay(uns16 milliSec) { uns8 next=0;//next is a cyclic counter (0-255) TMR0=0; //clear timer T0CS=0; //OPTION_REG.5,see data sheet PSA=0; //OPTION_REG.3,see data sheet OPTION_REG &=0b.1111.1000;//bit 2-0 prescaler OPTION_REG |=0b.0000.0010;//bit 2-0 prescaler //result prescaler 1:8 4Mhz=Fosc => 125 kHz=> 8 micro sec TMR0=1;//compensation for 2 instructions see data sheet do{ next +=125; //8*125=> 1 msec while (TMR0 != next) /*wait loop*/; milliSec-=1; } while(milliSec!=0); }