PDA

View Full Version : Music Input



malc-c
- 20th June 2006, 18:40
Hi,

I'm developing a disco light rig and need some advice. I want to connect the device to the line out from a CD player (typically 1v RMS peak to peak) via a lowpass filter that is then fed through a peak filter (CCt can be supplied if required) to pin RA2 of a 16F628a PIC

As I already have switches on some PORT A so I only want to set AN2 (RA2) to analogue.

Now I did try and use the POT comamnd, but realised that this wouldn't work as there is no real means of charging acapacitor, so I looked at the ADCIN command, and this is where my lack of experience shows. Here is the top section of my code



PORTA = 0 ' declare port level BEFORE port direction = safe power-on
CMCON = 7 ' PortA Digital inputs
DEFINE ADC_BITS 8
CCP1CON = 0 ' PWM off
VRCON = 0 ' Voltage reference disabled
OPTION_REG.7 = 0
ADCIN 2, M


As I was using switches on port A I had used CMCON = 7 to make all ports didgital, so how do I change this so that RA2 is analogue and the rest digital. I also assume that I have the correct syntax ADCIN 2, M to put the resulting value (0 - 255) into M? The idea then is to include a line that states if the value of M is above a threshold it will run to the step in the pattern, if its below it simply loops until M is above the threshold.

I welcome your comments

peterdeco1
- 20th June 2006, 19:19
Hi Malcolm. I did something similar a while back with a 12F675 and a portable radio. This program flashes several LED's with the beat of the music. Audio was taken from the audio feed to the volume control. The use of the ADC command automatically converts the port to analog.

ANSEL = 0 'all inputs digital
CMCON = 7 'comparators off
DEFINE OSCCAL_1K 1 ' Set OSCCAL for 1K device to accurize osc
@ DEVICE MCLR_OFF, INTRC_OSC, WDT_ON, BOD_ON, PWRT_ON, PROTECT_ON
TRISIO = %11111111 ' all inputs for now
'high & low commands convert to outputs
X VAR BYTE 'adc variable

START:
ADCIN 0, X
IF X > 2 Then High GPIO.2 'TURN ON LED'S ON GPIO.2
IF X <=2 Then Low GPIO.2 'OFF LED'S
GOTO START

malc-c
- 20th June 2006, 20:18
Thanks for the reply,

Sounds good (sorry no pun intended), I'll have a play and see what I can do.

Cheers

Melanie
- 21st June 2006, 05:56
If and when you get ADCIN to work with a 16F628A, come back and tell us how you did it. That PIC hasn't got any ADC's...

malc-c
- 21st June 2006, 09:58
Sorry I dow to your superior knowledge.. so what's an analogue comparator input then.. will it not do the same thing... ??

Acetronics2
- 21st June 2006, 10:15
Hi, Malc

Some years ago, Elektor committed such a project with a 16F84 ... you could have a look to their input stage ...

16F628 is a "bigger" '84 ...no ???

Alain

PS : Project 000107 ... note everything Downloadable ...

malc-c
- 21st June 2006, 11:21
Thanks for that, but me been a tight ass brit object to having to pay a quid to obtain access to the article... especially when the HEX and ASM are free !!

I did come accross this project, which appears to use the filtered bass to trigger an NE555 to provide the logic pulse to trigger another NE555 which can run as an astable free runner or mono-stable triggered by the music.

http://sound.westhost.com/p62-f5.gif

http://sound.westhost.com/p62-f6.gif


The actual chase generator is a 4017 decade counter. ( full project details http://sound.westhost.com/project62b.htm )

I might just try this, however it seems a but of an overkill to use all those op-amps and an NE555 to provide the input into a PIC.... I'll keep googling and yahooing and see what turns up

Melanie
- 21st June 2006, 12:06
An Analogue Comparator allows you to trip your input pin at different voltage levels determined by an internal or external reference. So, if you set your Reference voltage at say 500mV, you can trip the Comparators Output on or off at 500mV rather than the usual trip level for a Digital I/O pin.

By sweeping the Comparators Reference Voltage, you can then use its input as a cheapo ADC. However, the internal Reference in the 16F628 only has two scales of 16 steps, and allowing for a settling time would not be very good for Audio input sampling.

So, in reply to your query, an Analogue COMPARATOR does what it says... it COMPARES your input against a Reference. Whilst an Analogue to Digital CONVERTOR (ADC) will give you a snap-shot of your current Analogue input in Digital form. The two are NOT the same.

The 16F628 has TWO COMPARATORS on-board and NO ADC's. ADCIN only functions with ADC's which is why it's named ADCIN (that what I love about microprocessors, they name everything so obviously!).

Acetronics2
- 21st June 2006, 12:30
but me been a tight ass brit object to having to pay a quid to obtain access to the article... especially when the HEX and ASM are free !!



Let's see how much you hope to save ( let's do the whole count for the project ) ... makes me laugh !!!

mmmh, by the way ... have a look to Freescale MC 3340 P datasheet. An old Elektor ( once more, ... !!! ) summer issue show a really nice application

You'll be more than happy : datasheet is free ...

you fast draw, mmmmh ???

Alain

PS : 5or 8 £ for a pre-programmed basic PIC ( 675,628,84 ...) ... you're joking, I hope !!!

malc-c
- 21st June 2006, 14:15
Melanie,

Thanks for the explanation. I understand where my confusion came from now !

malc-c
- 21st June 2006, 14:24
Ok I've looked at the PDF (http://www.ee.washington.edu/stores/DataSheets/linear/mc3340.pdf) for that device, but how does an electronic volume control fit in with my bass extraction / filter thingy ???



PS : 5or 8 £ for a pre-programmed basic PIC ( 675,628,84 ...) ... you're joking, I hope !!!

Whoops - thanks for pointing out the typo... should be £5 like the rest.. now corrected.

And before you ask, that just covers the cost of the PIC and postage to me, then the cost of the post, packing and paypal charges when sending it out again !

Acetronics2
- 21st June 2006, 15:14
[QUOTE=malc-c]Ok I've looked at the PDF (http://www.ee.washington.edu/stores/DataSheets/linear/mc3340.pdf) for that device, but how does an electronic volume control fit in with my bass extraction / filter thingy ???

I just thought you had understood the presence of D1,D2,Q1,Q2 ... around U1A ...

as for good films : do not make presume the end too early ...

Alain

PS: You buy your PICS from Radiospares ??? ... Who said Cr ...??? Ohhhhh.
RePS: Elektor is the same price ...

Pic_User
- 21st June 2006, 15:19
Hi Malcolm,

A pre-disco name for "disco light" could be "color organ".

I made a color organ in the early 1970's of the last century.

It was great before the word kewl, or way cool, or even cool was used to describe "neat" things.

There seems to be a lot of information on line about color organs. A search may turn up a lot of circuit ideas and schematics.

For instance:
http://www.tinaja.com/glib/muse108.pdf
Describes a color organ as;

Your speaker level input
audio is somehow safety isolated and
then lowpass, bandpass, or highpass
filtered into (usually) three or more
channels. Each channel’s output is
then converted into some dc control
voltage. That dc control voltage then
modulates a "power amplifier" of
some sort. Which in turn relates the
amount of audio energy in the band
to the brightness of one or more
colored lights. For instance, the lows
might be red, the mids green, and the
highs blue. Or whatever"
Now you may be interested, in a single channel "Bass" (lowpass), but the principle should be the same.

PicBASIC should truly turn the simplistic color organ into a true disco light. But be careful to isolate your circuit from the power lines (mains). It is also good practice to isolate the circuit from the input device as well.

This is a fun project and we hope you post where your journey takes you so we can all learn with you.

-Adam-

Acetronics2
- 21st June 2006, 15:57
Hi,

May I point out this little circuit from the far east...

http://www.selectronic.fr/includes_selectronic/pdf/Holtek/HT2040A.pdf

... really ... cool !!!

Alain

malc-c
- 21st June 2006, 16:02
I made a color organ in the early 1970's of the last century.



God you make me feel old, I think the last century bit made me reach for my zimmerframe and I'm only mid 40's :)

Thanks for the lead, I'll google colour (or color) organ and see what I get.

No worries on the mains isolation. I use solid state relays that have built in opto isolation. Its a lot safer and easier than messing about with triacs and thryistors like the good old days... I built my first sound to light in '77 consisting of a three way passive crossover, three mains to 6v ac transformers (using the secondry as the primary on the audio) and three 206 thyristors... never really thought about the amp become live at mains potential !!!!

I'll keep you guys posted of any development I get, and hopefully Melanie may let me post the final project and schematic in the respective forums when its completed.

malc-c
- 21st June 2006, 16:09
Hi,

May I point out this little circuit from the far east...

http://www.selectronic.fr/includes_selectronic/pdf/Holtek/HT2040A.pdf

... really ... cool !!!

Alain

Thats wicked ! .... nice find

Pic_User
- 21st June 2006, 17:00
God you make me feel old, I think the last century bit made me reach for my zimmerframe and I'm only mid 40's

Ha, I had to Google "zimmerframe", we have them in this country, just different names... Made me smile...
http://www.thefreedictionary.com/Zimmer+frame


Alain
What a great find. The HT2040A IS a disco light. (they might think it is for Christmas lights, but we know better.) All in one part.


Side Notes:
One of the interesting things, about the artistic mode of visual music, is sloppier is better!

Normally, the goal is to sharpen filters. Make the "cut-off", at band edges, as sharp as possible, without causing "ringing" or other ill effects. However, with "music changed into light", it is better to have overlapping filters, to cause a blending of the lights. Much more interesting patterns, come about, when the band edges overlap.

Very simple L-C or even R-C passive filters are not only adequate, but even desirable

"A Project Too Far."
What might be interesting:
Have mirrors mounted on some type of PIC controllable devices. This could be stepper motors, syncros, voice coils, linear motors etc..
The front panel could be some type of translucent, diffusing rear projection screen. Maybe, something as simple as a "suspended ceiling" florescent light diffusion lens.
The light would be modulated as in a standard colour (color) organ.
But, the mechanical device would move the modulated colours around by volume (loudness). Who knows, maybe higher on the panel could represent louder musical notes.
It seems like this might add a third dimension to the mix. ?

-Adam-

Acetronics2
- 23rd June 2006, 12:29
Hi,Malc

I've another lightshow including a Basic stamp interpreter chip ( In easy words : PicBasic compatible ... but some timings, may be, are to be corrected )

From Electronique Pratique june 2000 issue ... Here, all is done by soft ( no "miracle" filter to cut and paste ... )

Alain

malc-c
- 23rd June 2006, 12:39
Thanks

I do get the feeling that I'm re-inventing the wheel... but then again, its all good learning experience ;)

Acetronics2
- 23rd June 2006, 12:43
Thanks

I do get the feeling that I'm re-inventing the wheel... )

You took some time to understand it ... but youth must pass !!!

Alain

malc-c
- 24th June 2006, 16:50
Now the fact that we all went out to a party last night and I'm still getting over a hangover might have something to do with this...

Whilst this might be re-inventing the wheel, I'm still having fun at trying to get this working, but I'm having problems... I've managed (with some help from guys on an electronics forum) to come up with a low pass filter cct that goes high (5v) in time with the beat. The idea is to feed this pulse into the PIC so that whilst the pin is high the code continues to run through the sequence, and when its low it stops at what ever position it is in the sequence. Here is the modified code, which compiles but when I tie RA2 high the pattern doesn't advance at all.



;************ set up PIC *****************
PORTA = 0 ' declare port level BEFORE port direction = safe power-on
CMCON = 7 ' PortA Digital inputs
CCP1CON = 0 ' PWM off
VRCON = 0 ' Voltage reference disabled
OPTION_REG.7 = 0


TRISA=%11100111 'set PORTA as all input apart from A3 & A4
TRISB=%00000000 'set PORTB as all output

@RC_OSC_NOCLKOUT
@WDT_ON
@PWRT_ON
@MCLR_OFF
@BOD_ON
@LVP_OFF
@CPD_OFF
@PROTECT_OFF

;************* set up pattern data **********

Patt1 DATA 16,1,2,4,8,16,32,64,128,128,64,32,16,8,4,2,1
Patt2 DATA 8,129,66,36,24,24,36,66,129
Patt3 DATA 16,1,3,2,6,4,12,8,24,16,48,32,96,64,192,128,0
Patt4 DATA 16,1,128,2,64,4,32,8,16,8,32,4,64,2,128,1,0
Patt5 DATA 12,24,60,126,255,231,195,129,0,129,195,231,255
Patt6 DATA 13,1,2,4,8,17,34,68,136,16,32,64,128,0
Patt7 DATA 8,128,64,32,16,8,4,2,1

;************* set up varibles ************

i var byte ;used for for next loops
M var byte
D var byte ;used to store the result of the pot on port A1
scale var byte ;used in the POT command
Scale = 254 ;used to set range
SW1 var PORTA.6 ;up switch
SW2 var PORTA.0 ;down switch
mus var PORTA.2 ;pin for music input
SWcount var byte ;used as a place holder for patterns selwction
swcount=1 ;set place holder to default to pattern 1
steps VAR BYTE ;used to store the number of steps in the pattern sequence
counts VAR BYTE ;used in the FOR NEXT loop to run through the sequence

;************* main program ****************

Main:
Pot PORTA.1,scale,D ;used to read value from 10k pot
if sw1=0 then swcount=swcount+1 ;check to see if up button pressed, if so add 1 to SWcount
if sw2=0 then swcount=swcount-1 ;check to see if down button pressed if so delete 1 to SWcount
pause 60 ;debounce delay
If swcount>7 then swcount=7 ;error trap for exceeding max patterns
If SWcount<0 then swcount=0 ;error trap for exceeding min patterns
IF swcount = 0 then all:


TRISB = 0
gosub sel1 ;go to subroutine to select pattern
counts = 1 ;set position marker
gosub sel2 ;go to subroutine to advance through sequence
PAUSE D ;pause period set by varible D
If mus = 1 then counts = counts + 1 ;check to see if music trigger is present and if so advance position by 1
If counts > steps then counts =1 ;check to see if at the end of sequence
goto main: ;go back to the main program and run again

;************* Subroutines *****************
Sel1:
if swcount = 1 then read Patt1, steps
if swcount = 2 then read Patt2, steps
If swcount = 3 then read Patt3, steps
if swcount = 4 then read Patt4, steps
if swcount = 5 then read Patt5, steps
If swcount = 6 then read Patt6, steps
If swcount = 7 then Read patt7, steps
return

Sel2:
if swcount = 1 then READ (Patt1+counts), PORTB
if swcount = 2 then READ (Patt2+counts), PORTB
if swcount = 3 then READ (Patt3+counts), PORTB
if swcount = 4 then READ (Patt4+counts), PORTB
if swcount = 5 then READ (Patt5+counts), PORTB
if swcount = 6 then READ (Patt6+counts), PORTB
if swcount = 7 then READ (Patt7+counts), PORTB
RETURN


I also tried modifying the previous arrangement using the for next loop



TRISB = 0
gosub sel1 ;go to subroutine to select pattern
FOR counts = 1 TO steps ;advance to through the entries
gosub sel2 ;go to subroutine to advance through sequence
PAUSE D ;pause period set by varible D
if mus = 1 then
NEXT counts ;advance through loop to next position
end if
goto main: ;go back to the main program and run again


My logic was that if mus (ie pin RA2) is high then continue the for next loop, but no matter how I phrase the section I get syntax errors (nested next without matching for, etc)

Anyone have any ideas ?

malc-c
- 24th June 2006, 21:08
well several cups of coffee later I have something that works.. to a fashion. The only thing with the code at the moment is that it seems to randomly revert back to the default pattern 1, so something is causing SWcount to loose / reset. I'm assuming that the audio filter is causing interfearance, even though the PIN on the PIC is tied low via a 10K resistor.

Anyway, here is the main section of the code:


;************* main program ****************
counts = 0

Main:
Pot PORTA.1,scale,D ;used to read value from 10k pot
if sw1=0 then swcount=swcount+1 ;check to see if up button pressed, if so add 1 to SWcount
if sw2=0 then goto music ;check to see if down button pressed and if so go to music
pause 60 ;debounce delay
If swcount>7 then swcount=1 ;error trap for exceeding max patterns

gosub sel1 ;go to subroutine to select pattern
FOR counts = 1 TO steps ;advance to through the entries
gosub sel2 ;go to subroutine to advance through sequence
PAUSE D ;pause period set by varible D
NEXT counts ;advance through loop to next position
goto main: ;go back to the main program and run again


music:
Pot PORTA.1,scale,D ;used to read value from 10k pot
if sw1=0 then swcount=swcount+1 ;cycles through the patterns by adding 1 to SWcount
if sw2=0 then goto main ;check to see if down button pressed and if so go to main
pause 60 ;debounce delay
If swcount>7 then swcount=1 ;error trap for exceeding max patterns



gosub sel1
If mus = 1 then counts = counts + 1 ;if bass or beat present move to the next step in pattern
gosub sel2 ;go to subroutine to display pattern in current step
PAUSE D ;pause period set by varible D
If counts = steps then counts = 0 ;if counts then reset counts to 1
goto music: ;go back to the main program and run again

;************* Subroutines *****************
Sel1:
if swcount = 1 then read Patt1, steps
if swcount = 2 then read Patt2, steps
If swcount = 3 then read Patt3, steps
if swcount = 4 then read Patt4, steps
if swcount = 5 then read Patt5, steps
If swcount = 6 then read Patt6, steps
If swcount = 7 then Read patt7, steps
return

Sel2:
if swcount = 1 then READ (Patt1+counts), PORTB
if swcount = 2 then READ (Patt2+counts), PORTB
if swcount = 3 then READ (Patt3+counts), PORTB
if swcount = 4 then READ (Patt4+counts), PORTB
if swcount = 5 then READ (Patt5+counts), PORTB
if swcount = 6 then READ (Patt6+counts), PORTB
if swcount = 7 then READ (Patt7+counts), PORTB
RETURN