PDA

View Full Version : 7Seg-DB Daughterboard with BS2



Richard McCall
07-30-2008, 03:53 AM
I purchased the Parallax 7Seg-DB Daughterboard and the adaptor that allows it to be used with a regular breadboard.

Although I realize that it is made to take advantage of the BS2pe motherboard and its additional processors, I'm wondering if there is not some further documentation that will help me program the unit using Basic. The exisiting documentation treats only high level programming with much of the interface uploaded in hex to the motherboard.

The schematic is somewhat helpful in figuring out the display driver, but I would be helped if there were some documentation on the timing and sequence of commands (I've been using SHIFTOUT) as well as the codes associated with each digit.

Has anyone successfully programmed this unit using basic (Parallax or PICBasicPro) or know of any further resources?

Thanks,
Rick

Phil Pilgrim (PhiPi)
07-30-2008, 05:44 AM
It will be difficult to do what you want with just the BS2, since the digits on the 7Seg-DB are multiplexed and require constant refreshing to make all four of them "appear" at once. That said, the procedure for doing so (for one daughterboard) is this:

Initialization:

1. Raise /PWM.
2. Raise SCK.
3. Pulse RCK four times. This clears the anode driver shift register to all 1s.
4. Lower /PWM.

For each digit, in sequence:

1. Using SCK and D, clock in the segments for the first digit (1 = bright; 0 = dark). Leave SCK high for all but the first digit in every group of four.
2. Pulse RCK. This outputs the segment data just clocked in and shifts SCK into the anode driver shift register. Any "0" previously shifted in will advance to the next digit.
3. Return SCK low, if it's still high.
4. Repeat.

Following this procedure, the anode driver shift register will change state like so after each digit:

1110 <- SCK = 0
1101 <- SCK = 1
1011 <- SCK = 1
0111 <- SCK = 1
1110 <- SCK = 0
...

The use of SCK as an input to the anode driver shift register may preclude using SHIFTOUT for all eight bits of the segment data. You may have to use it for 7 bits and bit-bang the last one in order to keep SCK high at the end.

Whether a BS2 program can execute fast enough not to cause noticeable flicker among the digits remains to be seen. If you are successful, please post your code on the forum.

Good luck!
-Phil

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
'Still some PropSTICK Kit bare PCBs (http://forums.parallax.com/showthread.php?p=729096) left!

Richard McCall
07-30-2008, 06:03 AM
Many thanks! That's very helpful. It will save me much trial and error.

Rick

Richard McCall
07-31-2008, 10:11 PM
Again, thanks for your advice.

Using "SHIFTOUT D,SCK,1,[$E7]," for example, I can easily transfer the segments to the 74HCT595. Of course, the same number appears in each digit when RCK is pulsed.

I'm not sure how the proper state gets transferred to SCK so that it can be sent to the anode driver. If I use "SHIFTOUT, SCK,RCK,1,[%1101]," for example, a particular digit is selected. However, depending on where this command appears, it either corrupts the segment data or produces uneven intensities on the digits.

Could you say a bit more about how to clock the data into the 74HCT595 so that the SCK line contains the proper data to send to the anode driver? How many bits can the register hold?

Thanks for your help and patience.

Rick

Phil Pilgrim (PhiPi)
07-31-2008, 11:37 PM
SHIFTOUT always ends with the clock pin low. As I stated above, you can still use SHIFTOUT for the first seven bits, but you will have to clock the last bit into the '595 by bit banging it. That way, you can end with SCK high or low, depending on which digit is being clocked. Try this:




DO
IF (Digit) THEN
SHIFTOUT D, SCK, 1, [Char(Digit)], 7
D = Char(Digit).BIT0
HIGH SCK
ELSE
SHIFTOUT D, SCK, 1, [Char(Digit)]
ENDIF
PULSOUT RCK, 1
LOW SCK
Digit = Digit + 1 & 3
LOOP




This is untested code and relies on Char being a Byte array of length four, and D, SCK, and RCK being defined appropriately using PIN commands.

-Phil

Richard McCall
07-31-2008, 11:52 PM
Once again, thank you. I very much appreciate your guidance.

Rick

Richard McCall
08-05-2008, 09:26 PM
Here's the demo program (it counts up to 9999 on the daughterboard 7-seg LED) using your suggestions. It works quite nicely, and the subroutine could be used for any kind of input.

Thanks again for your your helpful suggestions.

Rick
__________________________________________________ _______________________________
' {$STAMP BS2}
' {$PBASIC 2.5}

'~~~~~~~Definitions~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~

RCK PIN 6 'Parallax adapter pin A (RCK)
D PIN 7 'Parallax adapter pin B (DI)
SCK PIN 5 'Parallax adapter pin C (SCK)
PW PIN 4 'Parallax adapter pin D (PWM) 120 K Resistor


digit VAR Byte
i VAR Byte
Char VAR Byte(4)
number VAR Byte
cnt VAR Word
digt VAR Byte
lsb VAR Byte
t VAR Byte

'~~~~~~~~INITIALIZATION~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~
HIGH PW
HIGH SCK
FOR i = 1 TO 4
PULSOUT RCK,1
NEXT
LOW PW

'~~~~~~~~~MAIN PROGRAM~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~

Counter:
cnt = 0 'Initialize Cnt to 0

NXT:

digit = cnt DIG 3 'Get 1000s digit
GOSUB CONVERT 'Get segments to turn on
Char(0) = number 'Display pattern for 1000s digit

digit = cnt DIG 2 'Get 100s digit
GOSUB CONVERT 'Get segments to turn on
Char(3) = number 'Display pattern for 100s digit

digit = cnt DIG 1 'Get 10s digit
GOSUB CONVERT 'Get segments to turn on
Char(2) = number 'Display pattern for 10s digit

digit = cnt DIG 0 'Get 1s digit
GOSUB CONVERT 'Get segments to turn on
Char(1) = number 'Display pattern for 1s digit

GOSUB display 'Display number on Parallax 7-Seg Daughterboard

cnt = cnt + 1 'Increment Cnt
IF cnt > 9999 THEN Counter
GOTO NXT

'~~~~~~~~~~~~DISPLAY SUBROUTINE~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Display:

IF cnt < 10 THEN char(0)= 0:char(2) = 0:char(3) = 0 'Suppress leading zeros
IF cnt < 100 THEN char(0) = 0:char(3) = 0
IF cnt < 1000 THEN char(0) = 0

FOR t = 1 TO 200 'Timing loop for counter

IF (digt) THEN 'For digits 1, 2,and 3,
lsb = Char(digt)& 1 'save LSB in variable y
SHIFTOUT d,SCK,1,[Char(digt) >> 1\7] 'Shift byte 1 bit to right and shift result into register
D = lsb 'Bang saved bit in
HIGH SCK 'Take SCK high
ELSE
SHIFTOUT D,SCK,1,[Char(digt)] 'For digit 0, shift byte into register
ENDIF
PULSOUT RCK,1 'Send clock pulse
LOW SCK 'Take SCK low
digt = digt + 1 & 3 'Increment digit (using first two bits)

NEXT
RETURN

'~~~~~~~~~~DIGIT CONVERSION SUBROUTINE~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

CONVERT:
LOOKUP digit,[$E7,$60,$57,$75,$F0,$B5,$B7,$64,$F7,$F5],number
RETURN

END

Phil Pilgrim (PhiPi)
08-06-2008, 05:32 AM
Richard,

I'm glad you got it working! Nicely done!

-Phil

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
'Still some PropSTICK Kit bare PCBs (http://forums.parallax.com/showthread.php?p=729096) left!