Sabertooth 2x5 programming

Hey,

Is there a special way of interfacing the basic atom pro with the sabertooth 2x5 using simplified serial? I’ve tried using the serial data from my PS2 controller and using the SEROUT command to send that data to the sabertooth (from the y-axis of one of the joysticks to test it out). I made sure that the data was within the range of values for the sabertooth (I think it was 1-127, with 64 being stopped) by first outputting to my computer, which it did successfully. However, when I changed the SEROUT to output through a pin to the sabertooth…the motor did respond to different joystick positions, but it only spun in one direction and the different speeds were very random.

I was using a BR of 38400, if that helps any. I also used a lower BR with the same results. In fact, different serial data values didn’t really effect the results (like if I divided the values vs. not doing anything), though if I used a different BR on the ST than on the atom, it wouldn’t work, which is expected. I attached a couple of ceramic capacitors to each of the terminals because I heard you need to do that too, or else the speeds aren’t as precise as they should be, because you get interference…?

Any suggestions? I’m hoping the problem is rather simple and there’s something I’m overlooking again.

-Thanks!

I think you are not sending the data in the proper format. Can you provide an example of the simple Basic Atom program?

It sounds to me like you’re sending at the wrong baud rates. What happens if you’re sending, say, 19200 but its expecting 38400 is that it will only read half the bits you send, but it’ll read them twice. This would cause… unexpected results such as you’re seeing.

Just for a sanity check, can you try analog independent mode briefly to make sure that the driver is working correctly. Then I’d try different baud rates

Also, make sure that the serial output isn’t being inverted (which it might be, depending on your serial port settings)

[code]DAT con P12
CMD con P13
SEL con P14
CLK con P15

index var byte
temp var byte(19)
mode var byte
basespeed var byte(2)
motor1speed var byte
motor2speed var byte

;PS2Init
high CLK

low SEL
shiftout CMD,CLK,FASTLSBPRE,$1\8,$43\8,$0\8,$1\8,$0\8] ;CONFIG_MODE_ENTER
high SEL
pause 1

low SEL
shiftout CMD,CLK,FASTLSBPRE,$01\8,$44\8,$00\8,$01\8,$03\8,$00\8,$00\8,$00\8,$00\8] ;SET_MODE_AND_LOCK
high SEL
pause 100

low SEL
shiftout CMD,CLK,FASTLSBPRE,$01\8,$4F\8,$00\8,$FF\8,$FF\8,$03\8,$00\8,$00\8,$00\8] ;SET_DS2_NATIVE_MODE
high SEL
pause 1

low SEL
shiftout CMD,CLK,FASTLSBPRE,$01\8,$4D\8,$00\8,$00\8,$01\8,$FF\8,$FF\8,$FF\8,$FF\8] ;VIBRATION_ENABLE
high SEL
pause 1

low SEL
shiftout CMD,CLK,FASTLSBPRE,$01\8,$43\8,$00\8,$00\8,$5A\8,$5A\8,$5A\8,$5A\8,$5A\8] ;CONFIG_MODE_EXIT_DS2_NATIVE
high SEL
pause 1

low SEL
shiftout CMD,CLK,FASTLSBPRE,$01\8,$43\8,$00\8,$00\8,$00\8,$00\8,$00\8,$00\8,$00\8] ;CONFIG_MODE_EXIT
high SEL
pause 1

main
;-----------PS2 Mode----------
low SEL
shiftout CMD,CLK,FASTLSBPRE,$1\8]
shiftin DAT,CLK,FASTLSBPOST,[mode\8]
high SEL

;-----------------------------

pause 1

;-----------PS2 Data----------
low SEL
shiftout CMD,CLK,FASTLSBPRE,$1\8,$42\8]
shiftin DAT,CLK,FASTLSBPOST,[temp(0)\8,temp(1)\8,temp(2)\8,temp(3)\8,temp(4)\8,temp(5)\8,temp(6)\8,temp(7)\8,temp(8)\8, |
temp(9)\8,temp(10)\8,temp(11)\8,temp(12)\8,temp(13)\8,temp(14)\8,temp(15)\8,temp(16)\8,temp(17)\8,temp(18)\8]
high SEL
;-----------------------------

pause 1

;-----------Sending data to Sabertooth---------
basespeed(1)=temp(4)/2 'reacts the same with or without the /2

'making sure motor stops at center…doesn’t matter if this part is
'commented or not, it reacts the same
'if basespeed(1)>=70 then
’ basespeed(1)=basespeed(1)-1
'elseif basespeed(1)<=57
’ basespeed(1)=basespeed(1)
'else
’ basespeed(1)=64
'endif

serout p0,i38400,[dec3 basespeed(1)] '<----data out to sabertooth

goto main[/code]

Also, I have 1 motor connected to the M1 motor port, along with a data line connected to S1 and ground connected to the atom pro ground. If I wanted to use two motors in simple serial, would I need to connect another data line to S2?

I’m pretty sure there’s just something wrong with my code (I’m very new to this), but if any programming suggestions doesn’t fix it I’ll look at the Sabertooth itself (Though I’m sure it’s working just fine).

Thanks!

No, in simplified serial mode, commands 1-127 are for motor 1 and 128-255 are for motor two. The psuedocode for it would go something like the following

Void Drivemotor1(char speed)
{
putc(speed)
}

Void Drivemotor2(char speed)
{
putc(speed+128)
}

It certainly looks like you’re using a software generated serial stream. Do you know how accurate that is? Can you try 2400 baud and report if there are any differences?

Try writing a simple test program that does something like the following

for(i = 0; i<60; i++)
{
putc(64+i)
delay .5 seconds
}

and see if you get a smoothly ramping response

Also, make very sure that your serout command is working like a putc and not like a printf. If you can read the output in hyperterminal as plain text ascii, that’s not going to work. The sabertooth is expecting raw data, not ascii formatted plaintext. I’m sorry I’m not more familiar with the basic atom command set.

Ok, I think that’s my problem. Does anyone know what command I should use? I think it’s the shiftout command, but I don’t know how to use it :frowning:

Have you tried something like:

serout p0,i38400,[basespeed(1)\8] '<----data out to sabertooth 

Kurt

No, I haven’t, but I tried it and it works now! Except I get a compiler error with the \8 part, but I deleted that and it works! Not sure why it wouldn’t take it though…

I guess I shouldn’t have left in the DEC3 part.

Thanks!

basespeed(1) is a variable. # is an agrument for some modifiers(eg str). You aren’t using any modifiers in the command so the \8 is a syntax error. If you want to DIVIDE by 8 then you need to use /8. Note the differences between the two slashes.