Prop Cog, Object, Method hierarchy
Don Pomplun
Posts: 116
I've been battling strange happenings in my prop spin code for my house control computer. It uses all 8 cogs in half a dozen objects, most with plenty of PUB & PRI methods. As I look for my problems, some hierarchy questions arise. e.g., an object cognews a method located "halfway" down the code. There are PUB & PRI methods textually located both before and after. I'm wondering if the "physical" location of these has a bearing on which cog they run in, etc.
For instance, object 1 initially cognews method D. Methods A, B & C precede D in the listing, and E, F & G follow it. If something in object 2 calls F, is there a connection to D's cog? Or doesn't it make any difference?
Maybe all my PUB methods in object 1 should be located before D, which runs in its own cog(?)
TIA
Don
For instance, object 1 initially cognews method D. Methods A, B & C precede D in the listing, and E, F & G follow it. If something in object 2 calls F, is there a connection to D's cog? Or doesn't it make any difference?
Maybe all my PUB methods in object 1 should be located before D, which runs in its own cog(?)
TIA
Don
Comments
Start with your overall description ... what is the hardware you have? how is it connected to the Prop? what is the house computer supposed to do? how is it supposed to behave?
Or maybe arrays are not dimensioned big enough.
Or a more complex data-structure is updated by COG 1 and COG 2 reads the date without being synchronized to COG 1.
...
From a SPIN point of view all 8 COGs are equal! Which COG is used for which method depends on which COG is the next free one when doing the COGNEW. No dependency on where the code is located in the source-file!
Is there a connection? Well ... if F and D use the same global variables, then this is a connection. If F and D only use local variables (which are placed in the individual stack) or distinct global variables then there is no connection.
The location of the code in the source file is not relevant.
It would be better to post your code, then we can work on that and point you to the right direction.
Have to weigh the time-dependent stuff for cog usage. The system spends 99.99% just incrementing the time and checking to see if anything is scheduled to be done. Keypads & motion detectors need to be serviced as events occur, but on the whole, it's almost no activity over 24 hours (86400 seconds).
Of course, it's easy to adjust if your main loop requires other than 100ms to do its work. Ideally, it should be less than one second and an even multiple to simplify the update_rtc method.
It appears that my current remaining problem is associated with the serial handler. One cog continually updates a serial LCD display. Another polls for incoming serial characters from an X10 radio receiver that gets signals from wireless motion detectors & keypads. Conflicts seem to occur that hang up one and/or the other of these processes.
I see one *solution* as combining these processes in one cog so that screen updates are postponed whenever a poll sees an incoming character, and that process is carried thru to completion. That wouldn't create any visible impact since incoming strings are only a half dozen bytes at 9600.
But I see a problem with my next upgrade which will add a bunch of button pads which will be hard-wired to a serial input. This necessitates two serial input pins. I'm not sure how I implement another fullDuplexSerial. Any help here appreciated!
Don
Since I have the link handy, I thought I'd mention Tracy Allen's four port object FullDuplexSerial4portPlus_0v3. It watches for framing errors, has adjustable rx and tx buffers and fixes the flow control bugs in Tim Moore's original code. It's the best version of Tim Moore's four port object I'm aware of.
Don
A couple of things stick out to me.
If you're using a pin as a serial tx or rx line don't set the "dira" or "outa" for it. The serial object will take care of that for you. It looks like you're setting the direction of pin 3 at the beginning or your code and also using pin 3 for your LCD tx pin.
Does you LCD really need an inverted signal? Whenever I've used a serial LCD, I'm pretty sure I just had the "mode" set to zero.
And finally, you need to adjust the rx and tx buffers within the serial object to the size you want. I'd suggest something around 64 (it doesn't need to be a power of 2).
Here's the section with the buffer sizes:
Since you're using port #1 change the values of "TX_SIZE1" and "RX_SIZE" to the values you want. You might want to reduce the size of the other buffers you're not using while you're there.
Also the "Start" method returns zero if no cog is available, not -1, since one is added to the returned value of the newcog call.
FYI, as you can see, the port numbering starts with zero (as so many computer things). (Do computer programmers say "Hi this is child number zero" when introducing their oldest child?)
Edit: I just realized I was looking at Tracy Allen's "FullDuplexSerial4portPlus_0v3 ". I'm not sure if it has the same code as "FullDuplexSerial4portPlus".
My *real* code uses both ports 0 & 1. Just used #1 in the test because that's where the already working LCD panel is connected. It uses *inverted* because it goes thru an RS422 converter which also does an inversion. But that hardware works fine with my old code. Took out the DIR's and bumped up the buffer sizes, but all still the same.
Don
You mention you should see a string of "A"s but it looks like the command to send an "A" has been commented out?
Don
Now on to *enhancements*
Don