2016-12-14 10:27 PM
Hello. I am using a STM8 (STM8S208C8T6) and reading a code (not written by me) that employs a timer and its interrupt to call several routines. Apparently the clock is set at 16MHz i.e. 0.0625uS.
The settings of the timer are ARRH=0x03 and ARRL=0x20. therefore (0x0320=800) it resets at 800 (50uS) (ascending) PSCR is set as 0 so the timer has the same freq as the micro . The program also uses AD conversion (and its interruption)
Anyway checking with an oscilloscope the timer interrupt is called at
56us , 54uS, 54uS, 52uS, 52uS, 52us, 38us(!!!), 42us(?), 50us, 50us....
Curiosly when added, this gives 500uS so the timer called ten times does indeed gives 500uS as it should.
The first 8 times at the timer interrupt an AD conversion is initiated. so I am guessing that an AD interrupt (when the AD conversion is complete) is what is messing the frequency of the timer
1) Do you think my guess is correct? Can the AD interruption be affecting the period of the timer?
2) Why does it 'correct' itself by firing an interrupt at 38uS (and another at 42uS)?
I would appreciate any comment, pointer, advice on this since my experience with STM8 is limited.
Thanks
#stm8 #timer2018-03-19 06:47 AM
Could it be that in your software, the timer interrupt has a lower priority than the ADC interrupt, and usually an ADC interrupt is already being served when the timer interrupt arrives? Then the first 9 times the timer interrupt would stay pending until the ADC interrupt routine has returned, which seems consistent with what you see.
Philipp
2018-03-19 08:19 AM
Likely your isr is longer than 800 ticks.
One way to test is to set the isr to fire at longer intervals and if you see a steady timing interval, you got the problem.
2018-03-26 12:48 AM
ISR might be longer than required ticks, adding to that am not sure but you must also look at hard/soft interrupt priority/preemption and latency.