Shop OBEX P1 Docs P2 Docs Learn Events
How many hours has my Prop been running? — Parallax Forums

How many hours has my Prop been running?

mosquito56mosquito56 Posts: 387
edited 2008-01-19 18:32 in Propeller 1
·I am looking for a way to keep track of how long the prop is running in real time. Is there a way to intercept the cnt rollover? I read that if you miss a cnt you might have to wait over a minute. This is perfect for my purposes.
· I don't want to tie up a cog to do this. Any ideas?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
······· "What do you mean, it doesn't have any tubes?"

······· "No such thing as a dumb question" unless it's on the internet

Technologically challenged individual, Please have pity.

Post Edited (mosquito56) : 1/20/2008 5:46:42 AM GMT

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-01-17 21:03
    If you don't mind tying up a pin, you can do it. Program ctra to output in DUTY mode with a frqa value of 1. The pin will pulse once every time the counter rolls over. Use that pin as the input pin to ctrb, programmed to count on a high input. Now you've got 64 bits of count you can use for your elapsed time (more than 7000 years' worth at 80MHz).

    -Phil

    Addendum: BTW, the correct way to read the counters is to read the most-significant counter (MSC) first, then the least signficant counter (LSC), then the MSC again. If the two readings of the MSC are different, repeat the process. This will catch any rollovers from the LSC during the reading process.

    Post Edited (Phil Pilgrim (PhiPi)) : 1/17/2008 9:25:05 PM GMT
  • mosquito56mosquito56 Posts: 387
    edited 2008-01-17 21:38
    ·Ahh, i was setting it up for pos detector and trying to use phsa since it clocks every tick. What I don't get is is it ticking every clock of the chip ·or only on that one cog?
    · Also, how do i catch that one pulse?


    Addendum: BTW, the correct way to read the counters is to read the most-significant counter (MSC) first, then the least signficant counter (LSC), then the MSC again. If the two readings of the MSC are different, repeat the process. This will catch any rollovers from the LSC during the reading process.

    Sorry, this is greek to me.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Hmm, "What do you mean, it doesn't have any tubes?"

    ······· "No such thing as a dumb question" unless it's on the internet
    ········"What happens in Vegas ends up on the Internet"

    Technologically challenged individual, Please have pity.
  • hippyhippy Posts: 1,981
    edited 2008-01-17 22:20
    @ mosquito56, decoding the greek ...

    Take a digital watch, put your hand over the hours so you can only see the minutes; "59". Close your eyes, move your hand to uncover the hours and hide the minutes; "10".

    Is the time now really "10:59" or in the intervening period when you had your eyes shut and moved you hand did the time roll over from "9:59" to "10:00" ?

    You get the same problems if you read the hour first "10" and then read the minutes "00", is it now "10:00" or "11:00" ?

    The hour is the most-significant counter, the minutes is the least-significant counter in this case. Hence, read the hour, read the minutes, read the hour again, repeat if the hour has changed. That solves the roll-over problem.
  • mosquito56mosquito56 Posts: 387
    edited 2008-01-17 22:37
    Excellent analogy. thanx

    the light bulb went on, I don't have to code the ctrb, it does it automatically in pos detect mode.

    thanx guys




    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Hmm, "What do you mean, it doesn't have any tubes?"

    ······· "No such thing as a dumb question" unless it's on the internet
    ········"What happens in Vegas ends up on the Internet"

    Technologically challenged individual, Please have pity.
  • mosquito56mosquito56 Posts: 387
    edited 2008-01-17 23:20
    phil, is this what you had in mind?

    ctra[noparse][[/noparse]30..26] := %00110 ' Set mode to "counter mode"
    ctra[noparse][[/noparse]5..0] := 0 ' Set APIN to unused pin (P0)
    frqa := 1
    dira[noparse][[/noparse]0]:=0 'set pin 0 to input
    ctrb[noparse][[/noparse]30..26]:=%01000 'set ctrb to pos detect
    ctrb[noparse][[/noparse]5..0]:=0 ' set ctrb to detect pos on pin 0

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Hmm, "What do you mean, it doesn't have any tubes?"

    ······· "No such thing as a dumb question" unless it's on the internet
    ········"What happens in Vegas ends up on the Internet"

    Technologically challenged individual, Please have pity.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-01-17 23:27
    Yeah, that's pretty much it. You have to set dira[noparse][[/noparse]0] to 1 (output), though, so the output from ctra will appear there, and ctrb will see it. Also, be sure to set frqb to 1; otherwise phsb won't increment.

    -Phil
  • deSilvadeSilva Posts: 2,967
    edited 2008-01-18 00:18
    And remember: This excellent idea had been devised by Ariba smile.gif
  • mosquito56mosquito56 Posts: 387
    edited 2008-01-18 00:21
    Phil,

    ctra[noparse][[/noparse]30..26] := %00110·· ' Set mode to "counter mode"
    ctra[noparse][[/noparse]5..0] := 0·············· ·' Set APIN to unused pin (P0)
    frqa := 1
    ctrb[noparse][[/noparse]30..26]:=%01000····· 'set ctrb to pos detect
    ctrb[noparse][[/noparse]5..0]:=0
    frqb:=1
    dira[noparse][[/noparse]0]:=1······················· 'set to output and low
    outa[noparse][[/noparse]0]:=0·

    temp2:=ctrb[noparse][[/noparse]31..0]
    ·term.bin(ctrb,32)
    ·term.dec(ctrb)
    term.dec(temp2)
    term.bin(ctrb,32)
    ·term.out($0D)
    everything prints 0's ctrb is not incrementing or i am not reading it correctly?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Hmm, "What do you mean, it doesn't have any tubes?"

    ······· "No such thing as a dumb question" unless it's on the internet
    ········"What happens in Vegas ends up on the Internet"

    Technologically challenged individual, Please have pity.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-01-18 00:36
    The count values are in phsa and phsb, not in the counter control registers.

    -Phil

    deSilva: I wasn't aware (or didn't remember) that this had been brought up before. Can you post a link to Ariba's post? It's always helpful to link as much related info together as possible. Thx.
  • mosquito56mosquito56 Posts: 387
    edited 2008-01-18 00:54
    ·I am sure everything has been brought up before. Try finding it. even with the parallax search it can be hard to find.

    I print phsa and it's always around 68_000, phsb is always 0. I put in a delay and it is still the same. I just have everything in

    pub start and read the values in my dataloop, still only 0's. A well what can I say. Thanx much for the help.

    ctra[noparse][[/noparse]30..26] := %00110 ' Set mode to "counter mode"
    ctra[noparse][[/noparse]5..0] := 0······· ' Set APIN to unused pin (P0)
    frqa := 1
    ctrb[noparse][[/noparse]30..26]:=%01000··· 'set ctrb to pos detect
    ctrb[noparse][[/noparse]5..0]:=0
    frqb:=1
    dira[noparse][[/noparse]0]:=1
    outa[noparse][[/noparse]0]:=0·············· 'set to ouput and set low


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Hmm, "What do you mean, it doesn't have any tubes?"

    ······· "No such thing as a dumb question" unless it's on the internet
    ········"What happens in Vegas ends up on the Internet"

    Technologically challenged individual, Please have pity.
  • deSilvadeSilva Posts: 2,967
    edited 2008-01-18 01:04
    Phil Pilgrim (PhiPi) said...
    deSilva: I wasn't aware (or didn't remember) that this had been brought up before. Can you post a link to Ariba's post?
    It's the second posting in this thread: http://forums.parallax.com/showthread.php?p=668956, posted 8/20/2007 5:43 PM (GMT -8)

    In fact there could be older references, but this solution looked so "typically Ariba" to me, I was sure it was his idea... smile.gif
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-01-18 01:15
    mosquito56,

    Where are you putting your delay? The counters start counting from zero after they've been configured. Unless you're inserting your delay after this configuration, you will get the same reading every time; and the number you report seems about right.

    -Phil
  • mosquito56mosquito56 Posts: 387
    edited 2008-01-18 01:39
    I am not using any delay. I was trying to get phsa to change but I reliaze that won't work.
    I setup the pins in start

    I read the values in a repeat loop further down the same cog.
    repeat
    term.dec(phsb) that's it
    term.dec(phsa) prints about 68_000 everytime.

    I'm lost. This thing should be working .

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Hmm, "What do you mean, it doesn't have any tubes?"

    ······· "No such thing as a dumb question" unless it's on the internet
    ········"What happens in Vegas ends up on the Internet"

    Technologically challenged individual, Please have pity.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-01-18 03:36
    mosquito56 said...
    I put in a delay and it is still the same.
    Phil Pilgrim (PhiPi) said...
    Where are you putting your delay?
    mosquito56 said...
    I am not using any delay.
    You'll excuse me if I seem perplexed?

    Can you list your entire program, please, from beginning to end? And put it in between [noparse][[/noparse]code] [noparse][[/noparse]/code] tags, if you would.

    Thanks,
    -Phil
  • mosquito56mosquito56 Posts: 387
    edited 2008-01-18 06:05
    code

    PUB Start· |st, x,temp2
    st:=" "
    angle:=0
    delaygen:=1
    term.Start(31, 30)
    ctra[noparse][[/noparse]30..26] := %00110 ' Set mode to "counter mode"
    ctra[noparse][[/noparse]5..0] := 0······· ' Set APIN to unused pin (P0)
    frqa := 1
    ctrb[noparse][[/noparse]30..26]:=%01000··· 'set ctrb to pos detect
    ctrb[noparse][[/noparse]5..0]:=0
    frqb:=1
    dira[noparse][[/noparse]0]:=1
    outa[noparse][[/noparse]0]:=0···········

    Pub· temps |tempss

    repeat

    ·term.str(string("TI1"))
    ·term.dec(phsb)
    ·term.out($0D)
    ·term.bin(phsb,32) 'I HAD a pause here to try to change phsa but it didn't
    ·term.dec(phsa)
    ·waitcnt(clkfreq/10+cnt)

    /code

    ·Don't know what code /code means sorry


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Hmm, "What do you mean, it doesn't have any tubes?"

    ······· "No such thing as a dumb question" unless it's on the internet
    ········"What happens in Vegas ends up on the Internet"

    Technologically challenged individual, Please have pity.
  • James LongJames Long Posts: 1,181
    edited 2008-01-18 06:18
    Mosquito,

    ·If you paste code in the forum it has a bad habit of re-spacing it. I think the code tags are to prevent the forum software (running here) from re-spacing the code. Spacing is very important in Spin. It is considered syntax in Spin unlike some other languages. The spaces are operationally important.

    I've never heard of the [noparse][[/noparse]code] [noparse][[/noparse]/code] tags, I've aways used the quote tags myself.

    But someone smarter than I, can clarify better.

    James L


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    James L

    Partner/Designer
    Lil Brother LLC (SMT Assembly Services)

    Post Edited (James Long) : 1/18/2008 6:26:46 AM GMT
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-01-18 06:43
    Mosquito56,

    Please post all of your program, including the CON, OBJ, and VAR sections and the code that calls Start and temps. Put it between [noparse][[/noparse]code] and [noparse][[/noparse]/code] tags, as I indicated before. (You have to include the square brackets, just as I've shown here.) This will maintain your indentations. To make life easier, you can also copy and paste your code into my formatter here to reformat it for posting to the forum. As a further alternative, you could archive your entire program and attach it as a zip.

    -Phil

    Post Edited (Phil Pilgrim (PhiPi)) : 1/18/2008 6:55:28 AM GMT
  • mosquito56mosquito56 Posts: 387
    edited 2008-01-18 08:15
    · ·I don't know what's going on but it's working now. I took just the code you recommended and put it in a seperate file and it works fine. phsb starts at 561 for some reason. So the problem has to be in my program. I am going to load it in another cog as my cog 0 is starting to fill up.

    ·Thanx for all your help.



    [noparse][[/noparse]code]
    · [noparse][[/noparse]b]_xinfreq[noparse][[/noparse]/b]····· = 5_000_000
    [noparse][[/noparse]b]PUB[noparse][[/noparse]/b] Start·
    term.Start(31, 30)
    [noparse][[/noparse]b]waitcnt[noparse][[/noparse]/b](clkfreq *2 + [noparse][[/noparse]b]cnt[noparse][[/noparse]/b])
    [noparse][[/noparse]b]ctra[noparse][[/noparse]/b][30..26] := %00110 ' Set mode to "counter mode"
    [noparse][[/noparse]b]ctra[noparse][[/noparse]/b][5..0] := 0······· ' Set APIN to unused pin (P0)
    [noparse][[/noparse]b]frqa[noparse][[/noparse]/b] := 10
    [noparse][[/noparse]b]ctrb[noparse][[/noparse]/b][30..26]:=%01000··· 'set ctrb to pos detect
    [noparse][[/noparse]b]ctrb[noparse][[/noparse]/b][5..0]:=0
    [noparse][[/noparse]b]frqb[noparse][[/noparse]/b]:=1
    [noparse][[/noparse]b]dira[noparse][[/noparse]/b][0]:=1
    [noparse][[/noparse]b]outa[noparse][[/noparse]/b][0]:=0·············· 'set to ouput and set low
    temps
    [noparse][[/noparse]b]Pub[noparse][[/noparse]/b]· temps
    [noparse][[/noparse]b]repeat[noparse][[/noparse]/b]
    · term.[noparse][[/noparse]b]str[noparse][[/noparse]/b]([noparse][[/noparse]b]string[noparse][[/noparse]/b]("[noparse][[/noparse]b]Phsb[noparse][[/noparse]/b] decimal..."))·········
    · term.dec([noparse][[/noparse]b]phsb[noparse][[/noparse]/b])
    · term.out($0D)
    · term.[noparse][[/noparse]b]str[noparse][[/noparse]/b]([noparse][[/noparse]b]string[noparse][[/noparse]/b]("[noparse][[/noparse]b]Phsb[noparse][[/noparse]/b] binary..."))·········
    · term.bin([noparse][[/noparse]b]phsb[noparse][[/noparse]/b],32)
    · term.out($0D)
    · term.[noparse][[/noparse]b]str[noparse][[/noparse]/b]([noparse][[/noparse]b]string[noparse][[/noparse]/b]("[noparse][[/noparse]b]Phsa[noparse][[/noparse]/b] decimal..."))·········
    · term.dec([noparse][[/noparse]b]phsa[noparse][[/noparse]/b])
    term.out($0D)
    [noparse][[/noparse]b]waitcnt[noparse][[/noparse]/b](clkfreq/10+[noparse][[/noparse]b]cnt[noparse][[/noparse]/b])
    ·
    [noparse][[/noparse]b]PUB[noparse][[/noparse]/b] dec(value, scaleBy) | i

    '' Print a decimal number

    · [noparse][[/noparse]b]if[noparse][[/noparse]/b] value < 0
    ··· -value
    ··· term.out("-")

    · i := 1_000_000_000

    · [noparse][[/noparse]b]repeat[noparse][[/noparse]/b] 10
    ··· [noparse][[/noparse]b]if[noparse][[/noparse]/b] i == scaleBy / 10
    ····· term.out(".")
    ····· [noparse][[/noparse]b]result[noparse][[/noparse]/b]~~
    ··· [noparse][[/noparse]b]if[noparse][[/noparse]/b] value => i
    ····· term.out(value / i + "0")
    ····· value //= i
    ····· [noparse][[/noparse]b]result[noparse][[/noparse]/b]~~
    ··· [noparse][[/noparse]b]elseif[noparse][[/noparse]/b] [noparse][[/noparse]b]result[noparse][[/noparse]/b] [noparse][[/noparse]b]or[noparse][[/noparse]/b] i == 1
    ····· term.out("0")
    ··· i /= 10

    [noparse][[/noparse]/code]

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Hmm, "What do you mean, it doesn't have any tubes?"

    ······· "No such thing as a dumb question" unless it's on the internet
    ········"What happens in Vegas ends up on the Internet"

    Technologically challenged individual, Please have pity.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-01-18 08:27
    Mosquito56,

    I'm really perplexed that the forum software didn't handle your tags properly. I've never seen that happen before. So I'm going to copy and paste the program from your post here:

      [b]_xinfreq[/b]      = 5_000_000
    [b]PUB[/b] Start  
    term.Start(31, 30)
    [b]waitcnt[/b](clkfreq *2 + [b]cnt[/b])
    [b]ctra[/b][noparse][[/noparse]30..26&#093; := %00110 ' Set mode to "counter mode"
    [b]ctra[/b][noparse][[/noparse]5..0&#093; := 0        ' Set APIN to unused pin (P0)
    [b]frqa[/b] := 10
    [b]ctrb[/b][noparse][[/noparse]30..26&#093;:=%01000    'set ctrb to pos detect
    [b]ctrb[/b][noparse][[/noparse]5..0&#093;:=0
    [b]frqb[/b]:=1
    [b]dira[/b][noparse][[/noparse]0&#093;:=1
    [b]outa[/b][noparse][[/noparse]0&#093;:=0               'set to ouput and set low
    temps
    [b]Pub[/b]  temps
    [b]repeat[/b]
      term.[b]str[/b]([b]string[/b]("[b]Phsb[/b] decimal..."))          
      term.dec([b]phsb[/b])
      term.out($0D)
      term.[b]str[/b]([b]string[/b]("[b]Phsb[/b] binary..."))          
      term.bin([b]phsb[/b],32)
      term.out($0D)
      term.[b]str[/b]([b]string[/b]("[b]Phsa[/b] decimal..."))          
      term.dec([b]phsa[/b])
    term.out($0D)
    [b]waitcnt[/b](clkfreq/10+[b]cnt[/b])
      
    [b]PUB[/b] dec(value, scaleBy) | i
    
    '' Print a decimal number
    
      [b]if[/b] value < 0
        -value
        term.out("-")
    
      i := 1_000_000_000
    
      [b]repeat[/b] 10
        [b]if[/b] i == scaleBy / 10
          term.out(".")
          [b]result[/b]~~
        [b]if[/b] value => i
          term.out(value / i + "0")
          value //= i
          [b]result[/b]~~
        [b]elseif[/b] [b]result[/b] [b]or[/b] i == 1
          term.out("0")
        i /= 10
    
    
    


    Ah, much better. Now I can see what's going on. More to come...

    -Phil
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-01-18 08:42
    I tested your code (with some slight modifications for readability and to use TV output instead of RS232), and it works. I didn't see any evidence of phsb starting at a high value. (It started at zero.) Here's my modified code:

    [b]CON[/b]
    
      [b]_xinfreq[/b]      = 5_000_000
      [b]_clkmode[/b]      = [b]xtal[/b]1 + [b]pll[/b]16x
    
    [b]OBJ[/b]
    
      term : "TV_Wtext"
    
    [b]PUB[/b] Start
    
      term.Start(12)
      'term.Start(31, 30)
      [b]waitcnt[/b](clkfreq *2 + [b]cnt[/b])
      [b]ctra[/b][noparse][[/noparse]30..26&#093; := %00110 ' Set mode to "counter mode"
      [b]ctra[/b][noparse][[/noparse]5..0&#093; := 0        ' Set APIN to unused pin (P0)
      [b]frqa[/b] := 10
      [b]ctrb[/b][noparse][[/noparse]30..26&#093;:=%01000    'set ctrb to pos detect
      [b]ctrb[/b][noparse][[/noparse]5..0&#093;:=0
      [b]frqb[/b]:=1
      [b]dira[/b][noparse][[/noparse]0&#093;:=1
      [b]outa[/b][noparse][[/noparse]0&#093;:=0               'set to ouput and set low
      temps
      
    [b]Pub[/b]  temps
    
      [b]repeat[/b]
        term.[b]str[/b]([b]string[/b]("[b]Phsb[/b] decimal..."))          
        term.dec([b]phsb[/b])
        term.out($0D)
        'term.str(string("Phsb binary..."))          
        'term.bin(phsb,32)
        'term.out($0D)
        term.[b]str[/b]([b]string[/b]("[b]Phsa[/b] decimal..."))          
        term.dec([b]phsa[/b])
        term.out($0D)
        [b]waitcnt[/b](clkfreq/2 + [b]cnt[/b])
        
    [b]PUB[/b] dec(value, scaleBy) | i
    
    '' Print a decimal number
    
      [b]if[/b] value < 0
        -value
        term.out("-")
    
      i := 1_000_000_000
    
      [b]repeat[/b] 10
        [b]if[/b] i == scaleBy / 10
          term.out(".")
          [b]result[/b]~~
        [b]if[/b] value => i
          term.out(value / i + "0")
          value //= i
          [b]result[/b]~~
        [b]elseif[/b] [b]result[/b] [b]or[/b] i == 1
          term.out("0")
        i /= 10
    
    
    



    -Phil
  • mosquito56mosquito56 Posts: 387
    edited 2008-01-18 09:17
    ·Sorry, they weren't tags. I used the button you gave me then cut and pasted. I must have done something wrong.

    I will work on it tommorow.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Hmm, "What do you mean, it doesn't have any tubes?"

    ······· "No such thing as a dumb question" unless it's on the internet
    ········"What happens in Vegas ends up on the Internet"

    Technologically challenged individual, Please have pity.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-01-18 09:33
    mosquito56 said...
    I used the button you gave me then cut and pasted.
    That's all I do; it should've worked. Are you using Internet Explorer, by any chance? If so, and if you can switch out of the WSYWIG editor to edit plain text, it might help.

    Anyway, I've done some code modification that will permit you to ignore the reading in phsa and just read phsb, which will be in tenths of a second (with 99.975% accuracy ± crystal drift). ctra outputs pulses at 10Hz now, and ctrb counts them.

    Here are the relevant code snippets:

    [b]PUB[/b] Start
    
      term.Start(31, 30)
      [b]waitcnt[/b](clkfreq *2 + [b]cnt[/b])
      [b]ctra[/b][noparse][[/noparse]30..26&#093; := %00110 ' Set mode to "counter mode"
      [b]ctra[/b][noparse][[/noparse]5..0&#093; := 0        ' Set APIN to unused pin (P0)
      [b]frqa[/b] := 537
      [b]ctrb[/b][noparse][[/noparse]30..26&#093;:=%01000    'set ctrb to pos detect
      [b]ctrb[/b][noparse][[/noparse]5..0&#093;:=0
      [b]frqb[/b]:=1
      [b]dira[/b][noparse][[/noparse]0&#093;:=1
      [b]outa[/b][noparse][[/noparse]0&#093;:=0               'set to ouput and set low
      temps
      
    [b]Pub[/b]  temps
    
      [b]repeat[/b]
        term.out(0)
        term.[b]str[/b]([b]string[/b]("[b]Phsb[/b] (seconds)..."))          
        term.dec([b]phsb[/b] / 10)
        term.out($0D)
        [b]waitcnt[/b](clkfreq/10 + [b]cnt[/b])
        
    
    


    -Phil

    Post Edited (Phil Pilgrim (PhiPi)) : 1/18/2008 9:38:06 AM GMT
  • deSilvadeSilva Posts: 2,967
    edited 2008-01-18 09:42
    To not confuse other readers:
    OUTA[noparse][[/noparse]0]:= 0
    should be omitted from the code as redundant, and the comment
    'Set mode to "counter" mode
    is misleading (shoud read "Duty" mode), which isn't thus descriptive either, but would allow a better reference to the data sheet
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-01-18 09:50
    I noticed the outa[noparse][[/noparse]0] := 0, too, but decided to leave it alone, invoking the priciple of least interference with something that works in someone else's code. Nonetheless, since outa is ORed with the counter output, and since it's possible that it could've been set high earlier for another purpose, maybe it's not such a bad idea for a subroutine to return things to a known state. By the same logic, of course, phsa and phsb should also be zeroed.

    -Phil
  • mosquito56mosquito56 Posts: 387
    edited 2008-01-18 22:07
    outa[noparse][[/noparse]0]:=0
    I wasn't sure if the boot program took care of all that. I wanted to make sure that it was low in case it was floating.
    I was switching things back and forth, trying to figure it out so the comments weren't matching the codes. I.E.
    says "counter" when acutally was duty or vice versa.

    I put our code in a different cog. It prints fine with proterminal.

    I call the subroutine from main and it returns weird stuff, "2716" now. prints about 4 times and locks up.

    Call
    ·timer:=(phabget.starttimer)
    ·term.dec(timer)

    Pub· starttimer [noparse]:p[/noparse]hsbrett
    ·· phsbrett:=phsb
    {repeat
    · ·term.dec(phsb)
    ·· term.out($0D)· "this works fine by itself
    ·· term.dec(phsa)


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Hmm, "What do you mean, it doesn't have any tubes?"

    ······· "No such thing as a dumb question" unless it's on the internet
    ········"What happens in Vegas ends up on the Internet"

    Technologically challenged individual, Please have pity.
  • deSilvadeSilva Posts: 2,967
    edited 2008-01-19 01:28
    Phil: Accepted! Indeed there is some fineprint to it rarely noticed: I has to be ZERO!
    All I/O settings within a COG are ORed, so a ONE set by accident in OUTA would nullify all timer output ....
  • mosquito56mosquito56 Posts: 387
    edited 2008-01-19 18:32
    still can't get it to work. I see another post with the same problem.

    I read in one post that defining var with same name in both cogs can share a variable. I 've tried res but it won't take it in the lower cog when I use the same name. I tried referencing it from second cog with @timer1 but that doesn't work. Totally lost here. Thanx

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ······· "What do you mean, it doesn't have any tubes?"

    ······· "No such thing as a dumb question" unless it's on the internet

    Technologically challenged individual, Please have pity.
Sign In or Register to comment.