Guten tag:
Ich hab ein kleines project für die weihnachtsfeier von meine firma es ist ein applausometer mit 16 stufen , also brauche 16 pins von mein atmega 16, ich verwende port c und d, ich hab der code vom Bascom beispiel Bg30db led ein bischen modifiziert , ich benutze ein analogeingang (ADC 0), an dieser eingang hab ich ein microfon mit ein transistor als verstärker angeschlossen.
es funktioniert alles , aber ich täte mir wünschen das der spitzenwert erhalten bleibt für ein paar sekunden , und das die leds ein bischen ruhiger werden , hatt vielleicht jemand von euch schon so was gebaut ?
Zum project , es sind 48 reihen und 11 spalten mit 10 mm leds bestückt , also 528 ultrahelle leds .
Möchte es ansteuern mit 3 led reihen pro pin , dazu will ich verwenden ein uln 2803.
Wenn jemand ideen oder vorschläge hatt bitte her damit
Code:
'--------------------------------------------------------------------------------
'name : BG30dB_LED.bas
'copyright : (c) 1995-2005, MCS Electronics
'purpose : create a logarithmic LED bar graph dB (VU) meter
'micro : AT90S2313-10
'suited for demo : yes
'commercial addon needed : no
'use in simulator : possible
'
' Author : Ger langezaal
'
'---[ Small program description ]-----------------------------------------------
'
' This program is written to create a logarithmic LED bar graph dB (VU) meter
' with peak-hold and drop-down. Scale range is 30dB in 3dB steps.
' Log conversion is done with the analog comparator on a RC discharge curve.
' C1 is charged each 4mS with PB0 as output on a Timer0 Interrupt.
' Then PB0 is set to AIN0 (analog comparator +input) Timer1 is reset
' and start counting, C1 will be discharged by R1.
' Timer1 is counting until AIN0 < AIN1.
' Analog Comparator Output = ACSR bit 5.
' Timer1 value is in T1 stored for calculation.
'
' Display mode is set with PD6 (pin 11).
' 1 = bar mode
' 0 = dot mode (for low current applications)
'---[ LED to AVR connections ]--------------------------------------------------
'
' AVR Resistor Cathode dB
' Port pin Ohm LED nr Scale
' PD5 9 >--[680]--> 11 +6
' PD4 8 >--[680]--> 10 +3
' PD3 7 >--[680]--> 9 0
' PD2 6 >--[680]--> 8 -3
' PD1 3 >--[680]--> 7 -6
' PD0 2 >--[680]--> 6 -9
' PB7 19 >--[680]--> 5 -12
' PB6 18 >--[680]--> 4 -15
' PB5 17 >--[680]--> 3 -18
' PB4 16 >--[680]--> 2 -21
' PB3 15 >--[680]--> 1 -24
' PB2 14 >--[680]--> 0 infinit
'
' All LED Anodes to +5 Volt
'
'---[ Analog comparator inputs ]------------------------------------------------
'
'
' Meter DC input >-------[ R2 ]-------> PB1 (AIN1 pin 13)
' |
' GND <---------||-----
' C2
'
' ---[ R1 ]---
' GND <----| |----> PB0 (AIN0 pin 12)
' -----||-----
' C1
' R1 = 10k 5%
' R2 = 10k
' C1 = 47nF 5%
' C2 = 47nF
'
'---[ DC input versus Timer1 and Led position ]---------------------------------
'
' Measured Timer1 values for calculation:
' DC input = 3500mV Timer1 = 192 ( +6dB)
' DC input = 312mV Timer1 = 1544 (-15dB) 21dB = factor 11.22
' 21dB = 1543 - 192 = 1351 Timer1 counts
' 3dB = 1351 / 7 = 193 Timer1 counts
'
' Input mv Timer1 LED pos dB scale
' 3500 192 11 +6
' 2477 385 10 +3
' 1753 578 9 0
' 1241 771 8 -3
' 879 965 7 -6
' 622 1158 6 -9
' 440 1351 5 -12
' 312 1544 4 -15
' 220 1737 3 -18
' 156 1930 2 -21
' 110 2123 1 -24
' <110 >2123 0 infinit
'
'---[ Compiler and hardware related statements ]--------------------------------
$regfile = "m32def.dat" 'register file for AT90S2313
$crystal = 16000000 '10MHz crystal
$hwstack = 32 ' default use 32 for the hardware stack
$swstack = 10 'default use 10 for the SW stack
$framesize = 40 'default use 40 for the frame space
Config Portc = Output
Config Portd = Output
config portb = output
Config Porta.0 = Input 'output high and enable input pullup
$sim
'enable analog comparator ACSR bit 7 = 0
'---[ Variables ]---------------------------------------------------------------
Dim Peak_pos As Byte
Dim Peak_hold As Byte
Dim Drop_hold As Byte
Dim Led_pos As Word
Dim Bar_pattern As Word
Dim T1 As Word
'---[ Constants ]---------------------------------------------------------------
Const Peak_hold_time = 200
Const Drop_down_time = 40
Const Led_max = 16 'Led 0 - 11
Const T1_fs = 325
'full scale Timer1 value
Const T1_step = 12 '3dB step Timer1 value
'Calculate Timer1 range
'---[ Timer Configuration ]-----------------------------------------------------
Config Adc = Single , Prescaler = Auto , Reference = Internal
'R/C Timer
'reset after 1 Sec no reset watchdog
Start Adc
'---[ Main program loop ]-------------------------------------------------------
Do
'set all bits
'bar display mode
Bar_pattern = Lookup(led_pos , Bar_mode)
'reset peak bit
Portd.7 = Bar_pattern.15
Portd.6 = Bar_pattern.14 'led 11 = bit 11
Portd.5 = Bar_pattern.13 'reset peak bit
Portd.4 = Bar_pattern.12
Portd.3 = Bar_pattern.11 'led 11 = bit 11
Portd.2 = Bar_pattern.10
Portc.0 = Bar_pattern.7
Portc.1 = Bar_pattern.6
Portc.2 = Bar_pattern.5
Portc.3 = Bar_pattern.4
Portc.4 = Bar_pattern.3
Portc.5 = Bar_pattern.2
Portc.6 = Bar_pattern.1
Portc.7 = Bar_pattern.0
'led 0 = bit 0
Print T1
'-------------------------------------------------------------------------------
'-------------------------------------------------------------------------------
'---[ Interrupt Service Routine on Timer0 overflow ]---------------------------
'read Timer1 value
T1 = Getadc(0)
Led_pos = T1_fs - T1 'calculate led position
Led_pos = Led_pos \ T1_step 'led_pos = 0 - 11
Loop
Return
'---[ Led Bar pattern lookup data ]---------------------------------------------
' Led 11......... 0
Bar_mode:
Data &B1111111111111111% 'Word constants must end with the %-sign
Data &B1111111111111110%
Data &B1111111111111100%
Data &B1111111111111000%
Data &B1111111111110000%
Data &B1111111111100000%
Data &B1111111111000000%
Data &B1111111110000000%
Data &B1111111100000000%
Data &B1111111000000000%
Data &B1111110000000000%
Data &B1111100000000000%
Data &B1111000000000000%
Data &B1110000000000000%
Data &B1100000000000000%
Data &B1000000000000000%
Lesezeichen