5 years, 6 months ago.

adc of a sine wave of 50 Hz from signal generator

Hi I have been trying to do ADC on a sine wave of 50 Hz from a signal generator for LPC 1768. the code used is given below. Unfortunately the adc doesnt give a sine when the values are copied to Matlab and plotted. Please let me know where the problem is. All i want is a sine signal of 50 Hz sampled at a rate 3200 so as to get 64 samples in one cycle.

  1. define SAMPLE_RATE 3200
  1. include "mbed.h"
  2. include "adc.h"

int main() { int i;

printf("Requested max sample rate is %u, actual max sample rate is %u.\n", SAMPLE_RATE, adc.actual_sample_rate()); while (1) {

Set up ADC on pin 20 adc.setup(p20,1); Set up ADC on pin 19 adc.setup(p19,1); wait(1/3200);

Measure pin 20 adc.select(p20); Start ADC conversion adc.start(); Wait for it to complete while(!adc.done(p20)); printf(" %04f ", adc.read(p20)*(3.3/4096)); }

can u please tell me how u calculated the samplw rate i am lil confused (1/50)=0.02,and 64/0.02=3200.. how exactly the concept is i have a signal of 1khz and what should be the value i need to fix and hw.....

posted by Ashok K 16 May 2014
Comment on this question

1 Answer

5 years, 6 months ago.

Please use <<code>> and <</code>> tags around posted code to keep it readable. Where does your adc.h come from, what lib are you using? I think there are several issues with your code. The wait(1/3200) will end up as wait(0) because you use integers. Try wait(1.0/3200.0) or something like that. Also note that a printf() in your loop will take a lot of time and so it ruins your timing. Same applies to the ADC conversion itself. Accurate timing takes a timer that calls the ADC at the correct moment.

Thank you Wim. the printf statement was used on;y for a reconformation that the adc is happening properly. The algorithm following that failed to give me the desired output. Hence, i was forced to check if it had to do something with the ADC. I used two header files "mbed.h" and "adc.h". how are sample rate and the actual sample rate related to the clock divide value (which cn b 1,2,4 or 8).

posted by sneha jay 13 May 2014

hey d same thing even i was trying to do.. pls check and understand api how its takin the frequency values (i,e setting of clock) and try to collect the value in an array and then display the below link may help u ... https://mbed.org/users/gno/code/ADC_fast_sample_and_send/file/55ea5a2921b2/main.cpp

posted by Ashok K 15 May 2014