TIM problem

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

TIM problem

359 Views
holgerkeil
Contributor II

Hey,

 

I'm experiencing problems using a timer twice in a sequence. I use this two functions for the timer [...]

Update: Ok, this issue is solved, I just forgot to clear the TOF flag between both timers. That made the 2nd. timer run erratic.


But I have another question of understanding:

 

void irpulse(){     int run;       TSC_TSTOP=1;       TSC_TRST=1;       TSC_PS0=0;       TSC_PS1=0;       TSC_PS2=0;       TMOD=45;       TCH0=32768;       TSC0_MS0A=0;       TSC0_MS0B=1;       TSC0_TOV0=1;       TSC0_ELS0B=1;       TSC0_ELS0A=0;       TSC_TSTOP=0;      for (run=0; run<57; run++){     while(TSC_TOF == 0);       }     TSC_TOF=0;   TSC_TSTOP=1;       TSC_TRST=1;       LEDir=0;     }  

 

This function generates an approx. 32kHz 570µs width burst for infrared transmitter by using the PWM generation functionality. One single pulse/pause is 30µs, so a total of 19 pulses equals to the 570µs. 19 cycles means 38 phase changes (toggles on overflow). However if I write:

 

for (run=0; run<38; run++){     while(TSC_TOF == 0);       }  

 

I'll get only 12 pulses on my scope. I try-and-error-tune it to run<57 and I'll get an exact count of 19 pulses - a precise and stable burst of 570µs width. That works fine for me, but I want to understand why this routine does not work as expected.

 

Best regards

Holger

 

Last edited by Holger Keil

Labels (1)
Tags (1)
0 Kudos
0 Replies