I have an application where I need to use one pin as a digital output and analog input. I switch between input and output at a "high" frequency (>1 kHz) and it takes to much time to disable and enable the ADC-Channel all the time. When the ADC-Channel is enabled, it's not possible to use the pin as output pin and set it ti low or high. The voltage level will be at (Vgnd - Vcc)/2.
This works with the AVR Arduino boards (like the Arduino Uno) but not with the ARM version (like the Arduino due).
-
\$\begingroup\$ Can you post a link to an application example of this please? I'd like to see how this is implimented. My first thoughts are the Arm is running faster and so would need longer in clock cycles/instructions before the ADC settles. The same would apply to the output being on/off. This depends on the external components (R/C network) and how much pull up pull down the pin is capable of. \$\endgroup\$Spoon– Spoon2013年10月29日 13:34:14 +00:00Commented Oct 29, 2013 at 13:34
-
\$\begingroup\$ The ADC itself works. But if you measure the voltage of the output-pin it will always be at (Vgnd - Vcc)/2. The only way I can get it to work is to disable the ADC channel and then enable it again if I want to measure. But this is does not work fast enough. \$\endgroup\$Peanut– Peanut2013年10月29日 19:31:18 +00:00Commented Oct 29, 2013 at 19:31
-
\$\begingroup\$ Do you have measurements to compare? Is the code the same? \$\endgroup\$Spoon– Spoon2013年10月30日 08:01:26 +00:00Commented Oct 30, 2013 at 8:01
-
\$\begingroup\$ On other microcontrollers (STM32 series), you can flip between multiple functions on a GPIO by setting the IO type (in this case, switching between analog input and digital output) without disabling the peripheral. So, in the case of the STM32, you could leave the ADC enabled and configured and just change the mux setting for the IO. Check your datasheet in the GPIO section and see if you can just change the mux. \$\endgroup\$rjp– rjp2013年10月31日 02:49:52 +00:00Commented Oct 31, 2013 at 2:49
-
\$\begingroup\$ Also, this sounds like a capacitive touch application. You might check and see if Atmel has any app notes on how to perform this function. \$\endgroup\$rjp– rjp2013年10月31日 02:51:44 +00:00Commented Oct 31, 2013 at 2:51
1 Answer 1
Here is a work around: Tie two pins electrically together.
- One pin configured as digital tri-state output;
- One configured as analog input.
Then use the digital pin to set a HIGH or LOW level and switch the digital pin to INPUT (tri-state) while you read the analog voltage from the analog pin.
-
\$\begingroup\$ I don't want to use multiple pins. \$\endgroup\$Peanut– Peanut2013年10月29日 22:04:05 +00:00Commented Oct 29, 2013 at 22:04