Shop OBEX P1 Docs P2 Docs Learn Events
returning form an object back to the main program stack — Parallax Forums

returning form an object back to the main program stack

KeyBoardKeyBoard Posts: 22
edited 2013-10-17 04:28 in Propeller 1
hello all,

I am in a bit of a pickle my current project of a diy remote to communicate with my robot is going well except for an error I came across that I can't solve. I have a main program(RF_DEMO_TX) that calls and object in the program(RF_main) the object determines if the switch is on or off and transmits the signal, but now I need to get back from the object to the main program so that I can check the rest of the buttons and switch's I have tried return but it does not work.

any suggestions

kind regards

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2013-10-15 10:44
    You didn't say, but you're probably starting part of the other object in its own cog and you can't "return" from one cog to another.

    You need to post your code ... as an attachment to a reply ... use the Go Advanced button and use the Attachment Manager that shows up to upload your source files.
  • KeyBoardKeyBoard Posts: 22
    edited 2013-10-15 12:06
    hello,

    the code is attached I need the program to start in the main method of the RF_Demo_tx file after it has check the right_out switch it needs to "return " to the stack to check the right_in switch and then repeat forever

    regards,
    RF_Demo_Tx.spinRF_Main.spin
  • Mike GreenMike Green Posts: 23,101
    edited 2013-10-15 12:16
    What you describe is exactly what your program will do. Your program calls buttons.right_in which will return after the IF statement (there's an implicit RETURN at the end of the method), then it calls buttons.right_out which also returns after the IF statement and the whole thing repeats forever.

    Some comments ... Your indenting is sloppy. Things at the same nesting level need to be indented the same amounts.
    ... You don't call the initialization routine for the BS2_Functions object before you use the other methods in that object. The HIGH() and LOW() methods don't require this, but you should do it.
    ... There are other objects that you either don't use or use only in methods that you're not calling yet. It's best to only declare those that you're using.
  • KeyBoardKeyBoard Posts: 22
    edited 2013-10-15 22:31
    thanks for the comments but it does not work I can get buttons.right_in or buttons.right_out to work on its own but as soon as I use declare both it stops working, I know that after if has finished it will return because it works for my other programs like that but not this one.

    regards

    P.S will a video help
  • kuronekokuroneko Posts: 3,623
    edited 2013-10-15 22:47
    You didn't say what kind of board you have/use (if any) but are you sure you want to drive pin 31 (Data6) or any above and including 28 (EEPROM, boot serial link)?
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-10-15 23:02
    KeyBoard wrote: »
    the code is attached

    But not all the objects are attached. You can archive your program in the Propeller Tool by selecting File\Archive "RF_Demo_Tx"\Project....
    KeyBoard wrote: »
    it stops working

    What does that mean? What were you expecting it to do? What does it do you weren't expecting?
  • KeyBoardKeyBoard Posts: 22
    edited 2013-10-15 23:14
    I have to use the EEPROM pins and the Programming pins because I don't have any others I custom made my board for the remote.
    on the remote I have 6 pots, 4 toggle switchs, a lcd, a 4x4 matrix keypad and the transmitter uses 8 pins.

    I need the program to continually check the state of the inputs and if they change the transmit the signal
  • kuronekokuroneko Posts: 3,623
    edited 2013-10-16 00:44
    You still haven't told us what doesn't work means. Using your main loop:
    CON
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
     
    OBJ
      Buttons : "RF_Main"
    
    PUB main
    
      buttons.setup
    
      repeat
        buttons.right_in
        buttons.right_out
    
    I added a private RF_Main object to light some LEDs with simulated key presses on r_in/r_out.
    CON
      r_out = 0
      r_in  = 1
      
    PUB right_in
    
      ifnot ina[r_out]
        outa[16..23] := %11000001
      else
        outa[16..23]~
        
    PUB right_out
    
      if ina[r_in]
        outa[16..23] := %11000010
      else
        outa[16..23]~
    
    VAR
      long  stack[32]
      
    PUB setup
    
      dira[16..23]~~
      cognew(keys, @stack{0})
      
    PRI keys
    
      dira[r_in..r_out]~~
      repeat
        outa[r_in..r_out]++
        waitcnt(clkfreq + cnt)
    
    This does work - as has already been pointed out - but both function calls get in each others way, i.e. when pin r_out is 0 it sets certain bits to 1 but with r_in being 0 as well they are immediately cleared again (repeat loop). IOW you don't necessarily get a stable signal on your bus.
  • KeyBoardKeyBoard Posts: 22
    edited 2013-10-16 01:38
    it doesn't work because if I use buttons.right_out or buttons.right_in on its own it works I get and output but if I use them together like you did I don't get an output for either switch it got dead but if I then comment out one of them it works again
  • KeyBoardKeyBoard Posts: 22
    edited 2013-10-16 01:54
    here is a link to a video I made with my phone showing the problem https://www.dropbox.com/s/duk1o6laq119tb3/VIDEO0009.mp4 sorry for the shakiness
  • kuronekokuroneko Posts: 3,623
    edited 2013-10-16 02:06
    KeyBoard wrote: »
    here is a link to a video I made with my phone showing the problem https://www.dropbox.com/s/duk1o6laq119tb3/VIDEO0009.mp4 sorry for the shakiness
    For the sake of argument, can you place a 5 sec delay after each call, e.g.
    repeat
        buttons.right_in
        waitcnt(clkfreq*5 + cnt)
        buttons.right_out
        waitcnt(clkfreq*5 + cnt)
    
    and report the result?

    That said, depending on how you print the result it may not show what I'm after. Any chance that you could place some code after each function call indicating that we have been there (as an extreme case you could use the reboot command).
  • KeyBoardKeyBoard Posts: 22
    edited 2013-10-16 02:11
    it seems to be working but because of the delay it will take for ever to send the data I will try smaller and smaller values
  • KeyBoardKeyBoard Posts: 22
    edited 2013-10-16 02:14
    I figure out the problem because it sees right_in as on it transmits that then it immediately sees right_out as off so it transmits that thereby negating the right_in value
  • kuronekokuroneko Posts: 3,623
    edited 2013-10-16 02:20
    KeyBoard wrote: »
    I figure out the problem because it sees right_in as on it transmits that then it immediately sees right_out as off so it transmits that thereby negating the right_in value
    That's what I meant when I said "both function calls get in each others way". Glad you figured it out though.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-10-16 09:30
    It seems like you could use some I/O expansion in your project.

    Shift registers are pretty easy to use and there are both input and output versions.

    I thought I was being clever by reducing the number of I/O pins required by my 4x4 keypad to four pins but I was soon shown there were better ways to read a keypad with fewer pins. There's even a 1-pin keypad object.
  • KeyBoardKeyBoard Posts: 22
    edited 2013-10-17 04:28
    hello,
    does anyone have example code and wiring for the shift registers(74HC165 Parallel to Serial Shift Register, 74HC595 Serial to Parallal Shift Register) that parallax sells I think I would be better that for my project if I can send a string from the transmitter though the shift registers and tx chip to the rx chip and though the shift register again and let the rx prop receive a string. that could work or if anyone has ideas on doing the same thing with code because I don't have much space left on my board.

    kind regard,
Sign In or Register to comment.