PDA

View Full Version : HPWM Control



jrudd
- 26th July 2009, 02:47
I have an H-Bridge that can run under joystick control or R/C Transmitter Control.
While running under R/C Transmitter Control, I want the PWM to go to zero if the transmitter is accidentally shutoff or batteries go dead (i.e loss of good pulse signal from the receiver.
I have attached the code I'm working with below. Using a 16f877A@20MHZ.
Right now, when you shutoff the transmitter, the motor goes wild. Full speed to zero speed and back and forth. My last attempt to solve this was to add the line "if duty0>260 then duty0=0" just before the jump to genpwm2: which runs the HPWM command. Note, duty0=255 is max duty cycle. I'm working in the LOOP2: section of the code only right now.
Thanks,
John

ChrisHelvey
- 26th July 2009, 03:52
Hi,

I took a look at what you are doing and I have a thought. (Keep in mind I'm still kind of a newbie, but hey, sometimes a second pair of eyes can help:) If I'm totally off, I'm sorry - just trying to help.

In your lines-

loop2:
pulsin portb.0,1,rcin
rcin2=((rcin-536)*10)/17

Being that you have a word variable for rcin, the result is going to be a 16 bit number (between 0-1024,) but the math seems to need a number greater than 536 or it is going to have some trouble going negative won't it? When your transmitter is on, it is probably OK, but when it is off, wouldn't it read close to zero and end up negative?

I was under the impression that would cause some difficulty. Maybe a test right there would do the trick.

Good luck,

Chris

Bill Legge
- 26th July 2009, 04:42
I think Chris H is right.

1. Assume that your transmitter has failed/turned off

2. The receiver never puts out a pulse.

3. If the pulse never happens the variable is set to zero (PBP manual page120)

4. So rcin= - 5360/17 = - 315 and the PBP will turn this into a two's compliment number: 65,221 or $FEC5 or %1111 1110 1100 0101 (if I've got my maths right?) and this is larger than 300 so your code will loop back to 'loop2.'

5. Meanwhile, the PHWM will continue to follow the previous command.

Actually, I suspect that once the transmitter dies and the carrier is lost, the receiver outpus noise and it is this noise, misinterpreted by your software that causes the motor to surge around.

I've not given it much thought but, assuming the problem is not noise and is caused by rcin = 0 because no pulse is ever received then putting

IF rcin < 2 THEN
....kill the HPWM etc...
ENDIF

just after 'the loope2' PULSIN may fix the problem?

Regards Bill legge

jrudd
- 26th July 2009, 21:01
Thanks for the help guys.
After studying further, when I shut the transmitter off, I realized that some values for duty cycle were correct and would fall through to the HPWM Command. The trouble was that one time it may be full on(255) and the next time zero, thus causing the motor to jerk on and off.
So I setup a routine(testsignal:) to watch 10 straight rcin values. If they were all within +/-5 of each other, I assume that we have a good signal again and jump back to loop2: otherwise, it would keep checking while forcing duty cycle to zero. So now, I can flip the transmitter on and off and the motor stays rock solid at zero speed.
John