Problem using Hpwm with 20x2

seagreen

New Member
I am having trouble using the HPWM in FULL mode.
I should be very happy to hear your views as I have wasted all afternoon!
My chip is 20X2 @8Mz
I want to control the duty using an adc output.
My problem is that I only get 1 pwm output on C.5 whatever numbers I use in the HPWM statement.
my code is
dirsC= %0011100
dirsb = %0000100
HPWM 3, 2, 0, 200, 400
adcsetup = %00000001
MainLoop:
input b.0
readadc10 1, w4
HPWMDUTY w4
pause 1
goto mainLoop
 
Last edited:

hippy

Technical Support
Staff member
Welcome to the PICAXE Forum.

What firmware version of the 20X2 do you have ? ... View -> Options -> Mode -> Check Firmware Version

There was an issue with early 20X2 firmware, the workround is to replace your HPWM command with the following ...

PokeSfr $B9, %00001111
HPwm PWMFULL_F, PWMHLHL , 0, <freq>, <duty>
PeekSfr $BD, b0
b0 = b0 | %01000000 | PWMHLHL
PokeSfr $BD, b0
 
Last edited:

seagreen

New Member
problem with hpwm on 20X2 chip

Thanks for your promt reply.
My firmware version is C.1
Picaxe - 20X2 firmware version 1

I decided to try HPWM with a 28X1. Different problem port c hpwm
remains high in both forward and reverse modes.

Regards Ken Green
 

hippy

Technical Support
Staff member
I'm not aware of any issues with 28X1. Again, which firmware version, and perhaps post your code so we can investigate this further.
 

seagreen

New Member
Thanks again
Lets leave aside the problem with 28X2
And go back to my original problem with the 20X2.
Below is your patch.
Using simulation I get the correct levels for driving a full bridge.
note polarity 2 is required HLHL.
However when download to the 20X2 chip it gives Alow Bhigh Chigh Dlow and none is a pwm signal.
This remains whaever the mode is set to (2 or 3)
pokesfr $B9,%00001111
hpwm 3,2,0,249,500 (Mode 3 = reverse)
peeksfr $BD,B0
B0 = B0|%11000000
pokesfr $BD,B0
mainloop:
goto mainLoop

Regards Ken Green
 
Last edited:

hippy

Technical Support
Staff member
I've had time to investigate and have identified the issues for the 20X2. The workround given in post #2 contained a typo ( corrected ), but should have resulted in HPWM output appearing, albeit PWMFULL_R rather than PWMFULL_F as desired.

The workrounds for 20X2 C.0 and C.1 firmware are as follows.

Set the SYMBOL definition to the output pin polarity setting required ...

For PWMHALF mode

Symbol PWMPOLARITY = PWMHHHH

PokeSfr $B9, %00001111
HPwm PWMHALF, PWMPOLARITY, 0, <freq>, <duty>
PeekSfr $BD, b0
b0 = b0 | %10000000 | PWMPOLARITY
PokeSfr $BD, b0

For PWMFULL_F mode

Symbol PWMPOLARITY = PWMHHHH

PokeSfr $B9, %00001111
HPwm PWMFULL_F, PWMPOLARITY, 0, <freq>, <duty>
PeekSfr $BD, b0
b0 = b0 | %01000000 | PWMPOLARITY
PokeSfr $BD, b0

For PWMFULL_R mode

Symbol PWMPOLARITY = PWMHHHH

PokeSfr $B9, %00001111
HPwm PWMFULL_R, PWMPOLARITY, 0, <freq>, <duty>
PeekSfr $BD, b0
b0 = b0 | %11000000 | PWMPOLARITY
PokeSfr $BD, b0
 
Last edited:
Top