PWM on PICs explained?

Thread Starter

camerart

Joined Feb 25, 2013
3,724
Hi,
I've been playing with PWM for a while now, especially for servo control, and kind of understand it, but need clarification please.

I have seen the output of a RC transmitter on an oscilloscope, and how 'say' 6 channels appear. When one of the controls is moved, then that channel is stretched on shrunk and the other channels are moved along.

In simple terms when the transmitter sends all of the PWM signals, are they as a string, or more 6 channels sent tightly together.

I'm using PICs with PWM dedicated PINS, so each PIN will control 1x SERVO.

Note, I've got lots of previous information, but I haven't fully joined all of the dots yet.
EDITED:
Camerart.
 
Last edited:

Tonyr1084

Joined Sep 24, 2015
7,853
First, I'm not familiar with how RC transmitters work. I believe (probably wrong) that they send a frequency with some amplitude to it to control the servo, but like I said I'm probably wrong.

Here's what I'm confident with: PWM is a set frequency. Typically, but not strictly, around 1KHz. The width of the pulse is modulated, meaning it's varied between 0% & 100%. Well, not that wide I don't think, but the frequency doesn't change, nor does the amplitude. PWM is a percentage of ON versus OFF. The greater the ON time the more voltage, but the period does not change. It still remains at its given Hz.
 

Ian Rogers

Joined Dec 12, 2012
1,136
Hi C

RC isn't strictly PWM... The servo has a variable position around 1 ~ 2 mS pulse width with 1.5mS being central, 1ms pulse width is fully left / right 2ms pulse is fully right / left

As Tonr1084 said... Transmitting this data will be a byte giving position data.. The receiver will work out the pulse width..
 

jpanhalt

Joined Jan 18, 2008
11,087
Assuming CA is asking about "standard" hobby PCM (pulse code modulation) or PPM (pulse position) transmitters at 72 MHz and 75 MHz, here is a nice description of the differences: https://rcplanes.online/guide1.htm

Just FYI, the vast majority of those transmitters are FM today, and PCM is (was) most common. Today, most new stuff is 2.4 GHz, and I haven't kept up on the details of that. (I still use 72 MHz equipment but am working on a new airplane that will be on 2.4 GHz.)
 

Thread Starter

camerart

Joined Feb 25, 2013
3,724
Hi T, I and J,
I now see my first mistake, I was getting PWM mixed up with PPM (pulse position).

From post #1 I've seen PPM from an RC transmitter with 6 channels, and how they react to stick movement.

I would like to send 6 channels from a PIC to 6 servos, how would this be done?

J, I use 35Mhz 40MHz 2.4GHz and the UK 70CMs frequencies, for my models.

Thanks, C.
 

jpanhalt

Joined Jan 18, 2008
11,087
There are lots of ways to do that. Again, I have not kept up on 2.4 GHz stuff. I also forgot to point out the frequency band differences UK v. US. US also allows hams on 6 meter. With that lead in, here is the content of a very old folder in a dusty part of my SSD. I have not checked whether any of the links are still working. You have probably seen that most "servo testers" only test one servo at a time. These links are for driving multiple servos.

1) Most servos http://www.electro-tech-online.com/micro-controllers/34390-drive-33-servos-one-pic-usart.html
Appears to be commercial version of above: http://www.circuit-ed.com/30-Servo-HardwareSoftware-KIT-by-JVM-BOTS-P117C10.aspx
2) Eight servos: http://www.electro-tech-online.com/micro-controllers/36127-junebug-servo-c18-code.html (drives 8 servos)
3) Eighteen servos: http://www.electro-tech-online.com/micro-controllers/34329-18-servo-controller.html
4) Mike,K8LH: http://www.electro-tech-online.com/micro-controllers/29837-8-16-servos-using-pwm-module.html

Edit: Updated
John
 

MrChips

Joined Oct 2, 2009
30,712
Servo motors are controlled by a form of PWM (not PPM), but not in the usual way that we may think of PWM.

Normally, when we use PWM, we think of a continuous stream of equally spaced pulses with each pulse having the same pulse width (over a short term) but with a changing pulse width over the long term. In other words, the duty cycle of the digital pulse train may change from 0% to 100%.







This is how class-D audio amplifiers operate.




A single RC servo motor works on the same principle.
A PWM signal is sent to the servo motor. The pulse width may be 0.5ms to 2.5ms spaced every 20ms. The servo motor tries to position itself to the desired pulse-width at every pulse received by comparing the output of a potentiometer with the PWM command received.




In an analog RF TX/RX system, multiple servos are controlled by transmitting the PWM information one channel at a time. For example, for a 4-channel system, there will be four PWM pulses transmitted, one for each channel.



Some systems may use a PPM scheme.



In a digital system, the manufacturer may choose to create its own protocol for encoding the channel number and value information.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,724
Hi J and M,

J, I'm sure all of our confusion will be rectified, I'll look at your links tomorrow.
M, good explanation.
Thanks.

Here is an interesting video:

Once we've got it all clear, I need to know how to program a PIC to directly drive 6ish servos directly connected.
C.
 

MrChips

Joined Oct 2, 2009
30,712
What we were discussing above was how a single RF transmitter can control multiple servos. If you have an MCU driving 6 servos then you don't have that problem. Simply drive each servo with its own PWM signal using the internal timer and interrupts.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,724
Hi J,
I went through your links, but I think I need to start afresh, as they are all written in different languages, I only speak BASIC, and there are oddities with Oshonsoft, so care is needed.
Thanks, C.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,724
What we were discussing above was how a single RF transmitter can control multiple servos. If you have an MCU driving 6 servos then you don't have that problem. Simply drive each servo with its own PWM signal using the internal timer and interrupts.
Hi M,
"Simply drive each servo with its own PWM signal using the internal timer and interrupts"
Do I need a PIC with 6x dedicated PWM outputs?
Thinking the above is true, is the 18LF6722 PIC suitable? Or can it be done with an 184520 PIC?
C.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,724
hi C,
There is a section in the Oshonsoft Basic manual for Interfacing Radio Control (R/C) servos.

E
Hi E, Lovely morning here across the border,
Does this mean I can use any normal port PINs on 'say' an 18LF4520? If so that's excellent.
I noticed: 'Using internal PWM modules' What is this for?
C.
 

ericgibbs

Joined Jan 29, 2010
18,766
I noticed: 'Using internal PWM modules' What is this for?
hi C,
If you recall, we used PWM for controlling the speed and direction of scanning head rotation and tilt, with ref to the encoder inputs.
E
 

Thread Starter

camerart

Joined Feb 25, 2013
3,724
hi C,
If you recall, we used PWM for controlling the speed and direction of scanning head rotation and tilt, with ref to the encoder inputs.
E
Hi E,
If I recall correctly it uses TIMERS and INTERRUPTS, which are independent of the LOOP, is this correct, and what Using internal PWM modules is about? Which is different from Interfacing Radio Control (R/C) servos?
As you can see from the exchanges above, it needs to be clear, so we don't go off at angles:)
C
 

jpanhalt

Joined Jan 18, 2008
11,087
I'm using PICs with PWM dedicated PINS, so each PIN will control 1x SERVO.
Re: Post #18 and #15

I am getting a bit confused. What does controlling such servos with dedicated pins have to do with decoding of the transmitter? If there is a problem with using dedicated pins for each servo, several posts in the links I posted show how to use fewer pins, for example, one uses a counter (4017) to drive 9 servos using only 2 PIC pins.

In the alternative, are your concerns about how to generate a servo signal on a pin and how to control that signal from some external input, e.g., a pot?
 

ericgibbs

Joined Jan 29, 2010
18,766
hi C,
Servo control is for driving, say a rudder to a fixed angle of rotation and holding there, it is not normally used for continuous rotation.

Typically a frame has a 20mSec period, within that 20mSec period, a high pulse of duration between 1mSec and 2mSec is sent to the servo.
The length of the pulse determines the position of the servo shaft/rudder.
The pulses have to be sent continuously in order to hold the servo shaft in the required position.

In your application a PWM signal is used to drive motors.

This clip is a simple demo of Oshonsoft's Servo command, it requires the correct timing programming code, note 6 channels
E
ESP1 14-Mar-18 10.10.gif
 
Top