Shop OBEX P1 Docs P2 Docs Learn Events
Binary Timer — Parallax Forums

Binary Timer

Chris PalmerChris Palmer Posts: 5
edited 2007-11-26 15:34 in BASIC Stamp
Hi, I am new with this stuff so my problem is probablly pretty obvious.

I am trying to make a binary timer, so far I am only trying to get to through the seconds part, then I'll move on to minutes and hours. I am using leds on on and off position to denote the 1 or 0. I have the cathodes connected to pin 14, and then the anodes are hooked up as follows:·32 is pin 13,·16 is pin 12,·8·is pin 11, 4·is pin 10,·2 is pin 9,·1 is PIn 8.

When I run the program all of the leds light up.

The codes is:

' {$STAMP BS2}
' {$PBASIC 2.5}

seconds VAR Byte
useableSeconds VAR Byte
LOW 14
PAUSE 1000

FOR seconds = 1 TO 60
· useableSeconds = seconds
· LOW 13
· LOW 12
· LOW 11
· LOW 10
· LOW 9
· LOW 8

· IF((useableSeconds - 32) >= 0) THEN
··· useableSeconds = useableSeconds - 32
··· HIGH 13
··· IF((useableSeconds- 16) >= 0) THEN
····· useableSeconds = useableSeconds - 16
····· HIGH 12
····· IF((useableSeconds- 8) >= 0) THEN
······· useableSeconds = useableSeconds - 8
······· HIGH 11
······· IF((useableSeconds- 4) >= 0) THEN
········· useableSeconds = useableSeconds - 4
········· HIGH 10
········· IF((useableSeconds- 2) >= 0) THEN
··········· useableSeconds = useableSeconds - 2
··········· HIGH 9
··········· IF((useableSeconds - 1) >=0)· THEN
··········· useableSeconds = useableSeconds - 1
··········· HIGH 8
··········· ENDIF
········· ENDIF
······· ENDIF
····· ENDIF
··· ENDIF
··· ELSEIF((useableSeconds- 16) >= 0) THEN
····· useableSeconds = useableSeconds - 16
····· HIGH 12
····· IF((useableSeconds- 8) >= 0) THEN
······· useableSeconds = useableSeconds - 8
······· HIGH 11
······· IF((useableSeconds- 4) >= 0) THEN
········· useableSeconds = useableSeconds - 4
········· HIGH 10
········· IF((useableSeconds- 2) >= 0) THEN
··········· useableSeconds = useableSeconds - 2
··········· HIGH 9
··········· IF((useableSeconds - 1) >=0)· THEN
··········· useableSeconds = useableSeconds - 1
··········· HIGH 8
··········· ENDIF
········· ENDIF
······· ENDIF
····· ENDIF
····· ELSEIF((useableSeconds- 8) >= 0) THEN
······· useableSeconds = useableSeconds - 8
······· HIGH 11
······· IF((useableSeconds- 4) >= 0) THEN
········· useableSeconds = useableSeconds - 4
········· HIGH 10
········· IF((useableSeconds- 2) >= 0) THEN
··········· useableSeconds = useableSeconds - 2
··········· HIGH 9
··········· IF((useableSeconds - 1) >=0)· THEN
··········· useableSeconds = useableSeconds - 1
··········· HIGH 8
··········· ENDIF
········· ENDIF
······· ENDIF
······· ELSEIF((useableSeconds- 4) >= 0) THEN
········· useableSeconds = useableSeconds - 4
········· HIGH 10
········· IF((useableSeconds- 2) >= 0) THEN
··········· useableSeconds = useableSeconds - 2
··········· HIGH 9
··········· IF((useableSeconds - 1) >=0)· THEN
··········· useableSeconds = useableSeconds - 1
··········· HIGH 8
··········· ENDIF
········· ENDIF
······· ELSEIF((useableSeconds- 2) >= 0) THEN
··········· useableSeconds = useableSeconds - 2
··········· HIGH 9
··········· IF((useableSeconds - 1) >=0)· THEN
··········· useableSeconds = useableSeconds - 1
··········· HIGH 8
··········· ENDIF
······· ELSEIF((useableSeconds - 1) >=0)· THEN
··········· useableSeconds = useableSeconds - 1
··········· HIGH 8
··········· ENDIF
··········· PAUSE 950
···········


NEXT

Post Edited (Chris Palmer) : 11/22/2007 1:26:56 AM GMT

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-11-22 02:54
    Just a thought, but how about directly outputting the binary counter values to the output register?
    out13 = seconds.bit5
    out12 = seconds.bit4
    outc = seconds.nib0
    
    
  • Chris PalmerChris Palmer Posts: 5
    edited 2007-11-22 04:00
    I am sorry, I am really just beginning. Could you explain what that means.
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2007-11-22 05:11
    Hi Chris, Mike is refering to the OUT register. If you look at the Pbasic help file of the IDE under the section headed Memory and Variables you will see it describes the OUT register. This along with registers IN and DIR allows you to read or set the status of the I/O pins individually or more usefully in blocks.

    This is ideal for your application because all you have to do is pass the OUT register a value and it will appear at the outputs in binary fashion.

    When you connect your diodes connect the anode of each one to its respective output (as you have done) then connect a resistor of at least 220 ohms to the cathode of each diode (so 6 LED's = 6 resistors). Connect the other end of the resistors to VSS.

    Heres an example to help you understand, it requires 4 diodes with resistors. Connect the anodes to P0,P1,P2,P3 respectively. The diodes should "count" to 15 binary then reset to 0 and start again. It will also display binary and decimal in a debug window.

    DIRA=%1111·· '//SET I/O PINS 0-3 AS OUTPUTS
    main:
    IF OUTA =16 THEN OUTA=0
    OUTA= OUTA+1
    DEBUG CRSRXY,0,0,BIN4 OUTA,"· ",DEC2 OUTA
    PAUSE 1000
    GOTO main

    Jeff T.
  • Chris PalmerChris Palmer Posts: 5
    edited 2007-11-22 05:37
    Thanks a lot.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-11-26 15:34
    There is a limit to the current you can draw from the I/O pins.· Each I/O pin on a BS2 can source 20 mA or sink 25 mA, but the total per group of 8 I/O pins should not exceed 40 mA source or 50 mA sink.· With 8 LEDs it would be easy to do this.· You could drive 8 LEDs from a ULN2803 or similar chip instead.· In fact, since you’re going to need more than just seconds, you might want to consider using a 74HC595 to drive the LEDs.· Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
Sign In or Register to comment.