Using HPWM instead of PULSOUT

Hello,
I have been using the following code to drive my 4WD vehicle forward…

go_forward: for pulsecount = 0 to 400 pulsout 1,(3900) 'go forward at about 90% (20ft) compensate for right veer pulsout 0,(2190) PAUSE 20 NEXT

But, as we know the BAP can’t do anything else until the loop finishes. I would like to have the 4WD move on and execute the next line while the motors are still running. Can I just use the HPWM command to accomplish this? Would the below code be correct or do I have the period and duty backwards (or not correct at all)?

go_forward:
HPWM 1,400,3900
HPWM 0,400,2190

Thanks everyone

HPWM is only available on pins P10, P11 and P12 but yes. As long as the two pulse width signals are in the same period range. Period ranges are 0 to 65535, 65536 to 131071, 131072 to 262143 and 262144 to 524287. Period and duty are in clock cycles(eg 1/16000000 ofr a second on the BAP 24 and 28).

HPWM once started doesn’t stop unless you run a HPWM pin,0,0.

syntax is:
HPWM pin,period,duty

Hey cool! -and this take no processor overhead eh?

So English please… :blush: :laughing: Can you give me an example of how to drive ahead full power (or even half power) and of course reverse. This will give me an idea of how to equate the above numbers into something I can understand and use. Thanks for your response, by the way.

Richard

What are the signal requirements for your 4wd. If it’s just an h-bridge(or any other raw PWM signalling for power) then set your periods at whatever and adjust the duty for speed(eg: 10000, duty would be between 0 and 10000 for 0 to 100% power). If it’s something else I need to know what.

I am using a 2 channel scorpion motor controller so previously I had been using it in “tank” mode with jumper and simple pulsout commands from my Basic atompro 28pin. My rover was using a GPS to navigate, but since it couldn’t (“walk and chew gum at the same time”) run the motors and read the GPS at the same time it had to stop every 10secs or so to read the GPS then make course corrections. I was hoping with the HPWM command the rover would not have to stop to read the GPS.

Thanks for your help
Richard

What rryerson is wanting to do is generate 1 to 2mS pulses every 20mS. :wink: If the resolution is 0.0625uS then;
320,000 = 20mS
32,000 = 2.0mS
24,000 = 1.5mS
16,000 = 1.0mS

If my math is correct this should work. You will have to alter the 2500 to suit your motor speed requirements. Of course 1.5mS should stop the motors. I’m not sure which IDE is required, but am assuming Acidtech’s refrencing the new 8.0.0.0 IDE.

[code]Stop:
HPWM 10,320000,24000
HPWM 11,320000,24000
return

forward:
HPWM 10,320000,32000
HPWM 11,320000,32000
return

reverse:
HPWM 10,320000,16000
HPWM 11,320000,16000
return[/code]

If all you want to do is produce servo style pulses in the background you can use HPWM or you can use HSERVO. I’ve talked about HSERVO before so I won’t go into that. To use HPWM you must set your period to approx 20ms. That would be 16000000 * .020 seconds = 320000. Duty needs to be between 1 and 2 ms so max duty = 16000000 *.002 = 32000 and minimum duty = 16000000 *.001 = 16000. Adjusting Duty between 16000 and 32000 will adjust your pulse from 1 to 2ms.

Note the reason Jims math is wrong is because he has the wrong resolution. Resolution on HPWM is 1/16000000 = .0625us. Jim you were off by 10 so only an order of magnitude. :slight_smile:

I went back and edited my reply to correct the eror. 8)

yeah but if he had got it all right you would not had necessarily explained it so thoroughly. :wink:

Fabulous… I am actually starting to understand it now. Thanks Jim, Acidtech, and Eddie.

Richard

I would try HSERVO, it is designed for that type of pulse.

Hservo does effect other commands. I think the draw on the processor is only 3%. But if you only need 2 channels then hservo is overkill.

Agreed. If you only need (upto)3 servos then hpwm is more processor efficient(eg 0%).

Calculations for total processor usage of HSERVO can be made using the folowing formulas:

50hz refresh, 4 servos/group
worst case
((528groups) + (106servos)) * refresh / clock
best case
((424groups) + (106servos)) * refresh / clock

So 2 servos driven by HSERVO would, asuming you don’t change the default groups from 4 or the refresh from 20ms, take .2385% to .2905%. You could greatly reduce this even further by changing the groups to 1(meaning you’d have to use p0 to p3 for your 2 servos). You’d then be using .0795% to .0925%.