PDA

View Full Version : Just want to make sure this code doesn't fry my board before i try it



noobmuncher
12-26-2009, 10:58 AM
I just pulled apart a Christmas present of pass which is an old "RAD Robot" I have. I am using a SN754410 Quad Half H-Bridge IC www.sparkfun.com/commerce/product_info.php?products_id=315 (http://www.sparkfun.com/commerce/product_info.php?products_id=315) to power the opening and closing of the arms and the leaning forward and backwards of the torso. So I have it wired up to my propeller education kit via the pin layout described here www.hobbyengineering.com/appHBridge1A.html (http://www.hobbyengineering.com/appHBridge1A.html) however I am really afraid of frying it with the code I have. I have hooked this up on the BS2 before and it worked fine, but with that I just told two of the 4 signal pins to send HIGH commands and the others to have LOW and then just changed it. With the propeller I am a bit confused by the dira and the outa commands. I just need pins 27 and 25 to receive HIGH while 24 and 26 LOW and conversely.

If some one can help with this very simple problem that would be great, I am just afraid of having something get fried ha ha.

Thanks!

Clock Loop
12-26-2009, 01:11 PM
The chip you mention has recommended operating conditions of at least 4.5v.

noobmuncher
12-26-2009, 01:28 PM
I thought the datasheet said that it's minimum HIGH was 2.5 or am I totally mistaken? Can this be remedied?

StefanL38
12-26-2009, 01:47 PM
Hello noobmuncher,

as you didn't attached your code I can only say a little

DIRA is to set the DIRection of an IO-Pin




DIRA[ 0 ] := 0 'set IO-PIN Number 0 as input
DIRA[ 0 ] := 1 'set IO-PIN Number 0 as output

DIRA[ 27 ] := 0 'set IO-PIN Number 27 as input
DIRA[ 27 ] := 1 'set IO-PIN Number 27 as output




OUTA is for setting the IO-pins voltage




OUTA[ 27 ] := 0 'set voltage on IO-Pin number 27 to 0.0V
OUTA[ 27 ] := 1 'set voltage on IO-Pin number 27 to 3.3V




I enjoyed porting the BS2-example-code to SPIN




{BS2-Code:
MotorID VAR Byte ' Current Motor ID
}
'ported to SPIN
'see lines with PUB MotorBrake(MotorID), PUB MotorReverse(MotorID) etc.

CON
{BS2-code:
Motor1 CON 1 ' Motor 1 control on stamp pins 1, 3 and 5
' SN754410 pins 1 (1,2EN), 2 (1A) and 7 (2A)
Motor2 CON 2 ' Motor 2 control on stamp pins 2, 4 and 6
' SN754410 pins 9 (3,4EN), 10 (3A) and 15 (4A)
}
'ported to SPIN:
CON
Motor1 = 1
Motor2 = 2

LOW = 0
HIGH = 1

{BS2_code:
Loop:
DEBUG CR, "s"
MotorID = Motor1
GOSUB MotorBrake
MotorID = Motor2
GOSUB MotorBrake
PAUSE 1000

....
DEBUG "R"
MotorID = Motor1
GOSUB MotorReverse
MotorID = Motor2
GOSUB MotorReverse
PAUSE 1000

GOTO Loop
}
'ported to SPIN

PUB Main
DIRA[ Motor1 + 0 ] := 1 'setup IO-Pins as outputs
DIRA[ Motor1 + 2 ] := 1
DIRA[ Motor1 + 4 ] := 1

DIRA[ Motor2 + 0 ] := 1
DIRA[ Motor2 + 2 ] := 1
DIRA[ Motor2 + 4 ] := 1

repeat
MotorBrake(Motor1)
MotorBrake(Motor2)
WaitCnt(ClkFreq + cnt) 'wait for one second

MotorCoast(Motor1)
MotorCoast(Motor2)
WaitCnt(ClkFreq + cnt) 'wait for one second

MotorForward(Motor1)
MotorForward(Motor2)
WaitCnt(ClkFreq + cnt) 'wait for one second

MotorReverse(Motor1)
MotorReverse(Motor2)
WaitCnt(ClkFreq + cnt) 'wait for one second
'the INDENTION defines what belongs to the repeat-loop
'no "end of loop statement required even NOT defined in SPIN


{BS2-Code:
MotorCoast:
LOW MotorID
HIGH MotorID + 2
HIGH MotorID + 4
RETURN
}
'ported to SPIN
PUB MotorCoast(MotorID)
OUTA[ MotorID + 0 ] := LOW
OUTA[ MotorID + 2 ] := HIGH
OUTA[ MotorID + 4 ] := HIGH




{BS2-Code:
MotorBrake:
HIGH MotorID
LOW MotorID + 2
LOW MotorID + 4
RETURN
}
'ported to SPIN
PUB MotorBrake(MotorID)
OUTA[ MotorID + 0 ] := HIGH
OUTA[ MotorID + 2 ] := LOW
OUTA[ MotorID + 4 ] := LOW




{BS2-Code:
MotorForward:
HIGH MotorID
HIGH MotorID + 2
LOW MotorID + 4
RETURN
}
'ported to SPIN
PUB MotorForward(MotorID)
OUTA[ MotorID + 0 ] := HIGH
OUTA[ MotorID + 2 ] := HIGH
OUTA[ MotorID + 4 ] := LOW




{BS2-Code:
MotorReverse:
HIGH MotorID
LOW MotorID + 2
HIGH MotorID + 4
RETURN
}
'ported to SPIN
PUB MotorReverse(MotorID)
OUTA[ MotorID + 0 ] := HIGH
OUTA[ MotorID + 2 ] := LOW
OUTA[ MotorID + 4 ] := HIGH




best regards

Stefan

noobmuncher
12-26-2009, 01:49 PM
Now I am not usre if my wiring is correct, I will list it below and if someone can take a look at it and at the hobby engineering link www.hobbyengineering.com/appHBridge1A.html (http://www.hobbyengineering.com/appHBridge1A.html) and let me know what i am doing wrong i would appreciate it.
Pin (of the SN754410) :
1: Vdd
2:P27
3: Motor 1 A
4: Vss
5: Vss
6: Motor 1 B
7: P26
8: Negative terminal on the battery
9: Vdd
10: P25
11:Motor 2 A
12: Vss
13: Vss
14:Motor 2 B
15: P24
16:Positive terminal on the battery

and the code (among many, that i have now tested) is

PUB LedsOn
repeat
dira[24..27] := %1111
outa[24..27] := %0101
waitcnt(clkfreq + cnt)
outa[24..27] := %1010
waitcnt(clkfreq + cnt)

Thank you so much, Happy Holidays!

noobmuncher
12-26-2009, 01:57 PM
Wow thanks alot stefan! I will give it a try, I think the problem was I didn't have the EN set to anything, it was just going to Vdd. Where in your code can I change the variables to use the pins 27-24 and 20 and 19 though? I see this here:

Stefan said...
Motor1 CON 1 ' Motor 1 control on stamp pins 1, 3 and 5
' SN754410 pins 1 (1,2EN), 2 (1A) and 7 (2A)
Motor2 CON 2 ' Motor 2 control on stamp pins 2, 4 and 6
' SN754410 pins 9 (3,4EN), 10 (3A) and 15 (4A)

but I am sorry I am not sure where this is defined in the program.

Thanks again

noobmuncher
12-26-2009, 02:01 PM
Never mind I think I figured it out now, slick programing by the way. http://forums.parallax.com/images/smilies/smile.gif

noobmuncher
12-26-2009, 02:13 PM
So i rewired it to work with your code, however the program didn't seem to do anything. Any idea whats wrong?

StefanL38
12-26-2009, 07:03 PM
Hi,

Clock Loop mentioned that the SN754410-chip needs a SUPPLY-voltage of minimum 4.5V
so supplying it with 3.3V is too low

The IO-Pins start with zero not with 1

To do more analysing you have to provide a schematic of how you wired EVERYTHING
This means connections from Prop to SN754410 and SN754410 with the motor
With ALL pins numbered and named.

best regards

Stefan

noobmuncher
12-27-2009, 03:05 AM
Okay thank you, will do as soon as I get a chance.