|
View:
New views
3 Messages
—
Rating Filter:
Alert me
|
|
|
Problem initialise timer for 1µs cycleHello,
I have a problem with using the Timer on a MC9S12DP512. I want to create 1µ second cycles. Every µs I want to increment a variable, but I do not know how to initialise the timer, so that I get a timer interrupt every µs. I hope that someone can help me. Best regards Here is my function to initialise the timer: -------------------------------------------- void Init_Timers(void) { TCTL2= 0; // TCTL2_OL3= 0; /*TCTL2_OM2= 0; TCTL2_OL2= 0; TCTL2_OM1= 0; TCTL2_OL1= 0; TCTL2_OM0= 0; TCTL2_OL0= 0;*/ TIE&= ~(Bit5|Bit4|Bit3|Bit2|Bit1|Bit0); // C3I= 0, C2I= 0, C1I= 0, C0I= 0 /*TIE_C2I= 0; TIE_C1I= 0; TIE_C0I= 0;*/ TTOV&= ~(Bit5|Bit4|Bit3|Bit2|Bit1|Bit0); // TOV3= 0, TOV2= 0, TOV1= 0, TOV0= 0 /*TTOV_TOV2= 0; TTOV_TOV1= 0; TTOV_TOV0= 0;*/ //TTOV|= Bit6; TSCR2&= ~(Bit3); // TCRE= 0 TIOS|= Bit5|Bit4|Bit3|Bit2|Bit1|Bit0; // IOS3= 1, IOS2= 1, IOS1= 1, IOS0= 1 /*TIOS_IOS2= 1; TIOS_IOS1= 1; TIOS_IOS0= 1;*/ //TIOS|= Bit6; TSCR1|= Bit7; // TEN= 1 TSCR1&= ~(Bit6|Bit5); // TSWAI= 0, TSFRZ= 0 // TSCR1_TEN= 1; // TSCR1_TSWAI= 0; // TSCR1_TSFRZ= 0; PWMCTL&= ~(Bit3|Bit2); // PSWAI= 0, PFRZ= 0 // PWMCTL_PSWAI= 0; // PWMCTL_PFRZ= 0; //TCTL2|= Bit4; //TC6|= 0x8000; PWMSDN= 0; ICSYS= 0; //MCCTL|= Bit6; // MODMC= 1 TSCR2|= 7; // PR2= 1, PR1= 1, PR0= 1 // TSCR2|= Bit2|Bit1; // TSCR2_PR= 6; InitTimer1(); } and here is my Timer ISR: ------------------------- @interrupt void _ISR_Timer1(void) { ISR_Timer1(); gTimer1Count++; TFLG1= 0b00000010;// C0F - Interrupt Flag: Clear Input Capture 1 Flag if( IsTimer1Abgelaufen() ) { StartTimer1(1000); } } and here are some other functions I use (used in ISR): ------------------------------------------------------ void InitTimer1(void) { //TC1= TCNT + 65249; TIE&= ~Bit1; // C1I= 0 } void ISR_Timer1(void) { TIE&= ~Bit1; // C1I= 0 bTimer1Abgelaufen= YES; TFLG1|= Bit1; // C1F= 1 } void StartTimer1(unsigned int ticks) { TC1= TCNT + ticks; // 65249; TFLG1|= Bit1; // C1F= 1 bTimer1Abgelaufen= NO; bTimer1Laeuft= YES; TIE|= Bit1; // C1I= 1 } ------------------------------------ Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/68HC12/ <*> Your email settings: Individual Email | Traditional <*> To change settings online go to: http://groups.yahoo.com/group/68HC12/join (Yahoo! ID required) <*> To change settings via email: mailto:68HC12-digest@... mailto:68HC12-fullfeatured@... <*> To unsubscribe from this group, send an email to: 68HC12-unsubscribe@... <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/ |
|
|
RE: Problem initialise timer for 1µs cycleDid you initialize the counter? I have just implemented a 1 millisecond timer for this processor, but its in assembly since I use assembly more... I don't see a initialize routine for a timer starting point... If you want, I'll pass along my code for the 1 millisecond timer...then you would have to convert it to the micro second you want.. > To: 68hc12@... > From: folgli@... > Date: Fri, 1 May 2009 07:56:39 -0400 > Subject: [68HC12] Problem initialise timer for 1µs cycle > > Hello, > > I have a problem with using the Timer on a MC9S12DP512. I want to create 1µ second cycles. Every µs I want to increment a variable, but I do not know how to initialise the timer, so that I get a timer interrupt every µs. > I hope that someone can help me. > Best regards > > Here is my function to initialise the timer: > -------------------------------------------- > > void Init_Timers(void) > { > TCTL2= 0; > // TCTL2_OL3= 0; > /*TCTL2_OM2= 0; > TCTL2_OL2= 0; > TCTL2_OM1= 0; > TCTL2_OL1= 0; > TCTL2_OM0= 0; > TCTL2_OL0= 0;*/ > > TIE&= ~(Bit5|Bit4|Bit3|Bit2|Bit1|Bit0); // C3I= 0, C2I= 0, C1I= 0, C0I= 0 > /*TIE_C2I= 0; > TIE_C1I= 0; > TIE_C0I= 0;*/ > > TTOV&= ~(Bit5|Bit4|Bit3|Bit2|Bit1|Bit0); // TOV3= 0, TOV2= 0, TOV1= 0, TOV0= 0 > /*TTOV_TOV2= 0; > TTOV_TOV1= 0; > TTOV_TOV0= 0;*/ > //TTOV|= Bit6; > > TSCR2&= ~(Bit3); // TCRE= 0 > > TIOS|= Bit5|Bit4|Bit3|Bit2|Bit1|Bit0; // IOS3= 1, IOS2= 1, IOS1= 1, IOS0= 1 > /*TIOS_IOS2= 1; > TIOS_IOS1= 1; > TIOS_IOS0= 1;*/ > //TIOS|= Bit6; > > TSCR1|= Bit7; // TEN= 1 > TSCR1&= ~(Bit6|Bit5); // TSWAI= 0, TSFRZ= 0 > // TSCR1_TEN= 1; > // TSCR1_TSWAI= 0; > // TSCR1_TSFRZ= 0; > > PWMCTL&= ~(Bit3|Bit2); // PSWAI= 0, PFRZ= 0 > // PWMCTL_PSWAI= 0; > // PWMCTL_PFRZ= 0; > //TCTL2|= Bit4; > //TC6|= 0x8000; > PWMSDN= 0; > > ICSYS= 0; > > //MCCTL|= Bit6; // MODMC= 1 > TSCR2|= 7; // PR2= 1, PR1= 1, PR0= 1 > // TSCR2|= Bit2|Bit1; > // TSCR2_PR= 6; > InitTimer1(); > } > > and here is my Timer ISR: > ------------------------- > > @interrupt void _ISR_Timer1(void) > { > ISR_Timer1(); > gTimer1Count++; > TFLG1= 0b00000010;// C0F - Interrupt Flag: Clear Input Capture 1 Flag > if( IsTimer1Abgelaufen() ) > { > StartTimer1(1000); > } > } > > and here are some other functions I use (used in ISR): > ------------------------------------------------------ > > void InitTimer1(void) > { > //TC1= TCNT + 65249; > TIE&= ~Bit1; // C1I= 0 > } > > void ISR_Timer1(void) > { > TIE&= ~Bit1; // C1I= 0 > bTimer1Abgelaufen= YES; > TFLG1|= Bit1; // C1F= 1 > } > > void StartTimer1(unsigned int ticks) > { > TC1= TCNT + ticks; // 65249; > TFLG1|= Bit1; // C1F= 1 > bTimer1Abgelaufen= NO; > bTimer1Laeuft= YES; > TIE|= Bit1; // C1I= 1 > } > > > > > ------------------------------------ > > Yahoo! Groups Links > > > _________________________________________________________________ Windows Live Hotmail®: more than just e-mail. http://windowslive.com/online/hotmail?ocid=TXT_TAGLM_WL_HM_more_042009 [Non-text portions of this message have been removed] ------------------------------------ Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/68HC12/ <*> Your email settings: Individual Email | Traditional <*> To change settings online go to: http://groups.yahoo.com/group/68HC12/join (Yahoo! ID required) <*> To change settings via email: mailto:68HC12-digest@... mailto:68HC12-fullfeatured@... <*> To unsubscribe from this group, send an email to: 68HC12-unsubscribe@... <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/ |
|
|
RE: Problem initialise timer for 1µs cycleHi,
I find just this morning your problem about Timer. Because of character problems on the mail I received, I can't see if you want interrupt each micro-second... If so, it seems very very fast for that processor. With 12 Mhz quartz, no PLL, I use an empty function (in C) to delay 2.5 micro-seconds : void Delay_2_5_micro (void) { // nothing to do } That means just call and return from this empty function take 2.5 micro-seconds, measured with oscilloscope. Hope this helps. Joel -----Message d'origine----- De : 68HC12@... [mailto:68HC12@...] De la part de justin lucas Envoyé : vendredi 1 mai 2009 18:01 À : 68hc12@... Objet : RE: [68HC12] Problem initialise timer for 1µs cycle Did you initialize the counter? I have just implemented a 1 millisecond timer for this processor, but its in assembly since I use assembly more... I don't see a initialize routine for a timer starting point... If you want, I'll pass along my code for the 1 millisecond timer...then you would have to convert it to the micro second you want.. > To: 68hc12@... > From: folgli@... > Date: Fri, 1 May 2009 07:56:39 -0400 > Subject: [68HC12] Problem initialise timer for 1µs cycle > > Hello, > > I have a problem with using the Timer on a MC9S12DP512. I want to create 1µ second cycles. Every µs I want to increment a variable, but I do not know how to initialise the timer, so that I get a timer interrupt every µs. > I hope that someone can help me. > Best regards > > Here is my function to initialise the timer: > -------------------------------------------- > > void Init_Timers(void) > { > TCTL2= 0; > // TCTL2_OL3= 0; > /*TCTL2_OM2= 0; > TCTL2_OL2= 0; > TCTL2_OM1= 0; > TCTL2_OL1= 0; > TCTL2_OM0= 0; > TCTL2_OL0= 0;*/ > > TIE&= ~(Bit5|Bit4|Bit3|Bit2|Bit1|Bit0); // C3I= 0, C2I= 0, C1I= 0, C0I= 0 > /*TIE_C2I= 0; > TIE_C1I= 0; > TIE_C0I= 0;*/ > > TTOV&= ~(Bit5|Bit4|Bit3|Bit2|Bit1|Bit0); // TOV3= 0, TOV2= 0, TOV1= 0, > /*TTOV_TOV2= 0; > TTOV_TOV1= 0; > TTOV_TOV0= 0;*/ > //TTOV|= Bit6; > > TSCR2&= ~(Bit3); // TCRE= 0 > > TIOS|= Bit5|Bit4|Bit3|Bit2|Bit1|Bit0; // IOS3= 1, IOS2= 1, IOS1= 1, IOS0= 1 > /*TIOS_IOS2= 1; > TIOS_IOS1= 1; > TIOS_IOS0= 1;*/ > //TIOS|= Bit6; > > TSCR1|= Bit7; // TEN= 1 > TSCR1&= ~(Bit6|Bit5); // TSWAI= 0, TSFRZ= 0 > // TSCR1_TEN= 1; > // TSCR1_TSWAI= 0; > // TSCR1_TSFRZ= 0; > > PWMCTL&= ~(Bit3|Bit2); // PSWAI= 0, PFRZ= 0 > // PWMCTL_PSWAI= 0; > // PWMCTL_PFRZ= 0; > //TCTL2|= Bit4; > //TC6|= 0x8000; > PWMSDN= 0; > > ICSYS= 0; > > //MCCTL|= Bit6; // MODMC= 1 > TSCR2|= 7; // PR2= 1, PR1= 1, PR0= 1 > // TSCR2|= Bit2|Bit1; > // TSCR2_PR= 6; > InitTimer1(); > } > > and here is my Timer ISR: > ------------------------- > > @interrupt void _ISR_Timer1(void) > { > ISR_Timer1(); > gTimer1Count++; > TFLG1= 0b00000010;// C0F - Interrupt Flag: Clear Input Capture 1 Flag > if( IsTimer1Abgelaufen() ) > { > StartTimer1(1000); > } > } > > and here are some other functions I use (used in ISR): > ------------------------------------------------------ > > void InitTimer1(void) > { > //TC1= TCNT + 65249; > TIE&= ~Bit1; // C1I= 0 > } > > void ISR_Timer1(void) > { > TIE&= ~Bit1; // C1I= 0 > bTimer1Abgelaufen= YES; > TFLG1|= Bit1; // C1F= 1 > } > > void StartTimer1(unsigned int ticks) > { > TC1= TCNT + ticks; // 65249; > TFLG1|= Bit1; // C1F= 1 > bTimer1Abgelaufen= NO; > bTimer1Laeuft= YES; > TIE|= Bit1; // C1I= 1 > } > > > > > ------------------------------------ > > Yahoo! Groups Links > > > _________________________________________________________________ Windows Live Hotmail®: more than just e-mail. http://windowslive.com/online/hotmail?ocid=TXT_TAGLM_WL_HM_more_042009 [Non-text portions of this message have been removed] ------------------------------------ Yahoo! Groups Links |
| Free embeddable forum powered by Nabble | Forum Help |