# Generate a ramp input with an Arduino Uno

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: 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?

• 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

## 2 Answers

A RC filter will create a slow slewrate. simulate this circuit – Schematic created using CircuitLab

The circuit creates this signal: 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
{"ft_lang_label":"__label__en","ft_lang_prob":0.95208925,"math_prob":0.6311644,"size":1486,"snap":"2021-04-2021-17","text_gpt3_token_len":326,"char_repetition_ratio":0.09379217,"word_repetition_ratio":0.0,"special_character_ratio":0.21467026,"punctuation_ratio":0.086666666,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9552787,"pos_list":[0,1,2,3,4,5,6,7,8],"im_url_duplicate_count":[null,3,null,3,null,3,null,3,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-04-17T02:48:10Z\",\"WARC-Record-ID\":\"<urn:uuid:afc3c9db-c2bd-4942-a172-974c8c7dca6c>\",\"Content-Length\":\"181124\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:1b4479ea-35be-4f40-8acd-e1a076f43cff>\",\"WARC-Concurrent-To\":\"<urn:uuid:c079ff72-261d-4d64-880f-e029afb221c9>\",\"WARC-IP-Address\":\"151.101.129.69\",\"WARC-Target-URI\":\"https://arduino.stackexchange.com/questions/62816/generate-a-ramp-input-with-an-arduino-uno\",\"WARC-Payload-Digest\":\"sha1:LLEQBZ7YDSVJYKLHQDETOLWFOBUGR56L\",\"WARC-Block-Digest\":\"sha1:FFO5A4N7WI6KT6L66FX5EHFFBDFC57PN\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-17/CC-MAIN-2021-17_segments_1618038098638.52_warc_CC-MAIN-20210417011815-20210417041815-00391.warc.gz\"}"}