Shop OBEX P1 Docs P2 Docs Learn Events
Why won't this compile? — Parallax Forums

Why won't this compile?

SailerManSailerMan Posts: 337
edited 2009-05-28 00:43 in General Discussion
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

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

  • JonnyMacJonnyMac Posts: 9,213
    edited 2009-05-25 15:15
    The reason your program won't compile is that SET_SPEED isn't located in the lower half of a code page.

    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.
  • SailerManSailerMan Posts: 337
    edited 2009-05-25 16:04
    OK Thanks for the advice with Serin/Serout. I will look at the examples. I took out the Task stuff out and everything works great.

    I would still like to know How do I get Set_Speed in the lower half of the code page? What am I missing?
  • JonnyMacJonnyMac Posts: 9,213
    edited 2009-05-25 16:22
    We do a lot of AppMod type stuff at EFX-TEK and I found that I had created a template program for the SX48 -- even though we never used it in a product. This works, though it is designed to be compatible with the PSC so it has two baud rates: 2400 and 38.4K, and is addressable (%00 to %11). Of course, you can rip the baud and address stuff out if you want as there are constants built into the program for standard baud rates.

    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):

    ' Disable T1 and T2 interrupts
      ' -- could cause problems with serial comms
      ' -- credit: Robert Doerr for discovery & solution
    
      tmpB1 = T1CNTA                                ' read T1 control register
      tmpB1 = tmpB1 & %1101_1010                    ' disable all T1 interrupts
      T1CNTA = tmpB1                                ' write updated T1 ctrl reg
      tmpB1 = T2CNTA
      tmpB1 = tmpB1 & %1101_1010
      T2CNTA = tmpB1
    



    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.
  • JonnyMacJonnyMac Posts: 9,213
    edited 2009-05-25 18:30
    After a month of non-stop Propeller programming I have some SX work to do so I used your program as a warm-up. I've converted the other program to fixed baud using your Sio pin -- though I changed a couple of the motor control pins for wiring convenience. I've only tested the basic communications; I leave the rest up to you.

    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
  • SailerManSailerMan Posts: 337
    edited 2009-05-26 00:49
    JonnyMac,

    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
  • SailerManSailerMan Posts: 337
    edited 2009-05-27 02:18
    JonnyMac,

    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
    556 x 545 - 49K
  • JonnyMacJonnyMac Posts: 9,213
    edited 2009-05-27 17:37
    FWIW... you probably don't understand the details of SERIN and SEROUT -- you happily use them. As the ISR works you can do the same. The only reason for understanding the gritty details is to change the code. Are you ever going to want to do that? Mind you, I'm not trying to dissuade you from understanding the code, but think you should focus your energies on the overall project.

    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):

    mctrl.start(0, 0, %1100, 19_200)
    



    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
  • SailerManSailerMan Posts: 337
    edited 2009-05-27 18:30
    Serial.start(0, 0, %1100, 19_200) This is how my propeller is set up... I don't have problems sending information only recieving it.

    I do have a Pull-up on the serial line. I'll keep testing. Thanks for your help.
  • JonnyMacJonnyMac Posts: 9,213
    edited 2009-05-27 18:36
    Well... I'm beginning to thing the issue is with the Propeller. I took the motor control code I wrote for you and put it into a loop spitting out the characters of the alphabet; I can receive this into the BS2 and directly to a terminal (via the RS-232 level shifter on the PDB). But... the Propeller does not like the stream (and I tried FullDuplexSerial as well as Simple_Serial).

    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.
  • SailerManSailerMan Posts: 337
    edited 2009-05-27 18:58
    I'm at work right now and unfortunately I won't be home for a few hours.. but I will be back at it. I'm honestly a little relieved that you are having problems too because I toyed around with this for a while last night. [noparse]:)[/noparse]
  • JonnyMacJonnyMac Posts: 9,213
    edited 2009-05-27 19:15
    Okay, I'm not sure what I fixed but it is now working. See attached.
    595 x 484 - 127K
    640 x 480 - 567K
  • SailerManSailerMan Posts: 337
    edited 2009-05-28 00:43
    I got it to work also.. but I have Isolated my problem and am unsure how to fix it...

    Sio             PIN     RD.7  INPUT  TTL    ' I/O to host (10K pull-up)
    
    M2Pwm           PIN     RC.2  OUTPUT
    M2InA           PIN     RC.1  OUTPUT
    M2InB           PIN     RC.0  OUTPUT
    



    Is how the code is written but motor 2 is tied to

    RD.1 and RD.2
    



    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:
      ENDASM
    



    Am I thinking in the right way?
Sign In or Register to comment.