616Views4Replies

# PWM to Digital Signal Answered

I am trying to make an R/C sumo bot for a competition. What would be the easiest way to run regular DC gearhead motors from a servo controller? I'm thinking of somehow converting the pwm signal into a digital signal that would run the motors forward or backward.

Tags:

## Discussions

Depending on the size of the motors, and your budget, an ESC for an RC car should be able to handle around 20+ amps, at up to 9.6V and you can get a reasonable quality one new for under £30. If the motors are only small you can get a dual motor driver able to handle a couple of amps for around £5, but this will need a simple microcontroller to drive it.

If you do go down the microcontroller driving an H bridge route, the output signal from the receiver is 5V DC, with a 1 to 2 ms pulse roughly every 18 to 20ms, about 50 or 60Hz.

What exactly would i have to do to have the pwm signal be interprted by the microcontroller? I cant think of a way to work the signal so my radio will run the motors properly. I realize i am going to need an h bridge, but i am not proficcent enough with my microcontroller to figure out how to chane the signal. (in case it makes a difference,i use a pic16f690).

The simplest routine to convert the signal I can work out at the moment is to get it to loop back to the start until a high is detected on the input. When a high is detected, you should make it count up until it detects a low on the input port (you will probably need to add a delay in to the count routine to make sure it does not count over 256).

The equivalent of 1.25ms counting should then be subtracted. (if, for example it counts to 200 in 2ms, you should subtract 125). Move this to register A.

Subtract the actual value of A from the highest possible value of A (when the receiver is putting out the full forward signal.), putting the result in register B. If the result is greater half the maximum value of A, plus 5, then put a high on bit 1 of register C. If the result is less than half the value of A, minus 5, put a high on bit 2 of register C. The +-5 allows for inaccuracies.

#########

If bit 1 of C is high, set A = A minus the half the maximum value of A, set B=B minus half the maximum value of A.
This sets A as the high time, and B as the low time.

Set one of the outputs to the H bridge high, then run a delay of 16ms divided by half the maximum value of A, repeat A times.

Set the output low, then run the delay B times.

set A,B and C to 0, then goto start.

########

If bit 2 of C is high, do the bit sectioned off with the ###, just swap A and B over, and put the high output on the other input of the H bridge.

hopefully that will explain roughly how to do it, though to be honest, it is 9pm on friday afternoon, and I've been doing Alevels all week, so i'm not thinking too straight at the moment.

If you need any help with the programming, just ask.

Running DC motors from a servo controller won't work very well, because servo controllers output a very narrow range of duty cycles (proportion of the time the signal is "on" to "off"). I believe they tend to work between 5% and 10% duty cycle, whereas for a DC motor you want the entire range 0% to 100%. For that purpose a DC motor controller is probably your best bet unless you want to build your own or do some messing around with microcontrollers.

As for forwards and backwards, for a DC motor you want an H-bridge; no way around that.