Full Duplex Serial
I currently have my SX28 talking to my Propeller using the Propellers (bs2 Serial Object) I then decided to try the Full Duplex Serial and the poop has hit the fan. I can't seem to get anything working correctly.· I'm Using mode %1010 on the Propeller side.
Does anyone know what could be happening? Any working sample code between the Prop and the SX28 would be apreciated... Just to make sure I have my setup right.
Thanks in Advance,
Eric
·
Does anyone know what could be happening? Any working sample code between the Prop and the SX28 would be apreciated... Just to make sure I have my setup right.
Thanks in Advance,
Eric
·

Comments
I'd enclose my code but it's gettting a little hard to read... I need to clean it up.
but if It was working with the spin code (BS2 Object) I can't see why it will not work with the Full Duplex ASM code.
Here is the Prop Code
Con _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 SerialOutputPin = 17 SerialInputPin = 18 Var Long MicroSecond Byte Ramp Long LeftEncoder,RightEncoder long DeltaL,DeltaR Obj Debug : "TV_Text" Serial : "FullDuplexSerial" Pub Main|LastLeft,LastRight,Command,Dummy MicroSecond:= clkfreq / 1_000_000 Serial.Start(SerialInputPin,SerialOutputPin,%1010,9600) Debug.start(12) DirA[noparse][[/noparse]0]:=0 Repeat Command:=254 Serial.TX(Command) LeftEncoder:=Serial.RX RightEncoder:=Serial.RX Command:=170 Serial.TX(Command) Serial.TX(0) Serial.TX(RAMP) Ramp+=1 DeltaL:=(~LeftEncoder) DeltaR:=(~RightEncoder) Display Pub Display DEbug.Out(1) Debug.Str(String(" ",13)) Debug.Str(String("LeftEncoder =")) Debug.Dec(DeltaL) Debug.Str(String(" ",13)) Debug.Str(String("RightEncoder=")) Debug.Dec(DeltaR) Debug.Str(String(" ",13)) Debug.Str(String("RANGE=")) Debug.Dec(RAMP) Debug.Str(String(" ",13)) Debug.Out(1)and Here is the SX/B Code
····
DEVICE SX28, OSCHS2, TURBO, STACKX, OPTIONX, BOR42 FREQ 50_000_000 ID "ENCODER" Baud CON "N14585" PWM_Count VAR BYTE PWM_Values VAR BYTE (4) SerialData VAR BYTE DataInPin Var RC.0 DataOutPin Var RC.1 EncPort Var RA Index Var Byte EncodersOld VAR byte EncodersNew VAR byte Encoder_A_Count VAR Byte Encoder_B_Count VAR Byte tmpB1 VAR byte tmpB2 VAR Byte Temp Var byte Value Var Byte Channel Var Byte Command Var byte ' ========================================================================= INTERRUPT ' ========================================================================= ISR_Start: EncodersNew = EncPort TmpB1 = EncodersOld XOR EncodersNew TmpB2 = TmpB1 << 1 TmpB1 = TmpB1 OR TmpB2 EncodersOld = EncodersOld << 1 EncodersOld = EncodersOld XOR EncodersNew IF TmpB1.3 = 1 THEN IF EncodersOld.3 = 1 THEN INC Encoder_A_Count ELSE DEC Encoder_A_Count ENDIF Else Asm Nop Nop Nop Nop EndAsm ENDIF ' ========================================================================= IF tmpB1.1 = 1 THEN IF EncodersOld.1 = 1 THEN INC Encoder_B_Count ELSE DEC Encoder_B_Count ENDIF Else Asm Nop Nop Nop Nop EndAsm ENDIF EncodersOld=EncodersNew ASM ' ** Setup variables MOV __PARAM1,#4 ' (2) Number of bits per port MOV __PARAM2,#1 ' (2) OR Mask for turning a bit ON MOV __PARAM3,#254 ' (2) AND Mask for turning a bit OFF INC PWM_Count ' (1) Adjust the PWM count ' If the PWM value for each channel is ' less than PWM_Count then it should ' be high, othewise it should be low MOV __PARAM4,PWM_Count ' (2) Make copy of PWM_Count in global memory MOV FSR,#PWM_Values ' (2) Set FSR to address of 1st element of PWM values :NEXT_BIT ' ** First do port B bits CJA IND,__PARAM4,@:MAKE_HIGH_B ' (5/7) If this element is above PWM_Count ' Then jump to MAKE_HIGH_B AND RB,__PARAM3 ' (2) Value is below or equal to PWM_Count so ' make it low. JMP @:DONE_BIT_B ' (4) Jump over MAKE_HIGH code :MAKE_HIGH_B OR RB,__PARAM2 ' (2) Value is above PWM_Count so make it HIGH NOP ' (1) Waste time NOP ' (1) Waste time :DONE_BIT_B STC ' (1) Need to shift a 1 into AND mask value RL __PARAM3 ' (1) Shift AND mask value CLC ' (1) Need to shift a 0 into OR mask value RL __PARAM2 ' (1) Shift OR mask value Inc FSR DJNZ __PARAM1,@:NEXT_BIT ' (3/5) Repeat until done ENDASM RETURNINT ' ========================================================================= GetEncoders Sub 0 ChangePWM Sub 0 SendCommand Sub 1 GetData Func 1 PROGRAM Start NOSTARTUP Start: EncodersNew = EncPort EncodersOld = EncodersNew OPTION = $80 Main: TRIS_B=%00000000 Tris_C=%00000000 Input DataInPin Output DataOutPin Encoder_A_Count=0 Encoder_B_Count=0 Do RC.4=1 Command=GetData RC.4=0 RC.7=1 RC.6=1 If Command=254 then GetEncoders If Command=170 then ChangePWM Loop GetEncoders: Pauseus 100 SendCommand Encoder_A_Count SendCommand Encoder_B_Count Encoder_A_Count=0 Encoder_B_Count=0 Return ChangePWM: Channel=GetData Value=GetData If Value>128 Then PWM_Values(1)=255-Value PWM_Values(0)=0 High RC.7 Low RC.6 Else High RC.6 Low RC.7 PWM_Values(1)=0 PWM_Values(0)=Value*2 Endif Return SendCommand: SerOut DataOutPin,Baud,__Param1 Return GetData: SerIn DataInPin,Baud,__Param1 Return __Param1My SX Baud Rate is to compensate for the ISR
Basically The SX counts encoder pulses and creates PWM on·2 channels.
The Propeller Sends Command (254) to read the Encoders, and Command (170) to set the PWM Channel (0 or 1) + Duty (0-255)
I am noticing that I can Set the Motor Speed. But I can't read the Encoders. Hmmm....
Any help like always would be greatly appreciated
Thanks,
Eric
Post Edited (SailerMan) : 11/9/2006 12:51:12 AM GMT
Did you try using 0,1, or 2 instead of %1010? Start with 0
I could be off but I didn't think there were any other options besides 0 1 2 and maybe 3
Post Edited (originator99) : 11/9/2006 3:14:24 AM GMT
All is good now... I hope!! [noparse]:)[/noparse]
Thanks
Eric