Noobish question about cogs
mattbutsko
Posts: 8
Hey everyone, I don't have the exact code on me but it's likely not required for what I'm asking. I attend vocational school and my instructor wants me to work on a multiplexed 7SD (4 digits) and have it tell time. So the first two digits are minutes, the second two are seconds. Now, I've got some experience in Java and Python, and I'm not too bad at Spin but I'm still learning, so my goal is to do this without too much help but I've hit a dead end.
Setup: I have two objects, one of them just contains methods to display the numbers on the 7SDs, the other has two purposes; keep track of time using a few variables that increment, the other reads the variables and outputs the correct numbers - each purpose has it's own method - pub counter and pub display respectively. It also has a pub main to execute the methods. I launch each method into their own cog.
Problem: Once I have the dual-cog setup using two cognew(a,b) functions (sorry if thats the wrong lingo, used to python and java), nothing happens. Nothing works. If I combine the display and counter methods, then it works, however it's delayed because of the timer.
I'll get a copy of my real code tomorrow, it's on my class PC, but here's the basic pseudo code.
I can have the actual code up tomorrow. Thanks for looking!
Setup: I have two objects, one of them just contains methods to display the numbers on the 7SDs, the other has two purposes; keep track of time using a few variables that increment, the other reads the variables and outputs the correct numbers - each purpose has it's own method - pub counter and pub display respectively. It also has a pub main to execute the methods. I launch each method into their own cog.
Problem: Once I have the dual-cog setup using two cognew(a,b) functions (sorry if thats the wrong lingo, used to python and java), nothing happens. Nothing works. If I combine the display and counter methods, then it works, however it's delayed because of the timer.
I'll get a copy of my real code tomorrow, it's on my class PC, but here's the basic pseudo code.
CON block blah blah blah VAR block blah blah blah OBJ block blah blah blah PUB Main cognew(counter, @stack[0]) cognew(display, @stack[30]) PUB counter repeat increment seconds digit 000X increment seconds digit 00X0 increment minutes digit 0X00 increment minutes digit X000 PUB display repeat if either-secondsORminutes == 0 through 9 { That if block repeats for 0 to 9 for each digit } display corresponding numberI have a feeling it has something to do with the "repeats" that I'm using, but I have absolutely no idea. Now, I totally understand that my code is hardly the most efficient out there, but it's the best I can do right now! If there's any one who can help me understand why the cogs seem to not start, that would be great.
I can have the actual code up tomorrow. Thanks for looking!
Comments
An often made mistake is: Each cog has its own DIRA and OUTA registers, so you have to initialze theme in the right methode. The pins that drive your Display must be set at begin of the display methode, before the repeat, to the right direction and output state.
Andy
THIS! I was totally unaware of that. Swapped my dira/outa block and it fired up like a champ. Thanks!