Hello, I would greatly appreciate if someone could help me figure out how to make a motor pulse using MPLab. For example, The motor (pwm03) needs to pulse on and off continually every second. Any help programming this would be greatly appreciated!!
why do you need it to?
use a timer and check it and then do mod math to find the time and turn on or off according to it
The easy way to do this is:
You know that user_routines.c Default executes once every 26 (approx) ms.
That means that every 38 loops is nearly exactly 1 second. Simply write a counter, and then an if-then-else. It would look something like this:
count=count+1;
if (count == 38)
{
pwmXX=255;
count=0;
}
else
pwmXX=127;
Note you would want to declare the counter as a static variable.
i need a little more help with this. Where exactly would i put the variables unsigned char unsigned int? Or does anyone have a simpler way of doing this? Please let me know i really need help. Thank You.
The only variable involved is your counter. Put it in the declaration section of the routine that you put the code in. This is generally located at the beginning of the routine before any of the code, but after the open bracket {
eh, unfortunately, i’m still kind of lost. Someone please help
Ok, can you tell us how much experience you have with programming first of all.
-q
well i can program the robot to move , program relays, sometimes digital inputs… switches, triggers, buttons, autonomous.