Shop OBEX P1 Docs P2 Docs Learn Events
A/D conversion — Parallax Forums

A/D conversion

byocbyoc Posts: 17
edited 2013-05-23 14:14 in BASIC Stamp
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?

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2013-05-23 13:06
    Yep. Wavelength x Frequency = SpeedOfSound (or Speed of Light ... essentially Speed of Wave). For sound in air, this is temperature sensitive, but is approximately 343.2 meters per second in dry air at 20C.
  • byocbyoc Posts: 17
    edited 2013-05-23 13:28
    If wave length is the same as frequency in this case, then I don't think this is a very accurate means of ADC. At least there is consistency in so much as plucking on one string produces the same number each time, but there doesn't seem to be any rhyme or reason as to how the number it produces relates to the actual note being played regardless of octave. The wavelength number jumps all over the place as you go up the scale.

    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?
  • byocbyoc Posts: 17
    edited 2013-05-23 13:31
    Oh. Wait. You said, "Yep" as in yep, my assumption was incorrect? I guess I'd better figure out how to convert wavelength to frequency.
  • Mike GreenMike Green Posts: 23,101
    edited 2013-05-23 14:14
    Read my posting again. (Sigh ... I do try to give answers while trying to make people think). Do a Google search for "Wikipedia Speed of Sound" (see the link in my post).
Sign In or Register to comment.