Chronometer
nelson_dds
Posts: 2
Good morning,
I'm a new user Parallax and new in this website. I use (with my work to study parallax) a Super Carrier Board 8Bit with a BS2p, but it's very dificult for me to make a Chronometer, i have also a Parallax 2x16 Serial LCD (Backlit). I want to make a chronometer with two buttons Start/Stop and reset. The buttons are P9 and P12 and the Rx of LCD are P1. I have no idea how to do this.
PS: I live in French Swiss why my poor english
Nelson
I'm a new user Parallax and new in this website. I use (with my work to study parallax) a Super Carrier Board 8Bit with a BS2p, but it's very dificult for me to make a Chronometer, i have also a Parallax 2x16 Serial LCD (Backlit). I want to make a chronometer with two buttons Start/Stop and reset. The buttons are P9 and P12 and the Rx of LCD are P1. I have no idea how to do this.
PS: I live in French Swiss why my poor english
Nelson
Comments
But I can understand the desire to start in PBasic and an 8-bit solution.
First, you need an infinite loop that provides you with a 1 second clock tick.
Second, you need a register that will accumulate this ticks whenever you desire to start and which allows you to read whenever you desire (while counting or after a stop)
+++++++++++
Having suggested the above, 8 bits will only count to 255 seconds and then roll-over. If you desire more than 255 seconds of timing, you must chain together another register to get 16 bits, 24 bits, 32 bits and so on.
And below all that, you have to create the actual one second tick from a 20,000,000 hz clock (or more, depending on which BasicStamp). That too will require a set of registers able to accumulate far more than 8 bits.
++++++++++++
The Propeller would be much easier because you can have one Cog creating a one-second tick and running free without interferance, another Cog working as your Chronometer without interferance, and another Cog managing button i/o without interferance, and a final Cog providing output to LCD without interferance.
There lies the huge advantages of parallel processing. You avoid interuptions and get precise deterministic computing.
++++++
With the BasicStamp, you are going to have to be very careful to have all these different tasks share on CPU without affecting the underlying clock tick. In all honesty, I cannot recall if it can be done or if attaching a RTC might be required.
Someone else may mention code that has already done so with the BasicStamp.
Here is a 2007 which I have not read entirely. It may help. But it too begins by suggesting using the Propeller.
http://forums.parallax.com/showthread.php/92076-Stopwatch-Timer-Counter
And this...
http://www.slideshare.net/vrehere/implementing-a-digital-stopwatch-using-basic-stamp2
+++++++
If SPIN seems to much for you, you could do this quite easily in Forth on a Propeller. I would try Tachyon Forth to begin with.
Loopy mentioned using 4 separate cogs. You could do it easily in even one cog and still have deterministic (or precise, at least) timing, although I agree that serial for the LCD should have its own cog. Timing won't be nearly as precise on a BS2 - you can't check buttons and update an LCD while precisely keeping time. The only real timing the BS2 has is the sleep instruction, which won't take into account the fact that updating the LCD takes some unknown and not easily accountable time to be updated.
If Forth seems too much for you, you could do this quite easily in Spin on a Propeller.
But the original poster said he had a BS2 and so I wondered if one *could* write a stop watch without recourse to an external timer source. It has to be able to drive a Parallax 2x16 serial LCD and has to be, say, +- 1 per cent correct.
There are two sources of inaccuracy. The inaccuracy of the resonator that provides basic instruction timing, and the differences in the number of instructions executed in each pass through the loop. In the description of the PAUSE instruction, they say the accuracy of the resonator is +-1 percent.
Now we have to make sure that every pass through the loop takes exactly the same number of instructions. That is why the lap counter is written whether or not the button is pushed and that is why the SEROUT instructions are one character at a time.
As much as I hate magic numbers, I had to tune the delay (using a logic analyzer), and it would likely be needful to tune this for each BS2 module.
I would never consider this an anything other than an exercise, but I do think you can build a useable chono with a BS2 and no external timing source.