PDA

View Full Version : 7 segment digital counter 28312



WRD5
03-21-2010, 02:10 AM
My son and Iиare working on a project to trigger a servo motor, and want it to fire at 59.99 seconds.и

We are using aиseven segment counter, and are controlling it with a BS2pe motherboard.и We have started with the odomoter sample project as our code, and can get the counter to mimic a stopwatch fairly accurately, but need to add a decimal point between the second and third digit.и What command orиcode accomplishes this?и Basically, we want it to act as a stop watch, with 100th of a second readout (two decimal points).

Hoping for some help with this and then will need some help with the code for driving the servo within this 60 second window.
Thanks for any and all help!
B & N

Phil Pilgrim (PhiPi)
03-21-2010, 03:11 AM
WRD5,

Suppose your time in hundredths of a second is in a variable called Timer. Using the following code, you can print it out with the decimal:




OWOUT Owio, 0, ["z", 1, DEC2 Timer / 100, ".", DEC2 Timer // 100]




The "z", 1 provides one digit of leading zero suppression for the following decimal number, which is Timer / 100, printed as two decimal digits. Then comes the decimal point, followed by Timer // 100 (the remainder from Timer / 100), printed without leading zero suppression, since it's to the right of the decimal point.

-Phil

WRD5
03-21-2010, 04:12 AM
This added the decimal in the middle of the 4 numeric spots, but after counting to 0.99, it did not roll over to a "1" in the first spot to the left of the decimal...and the decimal disappeared, as the counter went back to counting, starting again at 1....and continues onward without any decimal...

I am not sure what is the "correct" definition to use for defining timer at the start of my program...We called it a nib and var with no difference.

Thanks for this start to show a decimal.
b

Post Edited (WRD5) : 3/20/2010 8:20:16 PM GMT

Phil Pilgrim (PhiPi)
03-21-2010, 04:32 AM
Can you post your entire program, please?

-Phil

WRD5
03-21-2010, 05:43 AM
' ================================================== =======================
'
' File...... odometer.bpe
' Purpose... modified counter and scrolling with the 7Seg-DB.
' Author.... N & B
' E-mail.... ' Started... 3/12/07
' Updated... 3/20/10
'
' {$STAMP BS2pe}
' {$PBASIC 2.5}
'
' ================================================== =======================


' -----[ Program Description ]---------------------------------------------

'Program to demonstrate scrolling on the 7Seg-DB.
'It operates like the odometer in a car,
'scrolling up the digits that change.
'This program requires a single 7Seg-DB master.

' -----[ I/O Definitions ]-------------------------------------------------

Owio CON 6

' -----[ Variables ]-------------------------------------------------------

cnt VAR Wordиииииииииииииииииииииииииииииииииииииии 'The counter: 0000-9999.
val VAR Wordииииииииииииииииииииииииииииииииииииииии'Chang ed part of cnt.
win VAR Nibииииииииииииииииииииииииииииииииииииииииии 'Left side of changed window.
i VAR Nibиииииииииииииииииииииииииииииииииииииииииииииии 'Scroll counter.
Timer VAR Wordиииииииииииииииииииииииииииииииииии 'adds timer for Phil Pilgrim code

' -----[ Initialization ]--------------------------------------------------

PAUSE 10иииииииииииииииииииииииииииииииииииииииииииии 'Wait for AVR to come out of reset.

' -----[ Program Code ]----------------------------------------------------

cnt = 9940иииииииииииииииииииииииииииииииииииииииииииии' start at 0.0 like a stopwatch.

OWOUT Owio, 0, ["z", 1, DEC2 Timer / 100, ".", DEC2 Timer // 100] 'code from Phil Pilgrim for decimal.
ииииииииииииииииииииииииииииииииииииииииииииииииии иииииииииии ' The "z", 1 provides one digit of leading zero suppression for the following decimal
ииииииииииииииииииииииииииииииииииииииииииииииииии иииииииииии 'number, which is Timer / 100, printed as two decimal digits.
ииииииииииииииииииииииииииииииииииииииииииииииииии иииииииииии 'THEN comes the decimal point, followed by Timer // 100 (the remainder from Timer / 100),
ииииииииииииииииииииииииииииииииииииииииииииииииии иииииииииии 'printed without leading zero suppression, since it's to the right of the decimal point.
DOииииииииииииииииииииииииииииииииииииииииииииииии ииииииии 'Countsиto 60.
PAUSE 71ииииииииииииииииииииииииииииииииииииииииииииии 'best count to get tenth of secs correct by stopwatch est on march 20th.
cnt = cnt + 1 // 10000ииииииииииииииииииииииииииии'Increment count modulo 10000.
val = 1000ииииииииииииииииииииииииииииииииииииииииииии 'We'll see if it's a multiple of 1000 first.
win = 0иииииииииииииииииииииииииииииииииииииииииииииииии 'Set the window to the left edge of display.
DO WHILE valииииииииииииииииииииииииииииииииииииииии'Val decreases, so loop terminates.
IF cnt // val = 0 THENииииииииииииииииииииииииииии'Is cnt a multiple of val?
val = cnt // (val * 10)ииииииииииииииииииииииииииии ' Yes: Set val to the digits of cnt that changed.
EXIT ' Exit LOOP.
ENDIF
val = val / 10ииииииииииииииииииииииииииииииииииииииии ' No: Try a smaller value for val
win = win + 1иииииииииииииииииииииииииииииииииииииии ' Move the left window border to the right.
LOOPииииииииииииииииииииииииииииииииииииииииииииии ииииии ' Try again.
OWOUT Owio, 0, ["w", win, 3]иииииииииииииии 'Define the new window.
FOR i = 1 TO 3ииииииииииииииииииииииииииииииииииииии 'Scroll current contents of window up by three (off the screen).
OWOUT Owio, 0, ["u"]иииииииииииииииииииииииииии ' Scroll up one.
PAUSE 1ииииииииииииииииииииииииииииииииииииииииииииииии ' Wait, for animation effect.
NEXT
IF val THENиииииииииииииииииииииииииииииииииииииииииии 'Is val equal to 0?
OWOUT Owio, 0, [DEC val]иииииииииииииииииииии' No: Display it in the window (still scrolled off).
ELSE
OWOUT Owio, 0, [DEC4 val]ииииииииииииииииии ' Yes: Display "0000" in the full window (still scrolled off).
ENDIF
FOR i = 1 TO 3иииииииииииииииииииииииииииииииииииииии 'Scroll new value onto window. (It takes three scrolls.)
OWOUT Owio, 0, ["u"]ииииииииииииииииииииииииииии ' Scroll up one.
PAUSE 1иииииииииииииииииииииииииииииииииииииииииииииииии ' Wait, for animation effect.
NEXT
LOOPииииииииииииииииииииииииииииииииииииииииииииии ииииииии 'And so ON...

Post Edited (WRD5) : 3/21/2010 4:15:55 AM GMT

Phil Pilgrim (PhiPi)
03-21-2010, 06:01 AM
WRD5,

If you put your code between
and tags, it will preserve indentation and use a monospaced font, making it easier to read. (You can modify your post by clicking the pencil icon in the upper righthand corner.)

-Phil

WRD5
03-21-2010, 12:16 PM
i went back and spaced the code and comments manually, line by line, but do not understand the comments about
and nomenclature?

Thanks,

b

Phil Pilgrim (PhiPi)
03-21-2010, 02:11 PM
WRD5,

Read the forum guidelines here: forums.parallax.com/forums/mCode.aspx#1.12 (http://forums.parallax.com/forums/mCode.aspx#1.12). It explains what the code tags are for and how to use them.

I think you misunderstood my use of the Timer variable. And I misunderstood that you still wanted to do the odometer roll. What I meant by using Timer is that it should replace (or take the name of) your own time variable, which appears to be cnt. If you still want to use the odometer roll, you will have to send a "." after the ones digit whenever that digit changes. But for numbers that change every hundredth of a second, I'm not sure you'll even be able to see the transition taking place.

My recommendation would be to skip the odometer roll for now and just concentrate on displaying numbers using the format I showed you, until you have a working familiarity with PBASIC and the commands used to write to the display. Trying to modify example code that you don't fully understand will be an exercise in frustration. Later on, you can embellish things if you like. But you'll have more success and garner more enjoyment for yourself and your son if you start simple and build up from there.

-Phil

WRD5
03-21-2010, 09:20 PM
Phil
you are absolutely RIGHT! We have NO interest in the artisitic function of the odometer rolling function, and were just using it as a starting point to understand, and try to make our 7 seg display work and do something similar to our clocking function.
And YES....much of the nomenclature is still baffling, but some of the logic is starting to sink in. N is also getting a kick out of changing the variables and seeing their result, so it hasnt all been for naught!

We appreciate your help!
b