PDA

View Full Version : VU Meter



Andre_Pretorius
- 18th May 2009, 16:48
Hi there
I have a LM358 amplifie-ing a maic signal to my pic16F913 AD input, this signal is used to drive 8 LED's in a VU meter fasion This part works fine.

Now i have a input that when made gets the signal and set a alarm setpoint one LED lower than the current signal === First problem with the signal variang fast it does not whant to select properly

Now what needs to happen is that as soon as the signal passes the setpoint again it needs to set a output basicly a high noise alarm, but my rele shutter if i add a timer it influence my VU meter

any one with some idea, here is my code for info



INCLUDE "MODEDEFS.BAS"

Asm
ERRORLEVEL -306
Endasm

DEFINE OSC 20 ' Define crystal as 20Mhz

'*ADC setup*
DEFINE ADC_BITS 10 'SETS NUMBER OF BITS IN RESULTS 8,10,12
DEFINE ADC_CLOCK 3 'SETS CLOCK SOURCE (RC = 3)
DEFINE ADC_SAMPLEUS 50 'SETS SAMPLING TIME IN MICROSECONDS

'This Part set PORTA 0-5 an analog inputs
ADCON1 = %01110000 'FRC (clock derived from a dedicated internal oscillator = 500 kHz max)
ANSEL = %00000011 'PortA 0 & 1 Analog 2 - 5 Digital
'The ANSEL (91h) and CMCON0 (9Ch)registers must be initialized to configure an
CMCON0 = %00000111 'analog channel as a digital input. Pins configured as analog inputs will read ‘0’.
TRISA = %00001111 'set PORTA 0-4 as inputs PORTA 5 output
ADCON0.7 = 1 'Right justify output of ADC datasheet P145 of 16F913

LCDCON = 0 'Disable LCD function on PORTC 0 - 2
TRISC = %00000000 'Set PORTC as output
TRISB = %00000000 'Sert PORTB as output

I VAR BYTE
j VAR BYTE
K VAR BYTE
L VAR BYTE
arr var word[10]

V1 VAR WORD
PORTB = 0


READ 1,J

Main:
for l = 0 to 9
ADCIN 0,V1
arr(l) = V1/60
next l

I = (ARR(0)+ARR(1)+ARR(2)+ARR(3)+ARR(4)+ARR(5)+ARR(6)+ ARR(7)+ARR(8)+ARR(9))/10

IF I >= J THEN
PORTA.5 = 1

ENDIF

IF I <= (J-1) THEN
PORTA.5 = 0
ENDIF


IF PORTA.2 = 0 THEN
K = I - 1
PAUSE 300
IF J <> K THEN
WRITE 1,K
J=K
ENDIF
ENDIF

IF J = 1 THEN
PORTB.0 = 1
ELSE
PORTB.0 = 0
ENDIF

IF J = 2 THEN
PORTB.1 = 1
ELSE
PORTB.1 = 0
ENDIF

IF J = 3 THEN
PORTB.2 = 1
ELSE
PORTB.2 = 0
ENDIF

IF J = 4 THEN
PORTB.3 = 1
ELSE
PORTB.3 = 0
ENDIF

IF J = 5 THEN
PORTB.4 = 1
ELSE
PORTB.4 = 0
ENDIF

IF J = 6 THEN
PORTB.5 = 1
ELSE
PORTB.5 = 0
ENDIF

IF J = 7 THEN
PORTB.6 = 1
ELSE
PORTB.6 = 0
ENDIF

IF J = 8 THEN
PORTB.7 = 1
ELSE
PORTB.7 = 0
ENDIF

IF I >= 1 THEN
PORTC.0 = 1
ELSE
PORTC.0 = 0
ENDIF

IF I >= 2 THEN
PORTC.1 = 1
ELSE
PORTC.1 = 0
ENDIF

IF I >= 3 THEN
PORTC.2 = 1
ELSE
PORTC.2 = 0
ENDIF

IF I >= 4 THEN
PORTC.3 = 1
ELSE
PORTC.3 = 0
ENDIF

IF I >= 5 THEN
PORTC.4 = 1
ELSE
PORTC.4 = 0
ENDIF

IF I >= 6 THEN
PORTC.5 = 1
ELSE
PORTC.5 = 0
ENDIF

IF I >= 7 THEN
PORTC.6 = 1
ELSE
PORTC.6 = 0
ENDIF

IF I >= 8 THEN
PORTC.7 = 1
ELSE
PORTC.7 = 0
ENDIF



goto main


END

mister_e
- 18th May 2009, 17:21
I tried and tried but... :( you lost me in your explanations.

Now i have a input that when made gets the signal and set a alarm setpoint one LED lower than the current signal === First problem with the signal variang fast it does not whant to select properly

Now what needs to happen is that as soon as the signal passes the setpoint again it needs to set a output basicly a high noise alarm, but my rele shutter if i add a timer it influence my VU meter

Ioannis
- 18th May 2009, 19:51
Now, if I understand what you try to say, is that, your noisy alarm has strong influence on your comparator? Like changing the setpoint?

Ioannis

Acetronics2
- 19th May 2009, 10:35
Hi, Andre

If I understand it right ...

one led column (I-port C) is the meter, and the other ( j -portB) is the ref index ...

Now, you want to catch your ref level "in flight" ... ( Porta.2 turns to low )

1st problem...

time before you see level and you press the button ... level has changed.
Why not extract the MAXIMUM of the readings while button pressed ???

2nd problem...

time you keep the finger on the button, your ref level is changing ... ( k= i-1 in a continuous LOOP )
Your Button must act as a OneShot for K value ! ... or see Upper

Alain

Andre_Pretorius
- 20th May 2009, 16:17
thank you for everybody, i got the problem fixed by improving the rectifier sircuit after the op amp and before the PIC everything works good now

Thanks again for everybody's advice