PDA

View Full Version : ADC sampling rate control for audio sampling


pokoRanger
07-25-07, 10:15 PM
Hello.

I will apologize if this is a ridiculously naive question, but I have a question regarding controlling the frequency for the A/D using ISOMAX, specifically for the MINPOD. Right now, I have a microphone ready with the voltage confined in the range of .5 to 3.0V, and I would like to do A/D conversion for this. I am hoping I can perform the sampling at around 30kHz (ideally 40kHz), and according to the spec, MINPOD is capable of do continuous AD at 1.2us, roughly at 833khz. I first used machine language, using
EVERY 113 CYCLES SCHEDULE-RUNS ADC_BUTTON
\ 44.1KHZ=5MHZ/#CYCLES, CYCLES=5MHZ/44.1KHZ~=113CYCLES

I created a machine ADC_BUTTON which will start the ADC when a button is pressed. But with this code, the machine freezes up. I understand that this may be extremely simple thing, but I would deeply appreciate it if I could receive some guidance. Thank you.

Sincerely,
Suzuki Takafumi

\ following is the code I've tried...It's my first crack at FORTH and ISOMAX,
\ as it may be a poorly written code

HEX
: ON?
1 =
IF
2DUP 3 + @ SWAP FFFF XOR AND OVER 3 + !
2DUP 2 + @ SWAP FFFF XOR AND OVER 2 + !
1+ @ AND 0=
ELSE
SWAP DROP DUP @ FCFE AND OVER ! @ FF7F AND 0= NOT
THEN
;

: OFF?
1 =
IF
2DUP 3 + @ SWAP FFFF XOR AND OVER 3 + !
2DUP 2 + @ SWAP FFFF XOR AND OVER 2 + !
1+ @ AND 0=
ELSE
SWAP DROP DUP @ FCFE AND OVER ! @ FF7F AND 0=
THEN
;

DECIMAL

( Single Ended Voltage = Vref x [Value Read/32760] )
: DECIVAL S>F VREF FSWAP 32760.0e F/ F* F. ;

LOOPINDEX CYCLE-COUNTER
DECIMAL 1 CYCLE-COUNTER END
1 CYCLE-COUNTER START

MACHINE ADC_BUTTON
ON-MACHINE ADC_BUTTON
APPEND-STATE ADC_OFF
APPEND-STATE ADC_ON

\ perform AD and output voltage when PA is grounded
\ or when button is pressed
IN-STATE
ADC_OFF
CONDITION
PA7 OFF?
CAUSES
ADC0 ANALOGIN S>F 32760.0e F/ 3.30e F* F.
THEN-STATE
ADC_ON
TO-HAPPEN

\ stop AD and output voltage when PA is no longer grounded,
\ ie button is released
IN-STATE ADC_ON
CONDITION
PA7 ON?
CAUSES
PA7 ON?
THEN-STATE
ADC_OFF
TO-HAPPEN


\ continue AD and output voltage when PA is still grounded
\ or when button is still pressed
IN-STATE ADC_ON
CONDITION
CYCLE-COUNTER COUNT
CAUSES
." "
ADC0 ANALOGIN S>F 32760.0e F/ 3.30e F* F.
THEN-STATE
ADC_ON
TO-HAPPEN

ADC_OFF SET-STATE ( INSTALL ADC_BUTTON
EVERY 113CYCLES SCHEDULE-RUNS ADC_BUTTON
\ 50000CYCLES = 10MS/PERIOD = 100HZ
\ 5000CYCLES = 1MS/PERIOD = 1KHZ
\
\ (freq you want)=5MHZ/(#CYCLES)
\ CYCLES=5MHZ/(frequency you want)
\
\ 44.1KHZ=5MHZ/#CYCLES, CYCLES=5MHZ/44.1KHZ~=113CYCLES

nmitech
07-27-07, 11:58 AM
1. There is no need to redefine ON? and OFF? words, if you are running IsoMax V0.82

2. If you want to use DECIVAL word, makesure to define VREF as i commented out below

3. When your program gets larger, makesure to use EEWORD and IN-EE

4. Try the modified code below



\ SCRUB

HEX

: ON?
1 =
IF
2DUP 3 + @ SWAP FFFF XOR AND OVER 3 + !
2DUP 2 + @ SWAP FFFF XOR AND OVER 2 + !
1+ @ AND 0=
ELSE
SWAP DROP DUP @ FCFE AND OVER ! @ FF7F AND 0= NOT
THEN
;
\ EEWORD

: OFF?
1 =
IF
2DUP 3 + @ SWAP FFFF XOR AND OVER 3 + !
2DUP 2 + @ SWAP FFFF XOR AND OVER 2 + !
1+ @ AND 0=
ELSE
SWAP DROP DUP @ FCFE AND OVER ! @ FF7F AND 0=
THEN
;
\ EEWORD


DECIMAL
\ 3.30E FCONSTANT VREF \ EEWROD
( Single Ended Voltage = Vref x [Value Read/32760] )
\ : DECIVAL S>F VREF FSWAP 32760.0e F/ F* F. ;
\ EEWORD


LOOPINDEX CYCLE-COUNTER
DECIMAL 1 CYCLE-COUNTER END
1 CYCLE-COUNTER START
\ EEWORD


MACHINE ADC_BUTTON \ EEWORD
ON-MACHINE ADC_BUTTON
APPEND-STATE ADC_OFF \ EEWORD
APPEND-STATE ADC_ON \ EEWORD

\ stop AD and output voltage when PA is no longer grounded,
\ ie button is released
IN-STATE ADC_OFF
CONDITION
PA7 ON?
CAUSES
\ do nothing
THEN-STATE
ADC_ON
TO-HAPPEN
\ IN-EE

\ perform AD and output voltage when PA is grounded
\ or when button is pressed
IN-STATE
ADC_ON
CONDITION
PA7 OFF?
CAUSES
ADC0 ANALOGIN S>F 32760.0e F/ 3.30e F* F.
THEN-STATE
ADC_ON
TO-HAPPEN
\ IN-EE

ADC_OFF SET-STATE ( INSTALL ADC_BUTTON
EVERY 113 CYCLES SCHEDULE-RUNS ADC_BUTTON

\ SAVE-RAM

pokoRanger
07-29-07, 06:50 PM
Thank you for the reply, nmitech,

But the problem I have is that even with the "EVERY 113 CYCLES SCHEDULE-RUNS ADC_BUTTON" code, apparently it does not show 44000 ADC sample results (maybe it displays 800 ADC results per second). Maybe I don't need to display it, but my hope this do the AD conversion of audio sound at a sufficient rate (maybe around 20khz) with Minpod and send the result to MATLAB using serial communication interface. To do this, I've been reading the display on the terminal output using MATLAB, so I thought I should display all the AD result on the terminal at the same rate as the sampling rate. Else, if the displaying is too fast for the terminal to capture, I would stop displaying the result and send the unconverted AD result to MATLAB someway. But again, if you could help me get the AD result in the sampling rate I wish, I would really appreciate it. Thank you in advance.

Sincerely,
Takafumi

RMDumse
07-30-07, 06:04 PM
my hope this do the AD conversion of audio sound at a sufficient rate (maybe around 20khz) with Minpod and send the result to MATLAB using serial communication interface.

Let's think about this a moment and see if it even possible. First we need to consider the serial channel. If we assume 115200 BAUD and using 1 start 8 data and 1 stop, it takes 10 bits to send a byte. So our maximum character rate is 11520 per second. If your readings were just 8 bits, a single character, you couldn't get half as many characters out the serial channel as you wished.

Plus, the PC's are usually hard pressed to capture data coming that fast. It's just the overhead of windows that tends to get in the way.

The 'Pod is fast enough to take A/D data, up to about 200K. But the problem is the speed of the serial. You could send it out faster via SPI or CAN. Or perhaps capture it in internal memory, or on a SPI based SD/MMC card.

Please advise if you have another idea, however, 20K on the serial port is not practical.