40X1 and HPWM, and apparently losing the program.

hackman127

New Member
I am trying to use HPWM to control a dual Half-H, but for some reason only hpwmA is going high. So to test it, I send this command:

hpwm 0, 0, %1111, 127, 512

hpwmA goes high, but B-D do not. I verified that I do in fact have an X1 by checking the firmware under the options screen. I have no idea what I need to do to make HPWM work.

Also, I intermittently lose the program. When I turn it on, it does not respond to any of the sensory input, but a quick re-program makes things work just fine.

Any ideas?
 

SD2100

New Member
Also, I intermittently lose the program. When I turn it on, it does not respond to any of the sensory input, but a quick re-program makes things work just fine.
I doubt that your losing the program, it's more likely to be something your code thats causing it to not respond.
 

hackman127

New Member
It's very simple code. I can turn it on and off several times, but it seems that if I let it sit for a while, it just doesn't work. When it does, it pauses for 100ms before my motors start running. When it decides to not work, the motors start instantly, and a re-program even while the picaxe is running always fixes the problem. If I do not re-program, it will not work again.
 

inglewoodpete

Senior Member
I would start looking around your download circuit and/or reset pins. Are they wired as per the manual?
 
Last edited:

hackman127

New Member
I would start looking around your download circuit and/or reset pins. Are they wired as per the manual?
Here is a link to the schematic for my CPU board:
http://images.adamthree.com/mbot/40xCPUv2.pdf

The only difference is the 220k on the serial out, but that really shouln't make a difference. Just provides a higher impedance if I want to use serial out as an output (which I can't do with the 40x), that is a leftover from the 08M board that I made. The reset circuit works well and I have no problems with the board running. When it does not respond to sensory input, it will still take a program via serial, so I have no idea what's going on with that. I'd mostly like to know how to use HPWM so I can have PWM in forward and reverse.
 

hackman127

New Member
Just an FYI, here's my code:
Code:
symbol IR_IN = b0
let    IR_IN =  0
main:
   pause 10
   readadc 1,IR_IN
   sertxd("IR_a = ", #IR_IN, 13, 10)
   if IR_IN <= 100 then 
      pwmout 1 , 10, 360
      pwmout 2 ,  0, 360
   else
      pwmout 1 , 30, 360
      pwmout 2 , 30, 360
   endif
 
   goto main
 

Technical

Technical Support
Staff member
R2 is on the wrong side of R1 in your circuit, a common mistake that people make.

For half mode hpwm you need something like

hpwm pwmhalf, pwmHHHH, 100, 127, 512
not
hpwm 0, 0, %1111, 127, 512 (which selects single mode, not half mode)

See hpwm description in part 2 of the manual for more details.
 

hackman127

New Member
R2 is on the wrong side of R1 in your circuit, a common mistake that people make.
Ah! I never caught that. Thanks!
hpwm pwmhalf, pwmHHHH, 100, 127, 512
Ok. I wasn't too sure, since there was no example code in the hpwm section. It seemed to me like the pwmhalf were just placeholders in the docs that corresponded to the numbers in the tables below. I will try that once I get my R1/R2 problem fixed.
 

hippy

Technical Support
Staff member
It's very simple code. I can turn it on and off several times, but it seems that if I let it sit for a while, it just doesn't work. When it does, it pauses for 100ms before my motors start running. When it decides to not work, the motors start instantly, and a re-program even while the picaxe is running always fixes the problem. If I do not re-program, it will not work again.
I'm not quite sure how "just doesn't work" and "will not work again" are meant here, you'll need to be more explicit in explaining what the failed condition is and exactly how the motors behave differently when working as expected and when not. Does it behave differently when "not working" after the reset button is pushed ? Does it behave differently after left with the download cable connected and with it removed ?

Your circuit diagram doesn't show how the motors or input sensor are connected to the PICAXE so it's hard to tell where any problem may be.
 

hackman127

New Member
Well, I moved the resistors to the right places on the serial input, and the reliablity problem seems to be much better, but I still cannot get the HPWM to work right.

I am running it in single mode so that I can drive all 4 channels of my H-Bridge. I told everyone wrong earlier, it is a Quad Half-H (SN754410), not a dual, that I am using to drive 2 motors so that I can run them forward and reverse. Here is a link to my schematic:
http://images.adamthree.com/sherman/sherman_schematic.pdf
In the schematic, I just put port tags to point to where the IO is going to in the 40X1, that way I didn't have to put all 40 pins on the schematic. :)

Since I am running all 4 channels of my quad half-h, I am running hpwm in pwmsingle. Here is my test code:
Code:
[/FONT]
[FONT=Arial]main:
   hpwm pwmsingle, pwmHHHH, %1111, 127, 512
   pause 300
   hpwm pwmsingle, pwmHHHH, %0000, 127, 512
   pause 300
   goto main [/FONT]
[FONT=Arial]
Now let me make it clear that to test it using this code, I am simply connecting 1 channel of my h-bridge at any given time to each one of the 4 outputs. Obviously if I lit up all 4 channels with the motors hooked up as they are in the schematic, nothing would happen. So the problem is, with that code above, only HPWM-A is going high, B-D are not.
 
Last edited:

BeanieBots

Moderator
I've not played with hpwm but assuming (and I may be completely wrong) the PWMout commands are similar to standard PWMout commands:-
if IR_IN <= 100 then
pwmout 1 , 10, 360
pwmout 2 , 0, 360
else
pwmout 1 , 30, 360
pwmout 2 , 30, 360
endif

is not going to work on account that duty must not be more than 4X period.
Try pwmout N,64,128 for about 50%
 

hippy

Technical Support
Staff member
I think you may have misunderstood the way HPWM works. It's probably worth looking at Microchip's Application Note AN893 and the datasheets for the PICmicros which implement HWPM ( 16F688 for 28X1/40X1 )

HPWM provides up to four signal lines which can be connected directly to full and half-bridge drivers to control a motor. You cannot control two motors independantly at the same time using HWPM.

The output you are seeing seems to be correct for what would be expected in the HPWM mode you have chosen but I haven't checked the datasheets.
 

hackman127

New Member
HPWM provides up to four signal lines which can be connected directly to full and half-bridge drivers to control a motor. You cannot control two motors independantly at the same time using HWPM.
Hm. The picaxe docs are rather misleading, then. The docs say for single mode:
Code:
single - A and/or B and/or C and/or D (each bit is selectable)
which lead me to believe that I could do as they say and select each individual bit to be on or off by sending a bitmask:
Code:
single mode - bit mask %0000 to %1111 to dis/enable DCBA
Does single mode not work or am I just totally missing it?
 

Technical

Technical Support
Staff member
In single mode you can 'bit select' the outputs to decide which outputs actually show the PWM signal (between 1 and 4 outputs). This is mainly used to select which pin you want the pwm signal to appear on. But in this single mode all 4 outputs (if all enabled) will be exactly the same, which is why Hippy says you cannot have separate control of 2 motors.

Therefore your circuit idea as drawn will not work.
 
Last edited:

hackman127

New Member
In single mode you can 'bit select' the outputs to decide which outputs actually show the PWM signal (between 1 and 4 outputs). This is mainly used to select which pin you want the pwm signal to appear on.
So if I run single mode with a bit select of %1111, I should have PWM on all 4 HPWM pins, correct? If that is correct, I can control 2 motors independently, I just cannot control the speed independently, which is not problem. But if that is the way it is supposed to work, it is not. If that is the case, the following code should pulse PWM on all 4 ports, correct?
Code:
[FONT=Arial]main:
   hpwm pwmsingle, pwmHHHH, %1111, 127, 512
   pause 300
   hpwm pwmsingle, pwmHHHH, %0000, 127, 512
   pause 300
   goto main[/FONT]
[FONT=Arial]
[/FONT]
 

hippy

Technical Support
Staff member
Lack of response usually means no one's tried it, or those who have haven't passed by. I'd say it was almost there but you still have a duty greater than four times the period ( BeanieBots post #11 ). Try ...

-- hpwm pwmsingle, pwmHHHH, %1111, 127, 255
-- do : loop

I'm not sure what a mask of %0000 will do without reading the datasheet and it's probably easier to get one part working then move on to the next. Also check the outputs are working with a scope or possibly a Led+R, don't rely on what your motors do. I've no idea how your circuit would behave in this mode; if the motors don't move it doesn't mean there isn't PWM happening as it's meant to.
 

hackman127

New Member
Also check the outputs are working with a scope or possibly a Led+R, don't rely on what your motors do.
The motor circuit has been tested a variety of ways and works correct. Just to be safe, though, I checked each hpwm output with a scope, and found the same. Only HPWMA has pwm on it. I've tried a variety of commbinations with the same result. I've decided to just forget using hpwm and I'll use pwm 1 and 2 and use some other means to control going to reverse.
 

BeanieBots

Moderator
Single transistor and DPDT relay for reverse has always been my prefered choice. Only one transistor gives higher effciency, especially at lower voltages.
 

hippy

Technical Support
Staff member
This needs further investigation

I checked each hpwm output with a scope, and found the same. Only HPWMA has pwm on it. I've tried a variety of commbinations with the same result.
I think this needs further investigation from Technical or someone else with a 40X to determine if HPWM does work or does not in all its various modes.

The evidence so far suggests it doesn't, but I am sure that HPWM firmware has been tested, so it would be useful to know where the problem is.
 

hackman127

New Member
Single transistor and DPDT relay for reverse has always been my prefered choice.
I wanted to try to stay away from having to use a relay, but if I have to I will. I have a couple TI analog switches (TS5A3159) that I may try. I've never used them before, I got a few because they looked interesting. I would guess that these would be much more effecient for my purposes than a 3904/relay combo.
I think this needs further investigation from Technical or someone else with a 40X to determine if HPWM does work or does not in all its various modes.
I would agree. I cannot see where I am doing anything against what the docs say, so that's why I'm confused. If I use the legs as digital outs, they work just fine.
 
Top