Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
01/06/04 21:45
Read: times


 
#62047 - RE: <<<Read This First>>>
Responding to: ???'s previous message
Stanley Lio wrote:
I want to place a "check sensor" procedure in the PWM generating delay.

It is a bad idea to generate PWM by delay because it holds the processor up and you can hardly do anything else with it. What you should do is either use a derivative with built in PWM module or simulate a PWM module by software using timer interrupt.
Make a function like this to start PWM from main program loop:
void startPWM(unsigned char direction, unsigned char dutyCycle);
What this function does is to set a flag to be checked by timer interrupt every 1 msec say, and loads the duty cycle register with required duty cycle.
assuming the pwm duty cycle is 100 msec, every 1 msec you decriment duty cycle register in 1 msec timer interrupt and the pulse hi duration register, if pulse hi duration register = 0 you clear PWM pin till end of PWM duty cycle register and reload register with duty cycle to decriment again untill start pwm flag is cleared by main program to stop motor.
This way you only trigger the PWM generation by main loop and it continues by itself using timer interrupt.
This way you can check for sensor signals and start or stop PWM at the same time.
Mahmood


List of 15 messages in thread
TopicAuthorDate
ISR time shouldn't last that long? 1 sec            01/01/70 00:00      
   RE: ISR time shouldn\'t last that long? 1 sec            01/01/70 00:00      
      RE: ISR time shouldn\'t last that long? 1 sec            01/01/70 00:00      
         RE: ISR time shouldn\\\'t last that long? 1 sec            01/01/70 00:00      
         <<<No ball motions>>>            01/01/70 00:00      
            RE: <<<No ball motions>>>            01/01/70 00:00      
   RE: ISR time shouldn't last that long? 1 sec            01/01/70 00:00      
   RE: ISR time shouldn\'t last that long? 1 sec            01/01/70 00:00      
   <<<Read This First>>>            01/01/70 00:00      
      RE: <<<Read This First>>>            01/01/70 00:00      
         RE: <<<Read This First>>>            01/01/70 00:00      
      RE: <<<Read This First>>>            01/01/70 00:00      
         RE: <<<Read This First>>>            01/01/70 00:00      
         RE: <<<Read This First>>>            01/01/70 00:00      
            RE: <<<Read This First>>>            01/01/70 00:00      

Back to Subject List