4

How can I generate this pulse with an Arduino Micro?

Is it necessary an external component?

enter image description here

rebatoma
5593 gold badges12 silver badges22 bronze badges
asked May 26, 2016 at 17:54
3
  • how much current will you be drawing / what will it be connected to? Commented May 26, 2016 at 18:00
  • is only for signal generator experiment Commented May 26, 2016 at 18:04
  • 1
    Looks like something for a 2-bit DA converter. en.wikipedia.org/wiki/Digital-to-analog_converter. A resistor ladder is the simplest solution; en.wikipedia.org/wiki/Resistor_ladder Commented May 26, 2016 at 18:22

2 Answers 2

6

Take two 10K or so resistors:

 +5V
 |
 10K
 | 
Pin2-+---> output
 |
 10K
 |
 GND

The following program does the trick:

const uint8_t kPin = 2;
const uint32_t kDelay = 10; // 100Hz
void setup() {
}
void loop() {
 pinMode(kPin, OUTPUT);
 digitalWrite(kPin, HIGH);
 delay(kDelay);
 pinMode(kPin, INPUT);
 delay(kDelay);
 pinMode(kPin, OUTPUT);
 digitalWrite(kPin, LOW);
 delay(kDelay);
 pinMode(kPin, INPUT);
 delay(kDelay);
}

When Pin2 (or any other pin for that matter) is set as INPUT, it is in high-impedance state (theoretically), so effectively you have a voltage divider giving you 1/2 Vcc. When it is set as OUTPUT, and now assuming that its output impedance is << 10KΩ, it drives the output to either +5V or 0V.

enter image description here

answered May 26, 2016 at 19:18
1
  • Obviously, this solution does not generalize to multiple levels; folllow @gerben's solution with a resitor ladder for that. However, I like using tri-state pins in creative ways. Charlieplexing is the canonical such example. Commented May 27, 2016 at 3:26
5

enter image description here

If both inputs are 0V, the output will be 0V.

If both inputs are 5V, the output will be 5V.

If one input is 0V and one 5V the output will be 2.5V.

However, if the device attached to the output doesn't have a high input impedance, the voltage will drop some. You could add an opamp to prevent this.

I think you can generate the 2 pins outputs using one of the timers in phase correct pwm mode. Freeing up the cpu and giving a very clean output signal, as using software "pwm" could be slightly of due to interrupts occuring.

answered May 26, 2016 at 18:46
2
  • ha! mine uses only one pin :) What did you use to draw the circuit? Commented May 26, 2016 at 19:19
  • @JayEye cool solution. Didn't think about tri-state. I used kicad to draw the schematic. Commented May 27, 2016 at 12:36

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.