Ana's picture


Joined: May 17, 2017

Replies: 3
May 22, 2017 - 5:12pm

Hi I have a doubt in the servomotor with PIC tutorial because  don't know how the REG_value is calculated  and why TMR0 is 251 and this line of code 

on_time = (170-pot_value); can you explain to me please, THANKS
Aswinth Raj's picture


Joined: Aug 16, 2016

Replies: 996

Here the variable pot value will vary from 0-40 based on the potentiometer value. So when the value is 0 we have to make a PWM with 0 duty cycle and when 40% we have to make a pwm with 100% duty cycle.

When the value of on_time is 170 a 100% duty cycle will be formed by the timer0 module and when 130 i.e (170-40) a 0% duty cycle will be formerd. To understand the concept better you can download the simulation file and try simulating the code by using different values for 170