chipKIT® Development Platform

Inspired by Arduino™

A/D converter MAX32 board

Created Thu, 02 Feb 2012 18:27:23 +0000 by redarmy1


redarmy1

Thu, 02 Feb 2012 18:27:23 +0000

Hi

I am new to microcontrollers and programming and was wondering if I could have a nudge in the right direction. I am wanting to perform an 12bit 32Khz A/D conversion using Mpide for a microphone pre-amp I am trying to design a noise data logger. I currently have an analougue reading using the following code. const int analogInPin=57; //Analog Input in from pre amp int sensorValue=0; //Read analog value from pin void setup(){ Serial.begin(9600); //Serial communications at 9600bps } void loop() This reads the value from the pre-amp however seem to be getting random values. I have created a A/D program however I am struggling to both set it up and get it talking to my board my A/D program is a follows. #include<plib.h> int main() { EnableADC10(); const int analogInPin=22; //Analog Input in from pre amp int sensorValue=0; //Read analog value from pin

Serial.begin(9600); //Serial communications at 9600bps sensorValue=analogRead(analogInPin); //reads analog value Serial.println(sensorValue); //Print results to serial monitor printf("input value=%d\n",sensorValue); unsigned long int result; result = ReadADC10(22); delay(10000); // Delay of 10seconds before loop starts again } the EnableADC10 I am assuming is for a 10bit ADC however I would prefer to do a 12 bit but am struggling to get going. Any tips would be great as it is all new to me

Thanks


knChip

Tue, 28 Feb 2012 19:01:06 +0000

The following code works for me. It looks to be that the ADC is using 10bits . I got max value as 1023 when 3.3 volts and 0 for 0 vots. you may connect a pot between 3.3 and gnd and the centre pin to A0 input of max32. verify eveything is working properly for DC. Then go for signal measurement.

from the library code, it looks to me that the analogRead() is blocking one, means it does not return until the conversion is over.

/***************************************************** *Analog Read. * *******************************************************/ int val; unsigned long time, time2; void setup() { Serial.begin(9600); Serial.println("hello");

}

void loop() { int i; time = micros(); for(i=0; i <10 ;i++) // do 10 conversions for better time estimate val=analogRead(A0); time2 = micros(); Serial.print("\n time elapsed for 10 conversions: "); Serial.print((time2-time)); Serial.print("\n Analog value: "); Serial.print(val); delay(1000);

}