PDA

View Full Version : Tach Project (binary counting)...



Netjammer
- 12th November 2004, 18:32
Hello Everyone! I'm progressing with my Tach project. I finally have all the parts
I need at least :) Things had been progressing until I ran into this bug...

The Circuit:
I'm using a 16F877 and a Max7219. I have each individual segment attached
to the anode of a discreet LED. The cathodes are all connected common to DIGO
of the Max7219. I have 8 LED's total connected (using the DP's output too).

The Code:
I've taken code written for the Basic Stamp 2 and modified it to work with my
PicBasic Pro / hardware setup. The final version will have 32 LED controlled
by Max7219 & 16F877. Code is listed below.

The Problem:
The code will count binary up to 14. When it reaches 15 (f) or 00001111 it
completely halts and all the LED's turn off. I thought it was pulling too
much current so I ran the shiftout function with %1111111111111111/16 which
turned on all the LED successfully so I'm guessing this is not an issue of
drawing too much current.

Request:
Anyone have PicBasic Pro Code that supports the Max7219 driving LED's and
not Digits? Ideally with the 16f877 and the microcontroller. If not, I can
remap the I/O pins.

I've explored modifying the scan limit, decode mode, intensity, shutdown
mode etc. still no favorable results.

Thank you for your time,
Netjammer-






' ================================================== =======================
include "modedefs.bas"

' -----[ Program Description ]---------------------------------------------
' Counting binary from 0 to 1111 (want to go to 11111111 but routine halts
'& LED's turn off

' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------
'symbol MAX_Data = PORTC.5 'line for data input connected to RC5
'symbol MAX_Clk = PORTC.3 'CLK line connected to pin RC3
'symbol MAX_Load = PORTA.3

symbol DOUT = PORTC.5 'line for data input connected to RC5
symbol CLK = PORTC.3 'CLK line connected to pin RC3
symbol Load = PORTA.3 'line for Load connected to RA3


' -----[ Constants ]-------------------------------------------------------
IsLow CON 0
IsHigh CON 1

' -----[ Variables ]-------------------------------------------------------
DIG0 VAR Word
DIG1 VAR Word
DIG2 VAR Word
Value VAR byte
Ken VAR byte

' -----[ EEPROM Data ]-----------------------------------------------------


' -----[ Initialization ]--------------------------------------------------
Dig0 = $0100
Dig1 = $0200
Dig2 = $0300
Value = 0
Ken = 0

' -----[ Program Code ]----------------------------------------------------
Begin:
GOSUB DecodeMode
GOSUB ShutDownMode
GOSUB ScanLimit
GOSUB Intensity



Continue:
'the for next loop is set up to cause each digit to count up
'sequentially from 1 to 100

FOR Ken = 0 TO 100

PAUSE 500

Dig0 = Dig0 | Value
Dig1 = Dig1 | Value
Dig2 = Dig2 | Value

'first digit least significant
LOW Load
SHIFTOUT DOUT, CLK, MSBFIRST,[Dig0\16]
HIGH Load
PAUSE 40


'second digit
' LOW Load
' SHIFTOUT DOUT, CLK, MSBFIRST,[Dig1\16]
' HIGH Load
' PAUSE 40

'third digit
' LOW Load
' SHIFTOUT DOUT, CLK, MSBFIRST,[Dig2\16]
' HIGH Load
' PAUSE 40

Value = Value + 1
Dig0 = $0100
' Dig1 = $0200
' Dig2 = $0300
NEXT
Value = 0

Dig0 = $0100
' Dig1 = $0200
' Dig2 = $0300

GOTO Continue


END
' -----[ Subroutines ]-----------------------------------------------------
'Decode mode for no decoding to BCD
'Least sig nibble:
'0 = no decode
'1 = decode digit 0
'F = decode digits 0-3
'FF = decode digits 0-7
DecodeMode:
LOW Load
' SHIFTOUT DOUT, CLK, MSBFIRST,[$090F\16]
SHIFTOUT DOUT, CLK, MSBFIRST,[$0900\16]
HIGH Load
RETURN

'Set shutdown mode so device is active
ShutDownMode:
LOW Load
SHIFTOUT DOUT, CLK, MSBFIRST,[$0C01\16]
HIGH Load
RETURN


'Set scan limit mode for three digits
ScanLimit:
LOW Load
' SHIFTOUT DOUT, CLK, MSBFIRST,[$0B02\16]
SHIFTOUT DOUT, CLK, MSBFIRST,[$0B00\16]
HIGH Load
RETURN

'Set intensity of LEdDs
'LSNibble 0 = min intensity and F = max intensity
Intensity:
LOW Load
SHIFTOUT DOUT, CLK, MSBFIRST,[$0A09\16]
HIGH Load
RETURN

mister_e
- 15th November 2004, 13:15
The same weird situation will happen also when using SPI EEPROM.

As i can see, the device don't accept the non decode mode. So $0F is Blank output. The only thing i can suggest is add

HIGH Load
Pause 20 ;maybe unecessary

before Gosub DecodeMode line.

let me know

regards

Netjammer
- 16th November 2004, 06:22
Originally posted by mister_e
The same weird situation will happen also when using SPI EEPROM.

As i can see, the device don't accept the non decode mode. So $0F is Blank output. The only thing i can suggest is add

HIGH Load
Pause 20 ;maybe unecessary

before Gosub DecodeMode line.

let me know

regards

Hi mister_e,
I tried your suggestion with the Pause 20, it had no effect. As far as $0F value I re-wrote the the shiftout command so that it now passes the binary equivalent. This works great for certain binary numbers. As an example:

00001111 (works)
00011111 (doesn't work)

00001111 0000111 00001111 00000111 (works)
00001111 0001111 00001111 00011111 (doesn't work)

I can adjust any bank with certain binary numbers. I've posted modified code below. Along with some photos of the setup. One curious affect is that no matter what binary numbers I have "ON" after a period of time ALL the banks will turn off.

Thanks for the suggestions I really appreciate it!
Netjammer-


Here is the code...

' ================================================== =======================
'
' File......MAX7219
' Purpose...
' Author...
' E-mail....
' Started...
' Updated...
'
' {$}
' {$PicBasicPro 2.5}
'
' ================================================== =======================
include "modedefs.bas"

' -----[ Program Description ]---------------------------------------------
' 4 Sets of 8 LED's (32 total). Each Dig# able to have an 8 bit number
' assigned to it.

' -----[ Revision History ]------------------------------------------------

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


symbol DOUT = PORTC.5 'line for data input connected to RC5
symbol CLK = PORTC.3 'CLK line connected to pin RC3
symbol Load = PORTA.3


' -----[ Constants ]-------------------------------------------------------
IsLow CON 0
IsHigh CON 1

' -----[ Variables ]-------------------------------------------------------
COUNter var byte
' -----[ EEPROM Data ]-----------------------------------------------------

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

' -----[ Program Code ]----------------------------------------------------
Begin:

GOSUB DecodeMode
GOSUB ShutDownMode
GOSUB ScanLimit
GOSUB Intensity
' gosub displaytest

Continue:

'first LED bank
LOW Load
ShiftOut DOUt,clk,MSBFIRST,[%0000000100001111\16]
HIGH Load
PAUSE 100

'second LED bank
LOW Load
ShiftOut DOUt,clk,MSBFIRST,[%0000001000111000\16]
HIGH Load
PAUSE 10

'third LED bank
LOW Load
ShiftOut DOUt,clk,MSBFIRST,[%0000001100000111\16]
HIGH Load
PAUSE 10

'fourth LED bank
LOW Load
' 87 0
ShiftOut DOUt,clk,MSBFIRST,[%0000010011100000\16]
HIGH Load
PAUSE 10

GOTO continue
END
' NEXT


' -----[ Subroutines ]-----------------------------------------------------
DecodeMode:
LOW Load
' SHIFTOUT DOUT, CLK, MSBFIRST,[$090F\16]
SHIFTOUT DOUT, CLK, MSBFIRST,[$0900\16]
HIGH Load
PAUSE 20
RETURN
'Set shutdown mode so device is active
ShutDownMode:
LOW Load
SHIFTOUT DOUT, CLK, MSBFIRST,[$0C01\16]
HIGH Load
PAUSE 20
RETURN
'Set scan limit mode for three digits
ScanLimit:
LOW Load
SHIFTOUT DOUT, CLK, MSBFIRST,[$0B03\16]
HIGH Load
PAUSE 20
RETURN
'Set intensity of LEdDs
Intensity:
LOW Load
SHIFTOUT DOUT, CLK, MSBFIRST,[$0A09\16]
HIGH Load
PAUSE 20
RETURN
'Set Display Test mode active
DisplayTest:
LOW Load
SHIFTOUT DOUT, CLK, MSBFIRST,[$0F01\16]
HIGH Load
PAUSE 20
RETURN

Photo attached...

mister_e
- 16th November 2004, 16:28
hummm, great setup. It really looks like it doesn't accept no-decode mode since

00001111 (works)
00011111 (doesn't work)

it's still refer to blank... for some

what about using those

high Load
pause 100
GOSUB ShutDownMode
GOSUB ScanLimit
GOSUB Intensity
GOSUB DecodeMode

and what about if you access to each digit separately???

Damn it's suppose to work!!! i'll try to find one of thes MAX7219 'round here to experiment too.

let me know what's happen now

mister_e
- 16th November 2004, 16:33
Are you using PIC16F877 ???? PORTA.3 for LOAD/CS pin.... PORTA.3 is analog. Must be turn to digital

ADCON1=7 ;turn off PORTA & PORTE to digital

Netjammer
- 17th November 2004, 06:55
Originally posted by mister_e
Are you using PIC16F877 ???? PORTA.3 for LOAD/CS pin.... PORTA.3 is analog. Must be turn to digital

ADCON1=7 ;turn off PORTA & PORTE to digital

Hi mister_e,
First off thanks again for giving me hand. I added the ADCON1=7 command as follows <snippet>

'********
symbol DOUT = PORTC.5 'line for data input connected to RC5
symbol CLK = PORTC.3 'CLK line connected to pin RC3
symbol Load = PORTA.3
ADCON1 = 7
'********

I read up on MELabs site about the intermittent problems they have when not turning off the A/D functions. Great tip. I did try adding the pause commands as you suggested. Still no change. I do see that the pause commands are taking affect as I'm monitoring the pins on a O-Scope.

A few observations:

I can have banks 1, 2 & 3 all 00000000 and bank 0 = 00011111 and all LED's on bank 0 shutsdown. As soon as I go to 00001111 all is well.

I cannot go into Display test mode, this also shutsdown all LED's.

Output of 16F877 pin#24 RC.5 has a strange output. Has 2 sets of pulses - a 12.5 Hz pulse and a 50 Hz pulse. I can see both at the same time (not using a dual channel scope mode). I attached a screen shot of the pulses. Not too good but you'll get the idea.

I am using the default 4MHz clock, I was under the impression that the clock pulse would be a constant pulse at a particular rate out. It almost looks like a burst of pulses (15 of them) then it starts the pattern over. I'm going to recheck my oscope to make sure I'm not in some un-calibrated mode.

Thanks for all the help you have given me. Their must be something I'm missing...

George-
Netjammer-

mister_e
- 17th November 2004, 16:53
i'm not 100% sure but, i don't think those lines work:
'********
symbol DOUT = PORTC.5 'line for data input connected to RC5
symbol CLK = PORTC.3 'CLK line connected to pin RC3
symbol Load = PORTA.3


must be like this
'********
DOUT VAR PORTC.5 'line for data input connected to RC5
CLK VAR PORTC.3 'CLK line connected to pin RC3
Load VAR PORTA.3

i've order one MAX7219 to play with... i'm still curious on this chip.

i'll still check if i can find something to help you.

regards

Netjammer
- 18th November 2004, 05:25
mister_e Finally got it! I had tried your suggestions as far as renaming the Port variables. Still had the same result.

Looking at the Max7219 Application notes regarding supply biasing they recommend using a filter cap on the +5 side of the rail. This is used to reduce power supply ripple during peak digit driver current. In my case I was driving 32 LED's. I installed a 10uF capacitor right onto the +5V line (not the current resistor line) and all the LED's came on!

Sheesh.. in a way it was probably better that it worked out this way. I got great tips from you and learned a lot more about both IC's in the process. Probably wouldn't even have bothered printing out the 216 page 16F877 datasheet if it wasn't for this blip.

Monitoring the +5V line with a scope I still see transient pulses. I need to add the .1uF cap in parallel with the 10uF. I'll find what the best cap combo is for me and post it up. May save someone some headaches.

Thanks for all the help!
Netjammer-

mister_e
- 18th November 2004, 12:50
Looking at the Max7219 Application notes regarding supply biasing they recommend using a filter cap on the +5 side of the rail. This is used to reduce power supply ripple during peak digit driver current. In my case I was driving 32 LED's. I installed a 10uF capacitor right onto the +5V line (not the current resistor line) and all the LED's came on!

i just receive this MAX7219 and i use your code and in fact everything is work... so i was thinking something was missing or bad connection on your bread-board or supply line before reading your post... in fact you must always use cap near every ics. Let's say .1uF ceramic. for my case i use 0.1uF near pic, and max7219 + 10uF tantalum close to MAX7219 and at the input of the bread board. Supply line is really neat and clean. Tantalum is a great choice to avoid glitchs and noise caused by these ics.

Some people use 47uF electrolytic instead of 10uF tantalum. easier to find? cheaper? but bigger!!!

great to know everything is now working. Well, looks we have both learn about this MAX ic. What a great chip :)

regards