Shop OBEX P1 Docs P2 Docs Learn Events
Cog question — Parallax Forums

Cog question

DiverBobDiverBob Posts: 1,102
edited 2008-04-08 03:19 in Propeller 1
I've been puzzling over this problem for a bit, came to the forum and didn't see anything under the search that told me anything I haven't done/tried so I'll throw the question out to the experts!

I've attached a portion of code used for displaying a series of count up and count down timers on the uOLED-96. There are 3 buttons attached to the uOLED on 18, 19 and 20. When I was checking for a pin to go hi (if dira[noparse][[/noparse]18] == 1) and had this in the main loop it worked. In order to improve the response of the main loop I removed the button check and added a flag instead. The idea is to use a seperate cog to just monitor the button states and set the appropriate flag. The flag is then checked in the main loop and acted upon with the flag being reset at the end of the process.
Now that I started a new cog (I have checked the success flag and it shows cog 2 running) but the SetTimerFlags does not appear to run.

Maybe someone else sees what I am missing.

Thanks for your help in advance!
Bob

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-04-07 23:33
    Just a little something ... "true" is $FFFFFFFF while "false" is $00000000. A single bit like INA[noparse][[/noparse] 5 ] will never be equal to true. Try using 0 and 1 instead as you did for INA[noparse][[/noparse] 18 ].
  • DiverBobDiverBob Posts: 1,102
    edited 2008-04-08 00:00
    I thought I'd done that earlier, I changed the code to ina[noparse][[/noparse]18] == 1 and still no response. I put a print statement in the method that is run by the cog but it never prints???
    This should be simple, I'm missing something basic here. I can get the examples in the manual to run but this has been a pain

    Bob
    ·
  • Mike GreenMike Green Posts: 23,101
    edited 2008-04-08 00:34
    In your check the switches routine, you're using the "!" operator.· This toggles the value.· As this test repeats, the value will be toggled repeatedly very quickly and that will only stop when the switch value goes back to zero.· I don't think that's what you want.· I think you want to use "~~" as a post-fix operator like "nflags~~" to set the value to true.
  • Timothy D. SwieterTimothy D. Swieter Posts: 1,613
    edited 2008-04-08 00:53
    Hi DiverBob -

    I downloaded your code from above to try it out and to see if I could help you. When I first went to compile your code and load it on my uOLED I had to find the other objects. I recommend using the file | archive feature when posting code so that all objects are included. Once I got the objects straight when I compiled the program I got several errors for variables that were undefined. Is this a code snippet because I do not see where it writes to the uOLED display?

    This doesn't help your core problem, but I see one efficiency. I see you have a waitcnt being used to pause program execution. You have already defined the "clock" object. You could use DELAY.PauseSec(1) to pause execution. This would take advantage of the object you are using and it makes the pause not processor speed dependent.

    There may be a problem with the way the buttons/flags are working between the cogs. What I have done in the past is used a COG to read button input. In that same cog the buttons are debounce and both the raw and debounce data is written to "registers" in the HUB RAM. Another COG that handles the program flow checks those registers when it is appropriate. On a second look, maybe that is what you are doing.

    What I would do next is go back to one COG. Have the uOLED screen display the actual I/O. Use INA to read your three pins into a byte and draw that byte on the screen. Press the buttons and see the byte change. Then jump back to two cogs and get the same behaviour to work.· From there implement the flags.· Becareful doing the "print statement" across cogs because you need to make sure everything is defined correctly, the objects may not be talking·to·one another as thought.

    Oh - I would also see if increasing the stack helps. I was going to try this with the downloaded code, but it doesn't compile properly.

    Good luck.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Timothy D. Swieter

    www.brilldea.com·- check out the uOLED-IOC, an I/O expansion for the uOLED-96-PROP
    www.tdswieter.com
    One little spark of imagination is all it takes for an idea to explode

    Post Edited (Timothy D. Swieter) : 4/8/2008 12:58:56 AM GMT
  • DiverBobDiverBob Posts: 1,102
    edited 2008-04-08 02:01
    Thanks for the·info everybody. After my last try, I stopped, had supper and then went back to the coding. Now I see where I went wrong - I was making several assumptions, one of which was·on the value of the flags when using the syntax '!nflag' (thanks Mike!). When I changed it to 'nflag := 1' instead,·I got the desired results. I will try the post-fix operator next (haven't needed to use it so far so time to experiment). I was also trying to toggle the button flags·when I should have just set them to 1 or true (I also mixed up a variety of items as true and 1 - too used to my normal day job programming).·I fixed the code problems and now it works pretty good. Still have some additional features to add but that will have to wait til tomorrow night.

    Tim - I will try the pausesec(1) out but I was going to get rid of the Clock object and just use the internal clock. It seems fairly accurate over the type of time spans I need (up to 3-4 hours) so why use up any more memory than I have to? You are right, I am using the cog just to trigger flags that the main program resets when it gets around to them. I didn't post all the code but cut out the various parts that weren't applicable to the problem, I guess I wasn't expecting anyone to actually try to compile it! The timer will consist of 3 timers, the top one just counts up. The middle one will be user programable to count down up to 10 sequential events with the user able to either have each time period to be consecutive or manual start. The bottom timer is a on-the-fly countdown timer where the user can enter up to 999 minutes and count it down from there. Each counter has a start/stop, reset function and the last button is used to select the timer that the buttons will work on.

    Once the code is completed I will post it if anyone else is interested.

    Bob
  • Timothy D. SwieterTimothy D. Swieter Posts: 1,613
    edited 2008-04-08 03:19
    Thanks for the update Bob. Is this device for the diving equipment that I think you mentioned in another thread?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Timothy D. Swieter

    www.brilldea.com·- check out the uOLED-IOC, an I/O expansion for the uOLED-96-PROP
    www.tdswieter.com
    One little spark of imagination is all it takes for an idea to explode
Sign In or Register to comment.