Shop OBEX P1 Docs P2 Docs Learn Events
Noobish question about cogs — Parallax Forums

Noobish question about cogs

mattbutskomattbutsko Posts: 8
edited 2011-09-27 18:23 in Propeller 1
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.
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 number
I 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

  • AribaAriba Posts: 2,690
    edited 2011-09-26 18:37
    Your pseudo code looks okay, if you use global variables for seconds and minutes (must be defined in the VAR section, and the counter and display methodes must be in the same file as this VAR section).

    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
  • mattbutskomattbutsko Posts: 8
    edited 2011-09-27 17:27
    An often made mistake is: Each cog has its own DIRA and OUTA registers

    THIS! I was totally unaware of that. Swapped my dira/outa block and it fired up like a champ. Thanks!
  • Cluso99Cluso99 Posts: 18,069
    edited 2011-09-27 18:14
    Mattbutsko: I see you are new here, so welcome to this fabulous prop chip and forum. Pleased your problem is solved. If more than one cog outputs to the same pin the results will be or ed internally. No hardware problems with this and can be used to advantage sometimes.
  • mattbutskomattbutsko Posts: 8
    edited 2011-09-27 18:23
    Yeah my bad, I marked it.
Sign In or Register to comment.