Hi,
i am a student and needs some help. Can someone help solve some of my doubts?
Hmm..may i know what does it means by SYSCLK/12/10? How can i go about calculating the timer values using the SYSCLK/12/10 if i want to use the codes below to make the LED blink at 1Hz?
Thanx=)
//------------------------------------------------------------------------------------ // MAIN Routine //------------------------------------------------------------------------------------ void main (void) { // disable watchdog timer WDTCN = 0xde; WDTCN = 0xad; SFRPAGE = CONFIG_PAGE; // Switch to configuration page PORT_Init (); SFRPAGE = TMR3_PAGE; // Switch to Timer 3 page Timer3_Init (SYSCLK /120/10); // Init Timer3 to generate interrupts // at a 10 Hz rate. EA = 1; // enable global interrupts SFRPAGE = LEGACY_PAGE; // Page to sit in for now while (1) { // spin forever } } //------------------------------------------------------------------------------------ // PORT_Init //------------------------------------------------------------------------------------ // // Configure the Crossbar and GPIO ports // void PORT_Init (void) { XBR2 = 0x40; // Enable crossbar and weak pull-ups P1MDOUT |= 0x40; // enable P1.6 (LED) as push-pull output } //------------------------------------------------------------------------------------ // Timer3_Init //------------------------------------------------------------------------------------ // // Configure Timer3 to auto-reload and generate an interrupt at interval // specified by <counts> using SYSCLK/12 as its time base. // // void Timer3_Init (int counts) { TMR3CN = 0x00; // Stop Timer3; Clear TF3; // use SYSCLK/12 as timebase RCAP3 = -counts; // Init reload values TMR3 = 0xffff; // set to reload immediately EIE2 |= 0x01; // enable Timer3 interrupts TR3 = 1; // start Timer3 } //------------------------------------------------------------------------------------ // Interrupt Service Routines //------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------ // Timer3_ISR //------------------------------------------------------------------------------------ // This routine changes the state of the LED whenever Timer3 overflows. // // NOTE: The SFRPAGE register will automatically be switched to the Timer 3 Page // When an interrupt occurs. SFRPAGE will return to its previous setting on exit // from this routine. // void Timer3_ISR (void) interrupt 14 { TF3 = 0; // clear TF3 LED = ~LED; // change state of LED }
"Hi, i have read up on the operation of timer 3, it mentioned that it can either use SYSCLK(divided by either 1,2 or 12).
Remember: when the Datasheet talks about "SYSCLK", it is talking about the physical signal on the chip - it knows nothing about any symbol in your source code that might just happen to also be named "SYSCLK"
"does the 1,2 or 12 represents the no of cycles needed to carry out the instruction?"
No - it means exactly what it says:
"SYSCLK divided by 1" is a signal with the same frequency as SYSCLK;
"SYSCLK divided by 2" is a signal with half the frequency of SYSCLK;
"SYSCLK divided by 12" is a signal with one-twelfth the frequency of SYSCLK
"for SYSCLK/12/10, for the value 10, does it represent the 10Hz rate?"
What 10Hz rate?
Again, "SYSCLK/12/10" is just plain arithmetic: take the value of SYSCLK, divide it by 12, then divide the result by 10.
Student means studying - the study required here is:
Hi, i have read up on the operation of timer 3, it mentioned that it can either use SYSCLK(divided by either 1,2 or 12). does the 1,2 or 12 represents the no of cycles needed to carry out the instruction? And for SYSCLK/12/10, for the value 10, does it represent the 10Hz rate?
This is the value for the sysclk:
//------------------------------------------------------------------------------------ // Global CONSTANTS //------------------------------------------------------------------------------------ #define SYSCLK 3062500 // approximate SYSCLK frequency in Hz sbit LED = P1^6; // green LED: '1' = ON; '0' = OFF
Hmm..the SYSCLK is defined as 3062500Hz.. Thanx=)i will go and check that out..
"i am a student and needs some help."
Student means studying - the study required here is: 1. Your 'C' textbook; 2. The documentation for this code that you're looking at; 3. The datasheet for the chip that you're using.
"what does it means by SYSCLK/12/10"
That is a simple arithmetic expresion; the '/' is the 'C' division operator - it means "divided by"
You haven't shown the part of the code that defines SYSCLK - we can only guess what it might mean without that!
For details of how Timer-3 operates, see the chip datasheet.
View all questions in Keil forum