Pulse Width Modulation

John M

New Member
I have a problem understanding the relationship between Duty Cycle, Period & Frequency, and how to work them out to programme the Command 'pwmout'.

I am trying to build a motor speed controller, and I need to vary the duty cycle between 10 &100%. The spec. from a commercial controller states that it has the following choice of frequency:
Low frequency mode: 100HZ. - Good for low speed control.
Variable frequency: 50 - 1000HZ. - Good all round for slow and high.
High frequency: 2000Hz. - Good for high speed control.

I need to be able to work out the correct programming to get these sort of frequencies. I have tried to use the example in the manual, but can't get sensible answers.

I hope some kind person out there will take pity on me. Any help would be appreciated.

Thanks, John M
 

Dippy

Moderator
Hi. 2 Ques. as I was doing a very similar thing now.

1. Have you tried the Wizard in the programme Editor to calc your PWM values?
2. Are you experienced with Poking PIC registers? If you set prescaler to 1:16 then the minimum PWM you can get @4MHz is just under 250Hz
 

D n T

Senior Member
Pwm Sample

John, like Dippy says, have a play with the PWM wizard.
This is a sample of code that I finished a couple of days ago:

symbol throt = 0 ` Throttle sensor
symbol motor = 1 ` output pin for PWM driver pin

symbol calc1 = w1 `b2 , b3 ` calculation variable
symbol thro_period = w3 `b6 , b7 ' throttle period
symbol throttle = b22 ` throttle reading

if throttle < 12 then stop_

stop_:

pwmout motor, 0,0
throttle = 00
goto Throttle_readout

drive: ` *** Duty cycle only useful from 100% - 50% below that, not enough power ***

calc1 = throttle * 10/145 ` *** Conversion factor from ADC to duty = 14.5(10/145) + 23...
thro_period = calc1 + 23 max 40 ` *** ...to a maximum thro_period of 40 allows for top 50%
pwmout motor,9, thro_period ` define motor speed at 100,000Hz or 100KHz

You probably have this already but ...
I hope this helps, I used the PWM wizard and it made it easy, then I scaled the duty between 10 and 100% at 100KHz.
I only used the maximum throttle period of 40 because at more than that the motor stalled. Note the duty stays the same ( 9 ), I ran a 10K pot as my throttle
good luck
 
Top