28x2 4 pwm with pwmdiv

rolandvanroy

New Member
Hello,

Thanks for this great forum with many helpful posts!

I have a question about the pwmout command on 28x2 chip:
I'd like to use 4 independent pwm signals with same frequency. PWM frequency around 250Hz, and preferably the max 1024 duty resolution. (The PWM's drive rather slow hardware, hence the low frequency)

I set the 28x2 frequency at 4MHz, and use pwmout pwmdiv16, B.0, 254, 510 command to set B.0 pin at correct 245Hz with 50% duty, which works well.
Now I do this for B.5 / C.1 / C.2 as well:
(I added a pause inbetween so I can see what is happening to the pins with oscilloscope). Then the program does some pwmduty commands to check duty cycle variation.

What happens: during the init cycle, I see on the scope that B.0 starts with the correct :16 frequency, but after defining the next pwm B.5, the B.0 frequency will reset to the undivided frequency, and when setting C.1, the B.5 pin also goes back to undivided frequency. C.1 and C.2 use same timer, and they stay at the divided frequency. So I end up with 2 pwm's at 3.9kHz and 2 pwm's at 245Hz (where each duty indeed can be set independently)

Is there a way to get 4 pwm's, all with :16 (245Hz) frequency?

I'm using latest version 5.3.5 program editor.

Thanks for your help!

Roland

Code:
init:
       setfreq m4
       pwmout pwmdiv16, B.0, 254, 510
       pause 1000
       pwmout pwmdiv16, B.5, 254, 510
       pause 1000
       pwmout pwmdiv16, C.1, 254, 510
       pause 1000
       pwmout pwmdiv16, C.2, 254, 510
       pause 1000
main:
       pwmduty B.0,10
       pwmduty B.5,20
       pwmduty C.1,30
       pwmduty C.2,40
       pause 1000
       pwmduty B.0,810
       pwmduty B.5,820
       pwmduty C.1,830
       pwmduty C.2,840
       pause 1000
       goto main
 
Last edited:

edski31

New Member
Hi Roland,

I think the command you are looking for is hpwm.

Look at manual 2 padges 86-90 and see if that helps.

Edski
 

Technical

Technical Support
Staff member
Something doesn't sound correct, could be a compiler issue which we will need to check out next week.
In the interval try this after the 4 initial pwmouts (it turns back on the DIV16 bit in the appropriate timers):

Code:
peeksfr $51,b0
bit1=1
pokesfr $51,b0
peeksfr $4A,b0
bit1=1
pokesfr $4A,b0
 

rolandvanroy

New Member
Code:
peeksfr $51,b0
bit1=1
pokesfr $51,b0
peeksfr $4A,b0
bit1=1
pokesfr $4A,b0
[/QUOTE]

Yes! This solved the problem: now all pwm's are running at same :16 frequency.
Duty-cycle can be set for each individual pwm, which was the reason for selecting 28x2.

So seems to be a compiler issue?

Thanks a lot for the fast response!

BTW: I intend to use this application to drive 4 opto-couplers. (as part of a flight simulation motion platform)
 
Top