PWM on PICs explained?

Thread Starter

camerart

Joined Feb 25, 2013
3,730
Hi J and E,
J, To clarify: A string of DATA is sent to the PIC via a radio. The DATA then goes through a calculation, and is output using 'say' 6 PWM PINS.

E, Thanks for the clarification of Interfacing Radio Control (R/C) servos.
Am I correct that if your code was inside a longish LOOP, then it wouldn't work properly?

If a dedicated PIC being controlled by a master PIC, to control the PWM outputs was used, and each of the 6x LENGTH times was changed each time, would this work?

Am I correct that another alternative to keep it all in 1x LOOP, Using internal PWM modules with CCP is needed which would mean 6x dedicated PWM CCP outputs?

C.
 

ericgibbs

Joined Jan 29, 2010
18,865
Hi C,
What is your planned method of transmitting all this control information to the remote receiver in the model aircraft.?
I would suggest you post a block diagram of the project so that we all have a point of reference.
E
If a dedicated PIC being controlled by a master PIC, to control the PWM outputs was used, and each of the 6x LENGTH times was changed each time, would this work?
Am I correct that another alternative to keep it all in 1x LOOP, Using internal PWM modules with CCP is needed which would mean 6x dedicated PWM CCP outputs?

E
 

Thread Starter

camerart

Joined Feb 25, 2013
3,730
Hi C,
What is your planned method of transmitting all this control information to the remote receiver in the model aircraft.?
I would suggest you post a block diagram of the project so that we all have a point of reference.
E
If a dedicated PIC being controlled by a master PIC, to control the PWM outputs was used, and each of the 6x LENGTH times was changed each time, would this work?
Am I correct that another alternative to keep it all in 1x LOOP, Using internal PWM modules with CCP is needed which would mean 6x dedicated PWM CCP outputs?

E
Hi E,
Would you ask this again here please: https://www.electro-tech-online.com/threads/radio-control-by-location.152926/

In this thread I hoped to only understand PIC SERVO control, if possible.

C
 

Thread Starter

camerart

Joined Feb 25, 2013
3,730
Hi E,
I have been going through the TRACKER program, and looking at the PWM section.
You needed to write in ASM for Oshonsoft to work, and each PWM output uses 2x PINs for the H bridge which is driving a DC motor.

For this project if possible I would like to use 1x/PIN for each PWM, so does this narrow down my earlier question choices, making
If a dedicated PIC being controlled by a master PIC, to control the PWM outputs was used, and each of the 6x LENGTH times was changed each time, would this work? the best choice?

C.
 
Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
3,730
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
View attachment 148280
Hi E,
I tried 3x servos on an 18lf2520, moving full range using [ If pwm1 = 1023 Then pwm1 = 0
pwm1 = pwm1 + 1 ] in a LOOP.
They appear to work ok, so I'll try this method on a separate PIC from the main LOOP PIC. I think the main PIC LOOP will take too long for the servos.
C.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,730
Hi,
I've been around the houses trying to get SERVO outputs from 6x PINS, and have now succeeded, after a lot of guidance.

Here is a LOOP that will control 6x SERVOs. This SERVO LOOP should be controlled, by a TIMER INTERRUPT, so that the LOOP keeps triggering. The 8000us WAIT after the SERVOs have been controlled, is where the control (MAIN LOOP) is run.

servoloop:
RB0 = 1
WaitUs 1000
RB0 = 0
WaitUs 1000

RB1 = 1
WaitUs 1999
RB1 = 0
WaitUs 1

RB2 = 1
WaitUs 1200
RB2 = 0
WaitUs 800

RB3 = 1
WaitUs 800
RB3 = 0
WaitUs 1200

RB4 = 1
WaitUs 1000
RB4 = 0
WaitUs 1000

RB5 = 1
WaitUs 1000
RB5 = 0
WaitUs 1000

WaitUs 8000
Goto servoloop

C.
 
Top