Shop OBEX P1 Docs P2 Docs Learn Events
[SOLVED] inverting the output pin connected to CTRA?? — Parallax Forums

[SOLVED] inverting the output pin connected to CTRA??

laser-vectorlaser-vector Posts: 118
edited 2013-02-13 05:21 in Propeller 1
Hi,

I have a servo H-Bridge that i built acording to the schematic below. it seems to be a little backwards compared to most of the others ive seen where the Enable pin is an active low instead of High.
attachment.php?attachmentid=99208&d=1360673122


H-Bridge Truth Table:
_______________________________________________________
FWD REV ENA*
1 0 0 - Turn on upper left source and lower right sink. (go forward)
1 0 1 - Disable lower right sink. When fed a PWM signal the bridge modulates the "forward" current through the motor.
1 1 0 - Turn on both lower left sink and lower right sink, shorting the motor "Braking."
1 1 1 - Disable both lower sinks. When fed a PWM signal the bridge modulates the "braking" of the motor.
0 1 0 - Turn on the upper right source and lower left sink. (go backward)
0 1 1 - Disable lower left sink. When fed a PWM signal the bridge modulates the "reverse" current through the motor.
0 0 0 - Turn off all sources and sinks. "Coast" motor is not engaged at all.
0 0 1 - Turn off all sources and sinks in a different way, same effect though.
_______________________________________________________

ok, so when i use a method like this:
PUB PWM(pin) | x, n , deadline , onepercentticks     

dira[pin]~~
deadline := cnt
onepercentticks := clkfreq/30_000
repeat
  waitcnt(deadline += onepercentticks*100) 
  ctra := 0
  frqa := 1
  phsa := -(onepercentticks * ( 1 #> DUTY <# 100))
  ctra := (%0_00100 <<26) + pin

by setting DUTY to 100
the output would be constantly high (or 1) and the motors are Not Enabled
and by setting DUTY to 0
the output would be constantly low (or 0) and the motors are Enabled

so my H-bridge needs the complete opposite!

i was successful at writing a program where 100 = "stopped" and 0 = "full power"
but things were getting messy in a hurry.

the only way i can think of doing this is to use something like a 74LS04 Not Gate connected to the output pins, but i keep telling myself there's an easier way to accomplish this!
if anyone has any suggestions on how to invert the pin's output controlled by cntra's output i would greatly appreciate it!!

Thanks
600 x 376 - 44K

Comments

  • Mike GMike G Posts: 2,702
    edited 2013-02-12 04:38
    Use an inverter? 74HC04 if memory servers. <- From duplicate post

    Don't the counter have a NOT mode where one is the inverse of the the other? I thought I remember reading that in the manual.
  • kuronekokuroneko Posts: 3,623
    edited 2013-02-12 05:10
    if anyone has any suggestions on how to invert the pin's output or cntra's output i would greatly appreciate it!!
    Use NCO differential (%00101) and use pin B instead of A? Changing the PWM logic should work as well.
  • AribaAriba Posts: 2,690
    edited 2013-02-12 05:29
    You can invert the PWM output by counting down and set a positive pulswith value:
    PUB PWM(pin) | x, n , deadline , onepercentticks     
    
    dira[pin]~~
    deadline := cnt
    onepercentticks := clkfreq/30_000
    repeat
      waitcnt(deadline += onepercentticks*100) 
      ctra := 0
      [COLOR="#FF0000"]frqa := -1[/COLOR]
      [COLOR="#FF0000"]phsa := onepercentticks * ( 1 #> DUTY <# 100)[/COLOR]
      ctra := (%0_00100 <<26) + pin
    

    ..and you don't need to set the counter new in every loop, just once before the repeat loop:
    PUB PWM(pin) | x, n , deadline , onepercentticks     
    
    dira[pin]~~
    deadline := cnt
    onepercentticks := clkfreq/30_000
    ctra := (%0_00100 <<26) + pin
    [COLOR="#FF0000"]frqa := -1[/COLOR]
    repeat
      waitcnt(deadline += onepercentticks*100) 
      [COLOR="#FF0000"]phsa := onepercentticks * ( 1 #> DUTY <# 100)[/COLOR]
    

    Andy
  • laser-vectorlaser-vector Posts: 118
    edited 2013-02-12 08:04
    Thanks for all the replies!

    as soon as i get home today i will investigate these suggestions and post the results.

    p.s.
    I apologize for these novice questions, i am a beginner at using the counters but definitely see their usefulness and really want to learn! so thanks for baring with me :)
  • tonyp12tonyp12 Posts: 1,951
    edited 2013-02-12 08:39
    Are you using Counter Duty mode (Pulse-density modulation) to pwm the motor controller?
    No way that will work, as it's to fast with 12.5ns pulses.
    No h-bridge switch that fast and when going through opto-isolators will smooth out the signal even more.

    Using NCO will give slower square waves, but fixed at 50% duty.
  • laser-vectorlaser-vector Posts: 118
    edited 2013-02-13 05:21
    i managed to achieve this by configuring the BPIN and using NCO Differential as per the advice of kuroneko. but thank you all so much for your advice!!
Sign In or Register to comment.