Counting time while doing other things
Sniper King
Posts: 221
Is there a good way to count off say 30 seconds while doing other things.· This is what I came up with but this device comes with a caveot that lives are on the line so, i want the forums opinion.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·- Ouch, thats not suppose to be hot!··
Michael King
Application Engineer
R&D
Digital Technology Group
' this is what I have come up with.... Pub Control Loop Tm:=CNT+(30*80_000_000) repeat GetGPSReady ' Wait for GPS Fix CheckTimeDisp(Tm) GetCoords ' Get GPS Coordinates CheckTimeDisp(Tm) KillGPSComms ' Stop GPS Cog KillGPSPower 'Turn off GPS CheckTimeDisp(Tm) MaxPwr(1) 'Turn on Commo SendFix 'Send GPS Position info CheckTimeDisp(Tm) KillComms ' Stop Comms Cog MaxPwr(0) 'Turn off Commo Sleep(2) Pub CheckTimeDisp(x) If (Tm<Cnt) 'Turn off display pub Sleep(x) ' Sleep for x Minutes Repeat i from 1 to x Repeat j From 1 to 60 Waitcnt(80_000_000+cnt) checkTimeDisp(tm)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·- Ouch, thats not suppose to be hot!··
Michael King
Application Engineer
R&D
Digital Technology Group
Comments
Also, rather than use 80_000_000 as hard-wired operating speed, using CLKFREQ makes it far more portable; "Waitcnt(CLKFREQ+cnt)" will wait one second regardless of operating speed. Likewise "Tm:=CNT+(30*CLKFREQ)".
I am former military (Army (Nat Guard) 11B (Infantry)) I was a sniper and sniper deployment NCO for 4 years.
This device is a tracking device. It gets GPS coordinates (Thank you Paul Hubner for the clever GPS parser!) and sends them wirelessly to a LAN enabled receiver and then onto a SQL server to record all the data from the different trackers. It also navigates by way of navigation packets sent back to the device and an uOLED display to show a compass and other text data.
The boards are done. The PC based software is done. The Server is done. The Tracker software is not.
The military is telling me to hurry up. Dept. of Homeland security is saying hurry up. Blackwater is saying hurry up.
So anyway, this is a huge project for me.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·- Ouch, thats not suppose to be hot!··
Michael King
Application Engineer
R&D
Digital Technology Group
I have looked a little into tracking devices, but never got far.
Plus I am a huge fan of Blackwater, so I am very impressed.
Let us know how it goes.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The pessimist is never disappointed.
It is possible to double the dynamic range by using unsigned arithmetic but it requires a little more juggling of code. If you can access the carry flag then unsigned becomes quite effective. But, that would still only be 52 seconds.
Evan
There's no way of saying this without causing some offence but it surprises me that the "US military complex" has such a project in the hands of a company which has no proven track record or demonstration of competence in the components being used.
Don't get me wrong, I wish you every success in the project, but if I were an over-seeing project manager on what seems to be such an important project I'd be a bit concerned that those developing it were having to ask how to do the basics. For something mission critical and perhaps life-critical I'd want to see all sorts of competence proofs before having confidence in what was being developed and deployed.
Maybe it's a 'different culture' thing. When I worked for a CMM Level 3 company there was more work ( and money made ) in defining the project, agreeing and providing proof of concept and demonstrating functionality and deliverables than in actually doing any 'real work'.
While I ask alot of questions about the basics, it is regarding the spin language. I have been a programmer for over 20 years. Java, C, VB and now I am learning spin. If I could write this in my native languages I would but spin is what I have to use here. So the learning curve attached to this project included spin.
One more thing. Never in my life have I said I could do a project if I knew I couldn't. As of last night, everything works and works well. The last thing is to add the display which will arrive on monday and put the compass on it which has already been written and tested (broke the last one).
The military didn't ask us to do this. We went head to head with L3, Lucent, and Motorola. I personally felt very small when we showed up at 29 palms for a demo. We watched all of them fail except Lucent whos tracker was about 10x6x1.5 with a 21 inch antenna on it. It worked flawlessly. We watched their engineers laugh at us with our 3 components (2 trackers and a node). Except ours worked flawlessly too. Our batteries lasted 2.7x as long as lucent and all the military brass on hand got to stay inside their air conditioned offices and watch it as our software polled our server in AZ and updated the locations of our trackers. When it was over they asked me to put a display on it that would handle simple text messages. I said sure and added we can give them the ability to navigate as well. They loved it and said go.
So while we are not a giant company, the proof was in the (propeller, the size (2x6.5x1) and the battery life) pudding.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·- Ouch, thats not suppose to be hot!··
Michael King
Application Engineer
R&D
Digital Technology Group
maybe you have not seen my posting from yesterday
So i post the code right here
I think with this code-template it is easy for you to adapt it to your project
If you have any questions feel free to ask me.
I have a question too:
how do you implement new parts of code into your project ?
Do you insert it right away or do make tests in a SEPARATE small program ?
best regards
Stefan
TMR:=((2*clkfreq)+cnt)
·This gives me a 2 second window to check into.
If the cnt>TMR then I pass back a 1
This has worked flawlessly for my project so far.· Though the timing isn't super accurate,· i am well within a second and I can easily count of 30 seconds without a problem
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·- Ouch, thats not suppose to be hot!··
Michael King
Application Engineer
R&D
Digital Technology Group
I think you've been lucky that this has worked as well as it has. This is a signed comparison and
CNT runs 0..+big, -big..-1, 0..+big. There are all sorts of issues with values which are across the
transition points.
As I say, I cannot remember the exact code but it's "if (tmr-CNT) > 0" or similar; check previous
forum posts where this has been discussed in detail.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·- Ouch, thats not suppose to be hot!··
Michael King
Application Engineer
R&D
Digital Technology Group
Man this look great for my intentions. I am still trying it out but so far so good. Thanks
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·- Ouch, thats not suppose to be hot!··
Michael King
Application Engineer
R&D
Digital Technology Group
somehow this is a very general question. So for me it is hard to understand what you mean exactly.
This is easy to calculate
The systemcounter has 32 bits 2^32 = 4294967296
At a systemclock of 80 MHz the systemcounter will wrap around after
4.294.967.296 / 80.000.000 = 53,687 seconds. In milliseconds 53687
For longer timeperiods you could use a nested if-condition with a countervariable
best regards
Stefan
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheers,
Simon
www.norfolkhelicopterclub.com
You'll always have as many take-offs as landings, the trick is to be sure you can take-off again
BTW: I type as I'm thinking, so please don't take any offence at my writing style
No the correct way to present it in spin is
Page 250 of the Propeller manual
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
You are my hero today!· Your counter is perfect! A few minor changes to fit my code and I am working flawlessly.· The forum was right about my method... It was completely unreliable.· Yours counts every time right on the money!· thank you!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·- Ouch, thats not suppose to be hot!··
Michael King
Application Engineer
R&D
Check out Project: PSAV Persistent Sailing Autonomous Vehicle
I'm glad (and surprised!!) anything I've done was of help. On the Shoulders of Giants eh?
This a dumb solution - but why not use the clock from the GPS? Thats what we us in telecom, and even if you don't go for stratum-1 (ie a best level of timing accuracy) the clock is still certainly accurate at the 'about 30 seconds' resolution
Paul