Shop OBEX P1 Docs P2 Docs Learn Events
Serial Help (Bargraph Tach) — Parallax Forums

Serial Help (Bargraph Tach)

ArchiverArchiver Posts: 46,084
edited 2001-04-23 09:57 in General Discussion
Yes I did get the Tach working. I used the MAX7219, I found the
display I was useing has 56 segments, and the max RPM is 7000. well
if you take 7000/56 you come up with 125 RPM per segment. the way I
made it work is (FULL WORKING PROGRAM)

'This program is for a Bar Graph display
'of a tach input. Using a MAX7219
'8 digit LED display driver.
'
'Electrical conections
'
'
'BS2 MAX7219
' 1---*
1
' 2---|---*
12
' 0---|---|---*
13
' | | |
' \ \ \
' / / /
' \ \ \ 10K Ohm
' / / / Restors
' | | |
' | | |
' |---*---|
' |
' ///
'
'
'
'
' VF display MAX7219
' |
|
' | [noparse]/noparse [noparse]/noparse..|...segment DP.....pin 22
' |
....|...sgement A......pin 14
' |
....|...segment B......pin 16
' |
....|...segment C......pin 20
' |
....|...segment D......pin 23
' |
....|...segment E......pin 21
' |
....|...segment F......pin 15
' |
....|...segment G......pin 17
' |
|
'
'
'
'

'====VARIBLES USED IN THE PROGRAM====

max_dat var word
tach_in var word
rpm var word
tach var word
index var byte
temp var word
odd var index.bit0

'===REGISTER ADDRESSES FOR THE 7219==

decode con 0
brite con 10
scan con 11
switch con 12
test con 15

'=====CON============================

cyl con 8

'===SET ALL PINS OUTPUT LOW==========

outs = 0
dirs = $FFFF

'======INITIALIZE THE MAX7219========

for index = 0 to 7
lookup index,[noparse][[/noparse]scan,6,brite,3,decode,0,switch,1],max_dat
shiftout 1,0,msbfirst,[noparse][[/noparse]max_dat]
if odd = 0 then noload
pulsout 2,1
noload:
next

'==========MAIN PROGRAM LOOP=========

loop:
count 3,500,tach_in
rpm = ((tach_in*2)*60)/cyl
tach = rpm
gosub tachdisplay
goto loop


'=========SUBROUTINES================

tachdisplay:
for index = 1 to 7 'do it for all displays(chang for no.
shiftout 1,0,msbfirst,[noparse][[/noparse]index] ' of displays that you use)
if tach => 1000 then grand 'is tach more then 1000
if tach => 875 then seg7 'is tach more then 875
if tach => 750 then seg6 'is tach more then 750
if tach => 625 then seg5 'is tach more then 625
if tach => 500 then seg4 'is tach more then 500
if tach => 375 then seg3 'is tach more then 375
if tach => 250 then seg2 'is tach more then 250
if tach => 125 then seg1 'is tach more then 125
if tach => 0 then seg0 'is tach more then 0

grand:
temp = $FF
tach = tach - 1000
goto send

seg7:
temp = $7F
tach = tach - 875
goto send

seg6:
temp = $3F
tach = tach - 750
goto send

seg5:
temp = $1F
tach = tach - 625
goto send

seg4:
temp = $0F
tach = tach - 500
goto send

seg3:
temp = $07
tach = tach - 375
goto send

seg2:
temp = $03
tach = tach - 250
goto send

seg1:
temp = $01
tach = tach - 125
goto send

seg0:
temp = $00
tach = tach - 0
goto send

send:
shiftout 1,0,msbfirst,[noparse][[/noparse]temp]
pulsout 2,5
next
return


fill free to use this program. I spent meny hours trying to figure it
out(figured it out at the worst place "WORK!").



Thanks to all who gave me some ideas
TC

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2001-04-23 09:57
    Hi TC

    I don't know the MAX7219 but, at first glance, your subroutine can be
    heavily simplified as follows:

    ·tachdisplay
    ·· temp = 1
    ·· tach = tach/125
    ·· for index = 0 to tach
    ·· shiftout 1,0,msbfirst,[noparse][[/noparse]index,(temp - 1)]
    ·· pulsout 2,5
    ·· temp = temp << 1
    ·· next
    ·· return
    this is only my 2c antispaghetti contribution.
    Note: Spaghetti code is said for code with a lot of branches.
    Regards
    ECO
    >

    Original Message

    From: <aconti@neo.rr.com>
    To: <basicstamps@yahoogroups.com>
    Sent: dimanche 22 avril 2001 16:47
    Subject: [noparse][[/noparse]basicstamps] Re: Serial Help (Bargraph Tach)

    > Yes I did get the Tach working. I used the MAX7219, I found the
    > display I was useing has 56 segments, and the max RPM is 7000
Sign In or Register to comment.