Is there anyway to generate a ramp input from an Arduino Uno? A visual depiction of the pulse I am looking for is as follows: Ramp Input

With other microcontrollers, I was able to use their in-built DACs, however I am aware that the Arduino UNO doesn't have any? Is there a way using PWM or analogWrite to output these type of pulses? I'm new to Arduino programming, so I'm a bit unsure. However my next guess would be to use an R-2R ladder to output this type of pulse?

  • 1
    A resistor ladder is a good option. For example 4 pins for 16 steps. What frequency is the signal and how steep and how accurate should the ramp be? The Arduino Uno does not have a analog output. The function analogWrite is PWM (it should be called pwmWrite). – Jot Mar 23 '19 at 5:59
  • Yea, I was thinking on using an R2R ladder. The rise time should be really fast (around 150 microseconds), and then 50 microseconds of constant voltage. After that, it could drop to 0 instantly. Yea I was fearing that I might need to use an R2R ladder – Muhammad Mar 23 '19 at 6:01
  • The function digitalWrite on a arduino uno is 5 microseconds. It can be (a lot) faster when writing directly to output registers of the microcontroller. Together with the function delayMicroseconds and turning off interrupts, then it is possible. The default pwm frequency is 500Hz when using the arduino libraries, that is too slow. – Jot Mar 23 '19 at 6:07
  • @Jot ahhh, I see. I will try giving it a go. I'm actually generating this pulse to trigger muscles. Okay but instead of directly outputting to the registers, won't digitalWrite alone, also be able to accomplish this rise time? – Muhammad Mar 23 '19 at 6:12
  • No, that is very fast and there is no way to slow it down. The 5 microseconds is used to call the function, check if the pin is valid and find the register and bit for that pin: github.com/arduino/ArduinoCore-avr/blob/master/cores/arduino/… Would a pullup resistor and capacitor and transistor be possible? The resistor and capacitor to rise slow, and the transistor to fall fast. – Jot Mar 23 '19 at 6:16

A RC filter will create a slow slewrate.


simulate this circuit – Schematic created using CircuitLab

The circuit creates this signal: enter image description here

A slow rising signal and a fast falling signal can be created with an extra transistor (the signal will be inverted).


simulate this circuit

For a linear rising and falling edge, a resistor network with a few digital pins is a simple solution. I think it can be created with an opamp circuit as well, but there are also special chips called "slew rate limiter".

  • This is so incredibly helpful! Thank you so much! – Muhammad Mar 24 '19 at 22:02

By "ramp", it seems that you mean a square wave with sloping rather than vertical edges between + and -. Can you clarify the question further: do the sloping parts need to be linear?

Direct synthesis of the waveform could be done using the digital output ports and an R2R ladder, as suggested in the comments. Each PWM timer output of the AVR can control output of 2 digital pins and definitely with a timing precision better than 1 microsecond. If high voltage resolution is needed, this method may not be able to produce the result you want.

Other possible solutions:

  • The waveform as plotted in the original post looks like a truncated sine wave. Such a waveform could be made by clipping a sine wave with an operational amplifier. For the sine wave connect the Arduino to a DDS module such as AD9850/1.

  • Use an external digital-to-analog converter, e.g. MCP48x2

  • Use an Arduino Zero or other 32-bit microcontroller (e.g. ARM STM32). These microcontrollers have a true analog output pin, but it's not bipolar.

  • Yes, it could be any. A sine wave or a sloping square wave. I will update the question. I will take a look at all the solutions that you suggested. Thank you for the help! – Muhammad Mar 23 '19 at 21:16

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.