Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years, 5 months ago.
Disco - F334C8 Analog read problem
Hi,
I want to read 8 analog values, but somewhy maximum what I can read is 4 inputs. I tried to print each analog input separately and it worked well but if I write them into the one code, the microcontroller does not respond or at least my Putty does not respond me. All the pins are supporting Analog Input. Thanks for help. Board type : DISCO-F334C8
Code :
include the mbed library with this snippet
#include "mbed.h"
AnalogIn Sen_1(PA_7);
AnalogIn Sen_2(PA_6);
AnalogIn Sen_3(PA_5);
AnalogIn Sen_4(PA_4);
AnalogIn Sen_5(PA_3);
AnalogIn Sen_6(PA_2);
AnalogIn Sen_7(PA_1);
AnalogIn Sen_8(PA_0);
Serial ser(USBTX, USBRX);
int main() {
float meas1;
float meas2;
float meas3;
float meas4;
float meas5;
float meas6;
float meas7;
float meas8;
ser.baud(115200);
printf("AnalogIn Test\n");
while(1) {
meas1 = Sen_1.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
meas2 = Sen_2.read();
meas3 = Sen_3.read();
meas4 = Sen_4.read();
meas5 = Sen_5.read();
meas6 = Sen_6.read();
meas7 = Sen_7.read();
meas8 = Sen_8.read();
meas1 = meas1 *3300; // Change the value to be in the 0 to 3300 range
meas2 = meas2 *3300;
meas3 = meas3 *3300;
meas4 = meas4 *3300;
meas5 = meas5 *3300;
meas6 = meas6 *3300;
meas7 = meas7 *3300;
meas8 = meas8 *3300;
printf("\nmeasure1 = %.0f mv\n\r", meas1);
wait(1);
printf("measure2 = %.0f mv\n\r", meas2);
wait(1);
printf("measure3 = %.0f mv\n\r", meas3);
wait(1);
printf("measure4 = %.0f mv\n\r", meas4);
wait(1);
printf("measure5 = %.0f mv\n\r", meas5);
wait(1);
printf("measure6 = %.0f mv\n\r", meas6);
wait(1);
printf("measure7 = %.0f mv\n\r", meas7);
wait(1);
printf("measure8 = %.0f mV\n\r", meas8);
wait(1);
}
}
1. Do all 8 channels work when done individually?
2. You wrote: "maximum what I can read is 4 inputs" Any combination of 4 works? In code constructed as in your example?
3. To where are USBTX. USBRX mapped? Is there a conflict with any of your analog inputs?
posted by Mike G 16 May 20161. Yes, all 8 channels work when done individually. 2. Any combination of 4 works and I used exactly the same construction method as in the example. 3. USBTX = PB_3 and USBRX = PB_4 so no conflict.
posted by Martin Pihooja 16 May 2016Perhaps there's a stack/RAM issue? Try looking at the number of floats you declare.
posted by Mike G 17 May 2016