In my design I've attached an analogue multiplexor to p18 of my mbed. The idea is to switch p18 between adc and dac during program operation. Is this actually possible?
To clarify: I want to change a pin between different types of I/O, without rebooting the mbed. More specifically I want to change p18 between DigitalIn DigitalOut, AnalogueIn and AnalogueOut. I know ideally I would use different pins, but that is impossible in this case. Can I do this, and if so, how?
In my design I've attached an analogue multiplexor to p18 of my mbed. The idea is to switch p18 between adc and dac during program operation. Is this actually possible?
To clarify: I want to change a pin between different types of I/O, without rebooting the mbed. More specifically I want to change p18 between DigitalIn DigitalOut, AnalogueIn and AnalogueOut. I know ideally I would use different pins, but that is impossible in this case. Can I do this, and if so, how?
Yes you can. You just need to use dynamic allocation of objects instead of static. An easy way to do it is to limit the scope of your class variables. E.g.:
float doADC()
{
AnalogIn ain(p18);
return ain;
}// ain is destroyed after leaving the function
void doDAC(float val)
{
AnalogOut aout(p18);
aout = val;
}// aout is destroyed after leaving the function
Yes you can. You just need to use dynamic allocation of objects instead of static. An easy way to do it is to limit the scope of your class variables. E.g.:
<<code>>
float doADC()
{
AnalogIn ain(p18);
return ain;
}// ain is destroyed after leaving the function
void doDAC(float val)
{
AnalogOut aout(p18);
aout = val;
}// aout is destroyed after leaving the function
<</code>>
what about run-time resetting of the pins? For example, having p18 go between ADC to it original state before it was initialized. How would I go about implementing that?
what about run-time resetting of the pins? For example, having p18 go between ADC to it original state before it was initialized. How would I go about implementing that?
Important Information for this Arm website
This site uses cookies to store information on your computer.
By continuing to use our site, you consent to our cookies.
If you are not happy with the use of these cookies, please review our
Cookie Policy
to learn how they can be disabled.
By disabling cookies, some features of the site will not work.
Access Warning
You do not have the correct permissions to perform this operation.
In my design I've attached an analogue multiplexor to p18 of my mbed. The idea is to switch p18 between adc and dac during program operation. Is this actually possible? To clarify: I want to change a pin between different types of I/O, without rebooting the mbed. More specifically I want to change p18 between DigitalIn DigitalOut, AnalogueIn and AnalogueOut. I know ideally I would use different pins, but that is impossible in this case. Can I do this, and if so, how?