Log in

View Full Version : MAKE A MOTOR PULSE????


jax1488
25-01-2008, 11:42
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!!

rhoads2234
25-01-2008, 11:55
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

Tom Line
25-01-2008, 12:03
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.

jax1488
25-01-2008, 12:50
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.

Tom Line
25-01-2008, 13:44
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 {

jax1488
25-01-2008, 14:14
eh, unfortunately, i'm still kind of lost. Someone please help :(

Qbranch
25-01-2008, 14:37
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

jax1488
25-01-2008, 14:40
well i can program the robot to move , program relays, sometimes digital inputs.... switches, triggers, buttons, autonomous.