The official mbed C/C++ SDK provides the software platform and libraries to build your applications.

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

Issue: Multiple AnalogIn/AnalogOut needs continuous initialization on Nucleo F334R8

I want to sample multiple AIn channels and simultaneously output the values to two AOut channels.

The following code works with one ain/aout combination, but if I add the construction of the second AnalogIn/AnalogOut objects, the AOut stops working:

  1. include "mbed.h" int main() { Combination 1 AnalogOut aout1(PA_5); AnalogIn ain1(PC_0); Combination 2 AnalogOut aout2(PA_6); AnalogIn ain2(PA_7);

while(1) { aout1=ain1; aout2=ain2; wait_ms(1); } }

Moving the constructions into the loop partially resolves the problem, but there are artefacts in the output, maybe due to the continuous re-initialization of the DAC/ADC:

  1. include "mbed.h"

int main() {

while(1) { Combination 1 AnalogOut aout1(PA_5); AnalogIn ain1(PC_0);

aout1=ain1;

Combination 2 AnalogOut aout2(PA_6); AnalogIn ain2(PA_7);

aout2=ain2;

wait_ms(1); } }

Any help is appreciated.

6 comments:

28 Apr 2015

not working (one aout is at 0V, no matter what the corresponding ain has):

int main() {

    AnalogOut aout1(PA_5);
    AnalogIn ain1(PC_0);

    AnalogOut aout2(PA_6);
    AnalogIn ain2(PA_7);

    while(1) {
        aout1=ain1;
        aout2=ain2;
        wait_ms(1); 

    }
}

working (with artefacts):

int main() {

    while(1) {

        AnalogOut aout1(PA_5);
        AnalogIn ain1(PC_0);

        aout1=ain1;

        AnalogOut aout2(PA_6);
        AnalogIn ain2(PA_7);

        aout2=ain2;

        wait_ms(1); 

    }
}
28 Apr 2015

You need <<code>> and <</code>> around your code (on seperate lines) to have it readable. Best place to have it noticed is on the mbed github though: https://github.com/mbedmicro/mbed

29 Apr 2015

Did you try taking the definitions out of the While loop? Keep the while loop empty with only the "wait_ms(1)" inside.

29 Apr 2015

Also I suggest you use the read/write APIs Meaning

aout1.write_u16(ain1.read_u16());

instead of just using the equal operators.

Let me know how that works for you!

29 Apr 2015

Hi Mustafa,

when placing the definitions out of the while loop it only works, if I comment out one of the ain/aout combinations, e.g.:

int main() {

    // Combination 1
    AnalogOut aout1(PA_5);
    AnalogIn ain1(PC_0);

    // Combination 2
//    AnalogOut aout2(PA_6);
//    AnalogIn ain2(PC_1);

    while(1) {

        aout1.write_u16(ain1.read_u16());

//        aout2.write_u16(ain2.read_u16());

        wait_ms(1); 
    }
}

As soon as both are uncommented, I get 0V on PA_5, no matter what is on PC_0, but PC_1 -> PA_6 is still working.

29 Apr 2015

Hello.

I have noticed a similar error in other stm-based platforms while using the mbed library (nucleo411RE and also Discovery 429, 407).

Cheers