Re: Timer_T1Time and Timer_T3Time do not work as they should Kategorie: IDE (von PeterS - 20.04.2010 17:46) | |
Als Antwort auf Timer_T1Time and Timer_T3Time do not work as they should von PepeV - 19.02.2010 17:46
| |
Hello Pepe, sorry for the long delay, but here is finally the answer. I was ill for quite some time, and very busy after that. There were 2 things that are wrong. You used the wrong prescaler values, and there is a bug in Timer_T0Time() and Timer_T3Time(). 1. For all timer except timer0 use the prescaler constants without a "0" in the name. For "64" prescaler use "PS_64" (except timer0 there is "PS0_64" ok). But this is documented correct in the manual. 2. There is a bug in the library so Timer_TxTime() uses 65536 instead of the given parameter. Unfortunately the timer library was not written by me, but some time later I found the bug. I also found a workaround that can be used in actual programs until a new IDE is released: Workaround Timer 1: Timer_T1Time(12345,PS_256); DirAcc_Write(0x4e,8|PS_256); // add this line after Timer_T1Time() & use the same prescaler in it Workaround Timer 3: Timer_T3Time(54321U,PS_64); DirAcc_Write(0x8a,8|PS_64); // add this line after Timer_T3Time() & use the same prescaler in it Regards, Peter > Hi all (and especially Peter), > > The functions Timer_T1Time(word Time,byte PS) and Timer_T3Time(word Time,byte PS) generate > interrupts with a frequency that does not match the parameters PS and Time. It seems that the value > of Time is totally irrelevant and that the value of PS sets the prescaler values of the Mega32 while > I compile for Mega128. > In contrast, the function Timer_T0Time(byte Time,byte PS) does what should do for all values of PS and > Time. > Below is the program I used to test it and the results. > > Is this an error in the Mega128 or what? > > Regards, > Pepe > > word T0_Cnt, T1_Cnt, T2_Cnt, T3_Cnt; > > void main(void) > { > Irq_SetVect(INT_TIM0COMP,T0_ISR); > Irq_SetVect(INT_TIM1CMPA,T1_ISR); > Irq_SetVect(INT_TIM2COMP,T2_ISR); > Irq_SetVect(INT_TIM3CMPA,T3_ISR); > > Timer_T0Time(144,PS0_256); // 400 Hz > Timer_T1Time(12345,PS0_32); // Only the prescaler value matters. Why?! > // Timer T2 freq is allways 100 Hz > Timer_T3Time(54321,PS0_64); // Only the prescaler value matters. Why?! > > while (T2_Cnt<10000); // run 100 sec > > Msg_WriteFloat(T0_Cnt/100.0); > Msg_WriteChar(13); > Msg_WriteFloat(T1_Cnt/100.0); > Msg_WriteChar(13); > Msg_WriteFloat(T2_Cnt/100.0); > Msg_WriteChar(13); > Msg_WriteFloat(T3_Cnt/100.0); > Msg_WriteChar(13); > } > > void T0_ISR(void) > { > int irqcnt; > T0_Cnt++; > irqcnt=Irq_GetCount(INT_TIM0COMP); > } > > void T1_ISR(void) > { > int irqcnt; > T1_Cnt++; > irqcnt=Irq_GetCount(INT_TIM1CMPA); > } > > void T2_ISR(void) > { > int irqcnt; > T2_Cnt++; > irqcnt=Irq_GetCount(INT_TIM2COMP); > } > > void T3_ISR(void) > { > int irqcnt; > T3_Cnt++; > irqcnt=Irq_GetCount(INT_TIM3CMPA); > } > > The results: > Timer_T1Time(xxxxx,PS0_1) f=225,01 Hz (matches Timer=65535 and PS=1) > Timer_T1Time(xxxxx,PS0_8) f= 28,12 Hz (matches Timer=65535 and PS=8) > Timer_T1Time(xxxxx,PS0_32) f= 3,51 Hz (matches Timer=65535 and PS=64) > Timer_T1Time(xxxxx,PS0_64) f= 0,88 Hz (matches Timer=65535 and PS=256) > Timer_T1Time(xxxxx,PS0_128) f= 0,21 Hz (matches Timer=65535 and PS=1024) | |
Antwort schreiben Antworten: |
Zur Übersicht - INFO - Neueste 50 Beiträge - Neuer Beitrag - Suchen - Zum C-Control-I-Forum - Zum C-Control-II-Forum