Wingmax
New Member
This is continuous from "Driving a servo motor". This time we'll use Timer0 in P16f84A to generate the pulse width and the period of the pulse train.
The program sets up the Timer0 function, set the first value in the Timer0 register and wait for it to overflow. This value times the postscale is the pulse high duration. When Timer0 register overflows we set the pulse low and enter a second value (longer duration) and wait for another overflow. This value is to set the pulse period. When this overflow occurs, we set the
pulse high again and repeats the whole process.
The program doesn't use the interrupt routine.
View attachment servo motor_timer0_C.txt
Please refer codes in the main program to setup Timer0 function.
Because we set 16 mS as the pulse period, we have to use prescale of 1:64 so that Timer0 register will take more than 16mS before overflows.
This program will lead to the next program, which uses Timer0 and Timer1 and Timer1 interrupt routine........
The program sets up the Timer0 function, set the first value in the Timer0 register and wait for it to overflow. This value times the postscale is the pulse high duration. When Timer0 register overflows we set the pulse low and enter a second value (longer duration) and wait for another overflow. This value is to set the pulse period. When this overflow occurs, we set the
pulse high again and repeats the whole process.
The program doesn't use the interrupt routine.
View attachment servo motor_timer0_C.txt
Please refer codes in the main program to setup Timer0 function.
Because we set 16 mS as the pulse period, we have to use prescale of 1:64 so that Timer0 register will take more than 16mS before overflows.
This program will lead to the next program, which uses Timer0 and Timer1 and Timer1 interrupt routine........