PDA

View Full Version : How many hours has my Prop been running?



mosquito56
01-18-2008, 04:38 AM
·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

Phil Pilgrim (PhiPi)
01-18-2008, 05:03 AM
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

mosquito56
01-18-2008, 05:38 AM
·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.

hippy
01-18-2008, 06:20 AM
@ 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.

mosquito56
01-18-2008, 06:37 AM
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.

mosquito56
01-18-2008, 07:20 AM
phil, is this what you had in mind?

ctra[30..26] := %00110 ' Set mode to "counter mode"
ctra[5..0] := 0 ' Set APIN to unused pin (P0)
frqa := 1
dira[0]:=0 'set pin 0 to input
ctrb[30..26]:=%01000 'set ctrb to pos detect
ctrb[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)
01-18-2008, 07:27 AM
Yeah, that's pretty much it. You have to set dira[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

deSilva
01-18-2008, 08:18 AM
And remember: This excellent idea had been devised by Ariba http://forums.parallax.com/images/smilies/smile.gif

mosquito56
01-18-2008, 08:21 AM
Phil,

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

temp2:=ctrb[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)
01-18-2008, 08:36 AM
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.

mosquito56
01-18-2008, 08:54 AM
·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[30..26] := %00110 ' Set mode to "counter mode"
ctra[5..0] := 0······· ' Set APIN to unused pin (P0)
frqa := 1
ctrb[30..26]:=%01000··· 'set ctrb to pos detect
ctrb[5..0]:=0
frqb:=1
dira[0]:=1
outa[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.

deSilva
01-18-2008, 09:04 AM
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... http://forums.parallax.com/images/smilies/smile.gif

Phil Pilgrim (PhiPi)
01-18-2008, 09:15 AM
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

mosquito56
01-18-2008, 09:39 AM
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)
01-18-2008, 11:36 AM
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
tags, if you would.

Thanks,
-Phil

mosquito56
01-18-2008, 02:05 PM
code

PUB Start· |st, x,temp2
st:=" "
angle:=0
delaygen:=1
term.Start(31, 30)
ctra[30..26] := %00110 ' Set mode to "counter mode"
ctra[5..0] := 0······· ' Set APIN to unused pin (P0)
frqa := 1
ctrb[30..26]:=%01000··· 'set ctrb to pos detect
ctrb[5..0]:=0
frqb:=1
dira[0]:=1
outa[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 Long
01-18-2008, 02:18 PM
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
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) (http://www.lilbro.mosquito.net.nz/index.html)

Post Edited (James Long) : 1/18/2008 6:26:46 AM GMT

Phil Pilgrim (PhiPi)
01-18-2008, 02:43 PM
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
and 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 (http://www.phipi.com/format) 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

mosquito56
01-18-2008, 04:15 PM
· ·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.





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

'' Print a decimal number

· if value < 0
··· -value
··· term.out("-")

· i := 1_000_000_000

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



▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
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)
01-18-2008, 04:27 PM
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:




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

PUB dec(value, scaleBy) | i

'' Print a decimal number

if value < 0
-value
term.out("-")

i := 1_000_000_000

repeat 10
if i == scaleBy / 10
term.out(".")
result~~
if value => i
term.out(value / i + "0")
value //= i
result~~
elseif result or 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)
01-18-2008, 04:42 PM
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:




CON

_xinfreq = 5_000_000
_clkmode = xtal1 + pll16x

OBJ

term : "TV_Wtext"

PUB Start

term.Start(12)
'term.Start(31, 30)
waitcnt(clkfreq *2 + cnt)
ctra[30..26&#093; := %00110 ' Set mode to "counter mode"
ctra[5..0&#093; := 0 ' Set APIN to unused pin (P0)
frqa := 10
ctrb[30..26&#093;:=%01000 'set ctrb to pos detect
ctrb[5..0&#093;:=0
frqb:=1
dira[0&#093;:=1
outa[0&#093;:=0 'set to ouput and set low
temps

Pub temps

repeat
term.str(string("Phsb decimal..."))
term.dec(phsb)
term.out($0D)
'term.str(string("Phsb binary..."))
'term.bin(phsb,32)
'term.out($0D)
term.str(string("Phsa decimal..."))
term.dec(phsa)
term.out($0D)
waitcnt(clkfreq/2 + cnt)

PUB dec(value, scaleBy) | i

'' Print a decimal number

if value < 0
-value
term.out("-")

i := 1_000_000_000

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





-Phil

mosquito56
01-18-2008, 05:17 PM
·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)
01-18-2008, 05:33 PM
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:




PUB Start

term.Start(31, 30)
waitcnt(clkfreq *2 + cnt)
ctra[30..26&#093; := %00110 ' Set mode to "counter mode"
ctra[5..0&#093; := 0 ' Set APIN to unused pin (P0)
frqa := 537
ctrb[30..26&#093;:=%01000 'set ctrb to pos detect
ctrb[5..0&#093;:=0
frqb:=1
dira[0&#093;:=1
outa[0&#093;:=0 'set to ouput and set low
temps

Pub temps

repeat
term.out(0)
term.str(string("Phsb (seconds)..."))
term.dec(phsb / 10)
term.out($0D)
waitcnt(clkfreq/10 + cnt)




-Phil

Post Edited (Phil Pilgrim (PhiPi)) : 1/18/2008 9:38:06 AM GMT

deSilva
01-18-2008, 05:42 PM
To not confuse other readers:
OUTA[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)
01-18-2008, 05:50 PM
I noticed the outa[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

mosquito56
01-19-2008, 06:07 AM
outa[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 :phsbrett
·· 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.

deSilva
01-19-2008, 09:28 AM
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 ....

mosquito56
01-20-2008, 02:32 AM
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.