-1
\$\begingroup\$

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).

\$\endgroup\$
  • \$\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 Oct 29 '13 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 Oct 29 '13 at 19:31
  • \$\begingroup\$ Do you have measurements to compare? Is the code the same? \$\endgroup\$ – Spoon Oct 30 '13 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 Oct 31 '13 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 Oct 31 '13 at 2:51
2
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ I don't want to use multiple pins. \$\endgroup\$ – Peanut Oct 29 '13 at 22:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.