Why won't this compile?
I have been trying to figure out why I get an error when compiling Can someone help. I've tried moving sections of code in hopes that I would find a simple solution. Nothing yet. Can someone load this up and tell me what the error " Not within the lower half of memory page" means. I'm using SX/B 2.00.24
Post Edited (SailerMan) : 5/25/2009 2:37:07 AM GMT
DEVICE SX48, OSCHS2
FREQ 50_000_000
Stack 8
ID "Motor"
Baud Con "T19200"
LEDS Pin RE Output
M1_PWM Pin RB.6 Output
M2_PWM Pin RC.2 Output
M1_INA Pin RD.1 OutPut
M1_INB Pin RD.0 Output
M2_INA Pin RB.1 OutPut
M2_INB Pin RB.0 Output
Serial Pin RD.7 Input
Index Var Word
Temp Var Byte
TempB Var Word
Speed Var Word
Command Var Byte
Sub Interrupt 1000
Tasks Run,10
Returnint
EndSub
Flash Task
GetData Func 1
SendData Sub 1
PROGRAM Start
Start:
Low M1_INA
High M1_INB
Low M2_INA
High M2_INB
Tasks Set,0,Flash,50
Tasks Enable
Main:
Do
Do
Command=GetData
LOOP UNTIL Command = "!"
DO
Command=GetData
LOOP UNTIL Command = "M"
Command=GetData
ON command = "S","I" GOSUB SET_SPEED,Info
Loop
End
Func GetData
L_Temp Var Byte
Serin Serial,Baud,L_Temp
Return L_Temp
EndFunc
Sub SendData
SerOut Serial,Baud,__Param1
High LEDS.2
Pause 25
Low LEDS.2
Pause 50
EndSub
Set_Speed:
TempB_LSB=GetData
TempB_MSB=GetData
TIMER2 PWM,Tempb,1024
TIMER1 PWM,Tempb,1024
High LEDS.3
Pause 25
Low LEDS.3
Pause 25
Return
Info:
Pauseus 500
SendData "!"
Return
Task Flash
Toggle LEDS.2
EndTask
Post Edited (SailerMan) : 5/25/2009 2:37:07 AM GMT

Comments
Beyond that, I believe you're going to have a lot of trouble mixing tasks with timing-sensitive instructions like SERIN and SEROUT. Don't do it -- you'll be chasing phantoms every time a task fires a clobbers a SERIN or SEROUT. You should probably stick with ISR serial (plenty of examples in these forums) though you'll have to make adjustments for one pin (I've done this with the SX28 but not the 48 [noparse][[/noparse]which handles TRIS differently]). You can take care of LED blinking and other timing requirements with the ISR as well.
I would still like to know How do I get Set_Speed in the lower half of the code page? What am I missing?
I did an SX48 motor controller for a friend (he paid for it so I can't post the code here) using the PWM function of the timers. As Robert Doerr found out you must disable the TIMER interrupts at the top of the program to prevent bothering the serial stuff -- here's his code to do that (which I used in my friend's program):
If you declare SET_SPEED with SUB the program might work out -- but I think ON x GOSUB is not a good idea; it's an old compatibility thing and with declared subs and funcs GOSUB is outdated. See my AppMod program for handling commands cleanly.
Oh... I added a "heartbeat" LED in the ISR where you were attempting to do it with a task; I also have activity LEDs for RX and TX though they are on very briefly at 19.2K.
Post Edited (JonnyMac) : 5/25/2009 6:40:55 PM GMT
That for such wonderful help... I've just printed out your program and am going through it line for line to understand how it works. ASM has never caught on with me..I keep trying. It's so heard for me to think low level. I've actually started reading the Beginning ASM for SX PDF.
I posted a picture of the board that I am designing.. I had my first prototype made at www.batchpcb.com
Here is a link to my first endeavor. http://forums.parallax.com/showthread.php?p=809620
Thanks so much for taking the time to provide such great assistance.
Best Regards,
Eric
I used your program... really great... the only problem I'm having is when the SX is sending the Version to the propeller... I have attached the scope picture for you to see. Any Ideas?
Regards,
Eric
Post Edited (SailerMan) : 5/27/2009 2:29:34 AM GMT
I tested my code with a BASIC Stamp because it was convenient (on the PDB). If you're using the Propeller to talk to this motor controller (which is a mystery when you can program a cog to do the work you're farming out to the SX...) you'll need to use the FullDuplexSerial object and set it up like this ("mctrl" is an FDS object):
This says you're using pin 0 for TX and RX, that you're ignoring the TX echo on RX, that you're using an open mode, tx and rx polarity is true, and you're communicating at 19.2K. Since you're using open mode serial you'll need a pull-up on the serial pin.
Post Edited (JonnyMac) : 5/27/2009 6:22:42 PM GMT
I do have a Pull-up on the serial line. I'll keep testing. Thanks for your help.
Don't wait on me to figure this out -- but I'll keep trying as I, too, want to connect SX devices (mostly EFX-TEK products) to the Propeller.
Is how the code is written but motor 2 is tied to
And is not configurable on my board.... I hope this can easily be fixed in code.
I think this section of code is why it's not working.
Transmit: ASM MOV FSR, #serial ' (2) TEST txCount ' (1) transmitting now? JZ TX_Done ' (2/4) if txCount = 0, no DEC txDivide ' (1) update bit timer JNZ TX_Done ' (2/4) time for new bit? MOV txDivide, #Baud1x0 ' (2) yes, reload timer STC ' (1) set for stop bit RR txHi ' (1) rotate TX buf RR txLo ' (1) DEC txCount ' (1) update the bit count MOV W, #$0F ' (1) read TRIS_A MOV M, W ' (1) MOV !RD, W ' (1) ---------------------------------------- Here ??? MOV tmpTris, W ' (1) copy to tmpTris MOVB tmpTris.7, txLo.6 ' (4) new bit to tris MOV W, #$1F ' (1) update TRIS_A MOV M, W ' (1) MOV !RD, tmpTris ' (1) TX_Done: ENDASMAm I thinking in the right way?