A/D conversion
byoc
Posts: 17
I'm trying to make some sort of analog to digital conversion so I can experiment with different sound FX on my guitar. I came across this thread http://forums.parallax.com/showthread.php/135941-Guitar-turner-circuit?highlight=guitar+tuner It looks like it uses an op amp to turn the guitar signal into an oscillating voltage that triggers the CD4017 decade counter, which in turn sends a high signal on the 2nd and 4th cycle every 5 cycles to the P0 to be interpreted by the PULSIN command and turned in to a wave length value. I swiped this little section of code from the guitar tuner that seems to handle the A/D conversion and added a debug to display the wave length every 1/4 second.
' {$STAMP BS2}
' {$PBASIC 2.5}
WaveLen VAR Word 'Wave Length BS2 Timing
Zero VAR Word
'Constants and equates
GPin CON 0 'Sound input
DPin CON 3 'Display Data Pin
LPin CON 2 'Display Latch Pin
CPin CON 1 'Clock Pin
'initialize
OUTPUT 4
OUTPUT 5
LOW LPin
SHIFTOUT DPin,CPin,MSBFIRST,[0\16]
PULSOUT LPin,3
'
DO
Main:
'sum 5 full cycles of wavelength
WaveLen=0
PULSIN GPin,1,WaveLen
'18181
IF WaveLen<18182 AND WaveLen>275 THEN
DO WHILE WaveLen>4595
WaveLen=WaveLen>>1
LOOP
ELSE
WaveLen=0
Zero=0
ENDIF
DEBUG ? WaveLen
PAUSE 250
LOOP
It seems to work. Not very well. I think the OpAmp needs more than 5V to trigger the CD4017. I've got to pluck the string really hard to get it to work. Anyhow... Now what I'd like to do is use the FREQOUT command to generate a note that matches the pitch of the input. However, the numbers I'm seeing in the DEBUG window do not match what I would expect the FREQOUT frequency to be to create the same pitch. Am I incorrect in assuming that wave lenth is the same a frequency?
' {$STAMP BS2}
' {$PBASIC 2.5}
WaveLen VAR Word 'Wave Length BS2 Timing
Zero VAR Word
'Constants and equates
GPin CON 0 'Sound input
DPin CON 3 'Display Data Pin
LPin CON 2 'Display Latch Pin
CPin CON 1 'Clock Pin
'initialize
OUTPUT 4
OUTPUT 5
LOW LPin
SHIFTOUT DPin,CPin,MSBFIRST,[0\16]
PULSOUT LPin,3
'
DO
Main:
'sum 5 full cycles of wavelength
WaveLen=0
PULSIN GPin,1,WaveLen
'18181
IF WaveLen<18182 AND WaveLen>275 THEN
DO WHILE WaveLen>4595
WaveLen=WaveLen>>1
LOOP
ELSE
WaveLen=0
Zero=0
ENDIF
DEBUG ? WaveLen
PAUSE 250
LOOP
It seems to work. Not very well. I think the OpAmp needs more than 5V to trigger the CD4017. I've got to pluck the string really hard to get it to work. Anyhow... Now what I'd like to do is use the FREQOUT command to generate a note that matches the pitch of the input. However, the numbers I'm seeing in the DEBUG window do not match what I would expect the FREQOUT frequency to be to create the same pitch. Am I incorrect in assuming that wave lenth is the same a frequency?
Comments
Any ideas as to whether this project is verified? Any potential flaws you can see that could use some tweaking? I happened to have a few CD4017 on hand so I figured I'd give it a shot. Do you have a link to a good ADC tutorial?