HW 8 channel SERVO/MOTOR output on 18F4431 (Oshonsoft)

Thread Starter

camerart

Joined Feb 25, 2013
3,724
Hi,
I'm trying to control 5xPWM outputs on an 18F4431 PIC, in Oshonsoft.

I have examples saved, even ASM CODE written by 'E', but they aren't suitable, as most use the CCP modules on the PIC, and there are only 2x.

There is a section in the PIC D/S that shows 8 PWM channels, but they appear to be in pairs, which is confusing.

Can anyone give me a few clues, please?
Camerart.
 

John P

Joined Oct 14, 2008
2,025
As in the best tradition of this forum, you're asking for help and explaining nothing. Please say what frequency these PWM outputs need to have, and how much resolution you need to provide.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,724
As in the best tradition of this forum, you're asking for help and explaining nothing. Please say what frequency these PWM outputs need to have, and how much resolution you need to provide.
Hi J,
Good, I like to keep up the best traditions :)

They are for radio controlled SERVO/MOTOR control, so 20kHz I think.
C
 

Thread Starter

camerart

Joined Feb 25, 2013
3,724
The IC appears to provide 8 single channel PWM, or 4 half-bridge outputs, or 2 full-H bridge outputs.
Hi M,
I read PWM 0 to7.
If so, then I've got to figure out how to set them.

I'm sure I have an example, and I'm still looking for it.
C
 

MaxHeadRoom

Joined Jul 18, 2013
28,617
Hi M,
I read PWM 0 to7.
If so, then I've got to figure out how to set them.

I'm sure I have an example, and I'm still looking for it.
C
The total gives you 8 single PWM channels, if you need half bridge or full bridge, then you are going to exceed those available if using anything but single for a qty of 5.
 

upand_at_them

Joined May 15, 2010
940
A user on here (MMcLaren), and ETO (Mike - K8LH), showed how to handle many servos on a micro by scheduling them (software PWM, not using the hardware PWM on the micro).
 

John P

Joined Oct 14, 2008
2,025
Hi J,
Good, I like to keep up the best traditions :)

They are for radio controlled SERVO/MOTOR control, so 20kHz I think.
C
Do you mean hobby servos? If so, the control signal is at 50Hz, which is 20msec per cycle. And the PWM output is high for a maximum of 2msec out of that period, though you might choose to add a little more, if your particular servo can accept it.

Depending on how much you're paying for a hobby servo, you might find that 100 increments over the 1msec period of variation (not the first 1msec, which is always high) would be as much resolution as the servo can respond to, so that's a 10usec increment of time that you'd have to control.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,724
A user on here (MMcLaren), and ETO (Mike - K8LH), showed how to handle many servos on a micro by scheduling them (software PWM, not using the hardware PWM on the micro).
Hi U,
I think you are talking about any PIN, with proportional ON/OFF, but I hope to use the dedicated PWM PINS.
C
 

Thread Starter

camerart

Joined Feb 25, 2013
3,724
Do you mean hobby servos? If so, the control signal is at 50Hz, which is 20msec per cycle. And the PWM output is high for a maximum of 2msec out of that period, though you might choose to add a little more, if your particular servo can accept it.

Depending on how much you're paying for a hobby servo, you might find that 100 increments over the 1msec period of variation (not the first 1msec, which is always high) would be as much resolution as the servo can respond to, so that's a 10usec increment of time that you'd have to control.
Hi J,
Yes, plus prop motors, with ESCs.
C.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,724
The total gives you 8 single PWM channels, if you need half bridge or full bridge, then you are going to exceed those available if using anything but single for a qty of 5.
Hi M,
I don't think I need half or full bridge.

I need 5x at the moment.
C.
 

BobTPH

Joined Jun 5, 2013
8,813
I am using a PIC PWM at 20Hz?
At what clock speed?

The minimum PWM frequency is:

clock speed / 16 (max prescalar) / 1024.

So for 50 Hz you have:

f / 16 / 1024 = 50
f = 50 * 16 * 1024 = 819200 Hz or an instruction frequency of just over 200,000.

If you need a faster clock, you cannot PWM at 50 Hz

Bob
 

Thread Starter

camerart

Joined Feb 25, 2013
3,724
At what clock speed?

The minimum PWM frequency is:

clock speed / 16 (max prescalar) / 1024.

So for 50 Hz you have:

f / 16 / 1024 = 50
f = 50 * 16 * 1024 = 819200 Hz or an instruction frequency of just over 200,000.

If you need a faster clock, you cannot PWM at 50 Hz

Bob
Hi B,
The 18F4431 uses an 8mHz crystal x 4 so 32mHz.
I'll have to study what you explain, for me to understand.
C
 
Top