PBASIC/H-bridge question
Hello All,
I thought this would be fairly simple- but I was wrong. Hopefully someone can help. Im working on a bot that uses an H-bridge to drive two dc motors. In order to make it go forward (or any other direction) 3 pins need to go high. This is fine if I just wanted it to go in one direction, but since I eventually want it to rome anywhere, I have a problem because the stamp sends multiple pins high and sets the h-bridge to "brake" with my current code (because all 5 pins go high). My code currently looks like this:
'Forward
High 1
High 3
High 5
'Backward
High 1
High 4
High 2
I searched the pbasic reference to see if I can set 3 pins high on one line of code, but maybe I missed it. Do I need to set up constants perhaps? Any suggestions would be greatly appreciated My fabrication skills are obviously better than my programming skills!
Thanks,
NOL1
I thought this would be fairly simple- but I was wrong. Hopefully someone can help. Im working on a bot that uses an H-bridge to drive two dc motors. In order to make it go forward (or any other direction) 3 pins need to go high. This is fine if I just wanted it to go in one direction, but since I eventually want it to rome anywhere, I have a problem because the stamp sends multiple pins high and sets the h-bridge to "brake" with my current code (because all 5 pins go high). My code currently looks like this:
'Forward
High 1
High 3
High 5
'Backward
High 1
High 4
High 2
I searched the pbasic reference to see if I can set 3 pins high on one line of code, but maybe I missed it. Do I need to set up constants perhaps? Any suggestions would be greatly appreciated My fabrication skills are obviously better than my programming skills!
Thanks,
NOL1
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
Thanks for the reply. Unfortunatley, Im not sure how to do that. Any code example would be great.
Nol1
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
Im still not very sure what to do with your info. I apologize for being so slow. I copied and pasted both the OUTl and OUTH labels into a new program,and it did not turn the motors on. How do I integrate those labels into a program to turn the motors on? Im using a BS2.
Nol1
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
Its a BS2
OutA is pins 0, 1, 2, 3 used as outputs.
OutB is pins 4, 5, 6, 7 used as outputs.
OutL (OutLow, get it?) is 0..7
So, you can set high or low sets of four pins at a time. Now all you have to do is assign the pins so you can control the groups you desire to control.
Thank you for the reply. Could you please give me a small code example using pins 1,3, and 5 that would get set to high?
Nol1
OUTL = %01010100···· ' Set pins 1,3 and 5 to HIGH
or
OUTS = %0101010000000000···· ' Set pins 1,3 and 5 to HIGH
Thanks for the reply- It tried your code and unfortunately it did not work. Is there anything else I need to add to your code to make the motors turn on?-ie, declaring varibles or constants or subroutines? Does anyone else have any suggestions?
Thank you,
nol1
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
Here is the code I have tried as per yours and Jonathon's suggestion:
OUTPUT 1
OUTPUT 3
OUTPUT 5
OUTS = %0101010000000000
This does not turn the two motors on. The bs2 is not damaged (I dont think) because after running the above code, if I run :
High1
High3
High5
the motors turn on/forward.
I guess the question I should be asking is-What type of code sequence would you write to make pins 1,3,5 go high using just one line of code?
Thanks again,
nol1
DIRS = %0101010000000000 ' Set pins 1,3 and 5 to be outputs
OUTS = %0101010000000000 ' Set pins 1,3 and 5 to high
Jonathan, binary numbers are expressed in most significant bit order for PBASIC, I believe your binary numbers were written in least significant bit order.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
Post Edited (Paul Baker) : 7/20/2005 3:47:56 AM GMT
Thank you very much for your patience. Your code worked for the backward motion part, but only one motor turns with your forward code. What exactly is the logic behind the "%00010110" scheme? I understand that it sets pins high or low with the 1 or 0 respectively, but when I try random combos of the 1's and 0's not much happens. If I could understand how to translate:
High 1
High 5
High 3
Into the %0101.... format, I would be a very happy man!
Thanks again,
nol1
Ok %00010110 is a binary number, the rightmost number is called the least significant bit, the leftmost bit is called the most significant bit. When you write a value to OUTL you are assigning values to pins 0 through 7, the rightmost bit represents pin 0, leftmost bit represents pin 7, so reading the above binary value you are setting pins 1, 2 and 4 high (each digit place represents the value of the pin 1=high, 0=low), you are also simultaneously setting bits 3 and 5 to low. The other bits (0,6 and 7) do not affect the value on pins 0,6 and 7 because the DIRL = %0011... set them as inputs.
As far as OUTL = %00101010 not working for forward, Im not sure because I don't know what points in the H-bridge are connected to which pins. (ie I can't determine if setting pins 1, 3 and 5 high and pins 2 and 4 low will correctly generate the signals to make the motor go forward, Id have to see a schematic or your description of thier connections). You state only one motor works with the forward code, are you sure the two motors·(and H-bridges) are connected the same? And you are duplicating the same signal to both h-bridges by setting pins 1,3 and 5 high and 2 and 4 low?
To summerize the binary numbers again, assigning a binary value to OUTL:
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
Post Edited (Paul Baker) : 7/19/2005 2:16:43 PM GMT
Good news. With your help, Im finally able to proceed! The problem was (besides my ignorance) was that the DIRL = %0011110 code was missing a 1, so pin # 1 was being setup initially as an input instead of an output. Thank you for explaining the binary scheme- it was easier than I thought. So far, my now successful and very simple code looks like this:
DIRL = %00111110 'sets pins to output
' 76543210 pin numbers
Main:
OUTL = %00101010 'forward
PAUSE 3000
OUTL = %00010110 'backward
PAUSE 3000
OUTL = %00011010 'Right turn
PAUSE 3000
OUTL = %00100110 'Left turn
PAUSE 3000
GOTO Main
Thanks again,
nol1
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10