I am trying to generate a sawtooth waveform from the GPIO, the frequency is high, 20 Khz. is pigpio library my best option?
-
2since gpio can be only in one of two states (high, low) ... how do you propose to generate a sawtooth? – Jaromanda X Feb 11 at 2:56
-
en.wikipedia.org/wiki/Resistor_ladder – jsotola Feb 11 at 7:54
-
I wasn't planning to do it directly. May be use the resistor ladder or a CoTS DAC, thanks. – engahmedtg Feb 11 at 13:37
-
Still interested in this? Would you consider adding an external op amp? What about external Resistor and Capacitor? {Here are the basics for the RC approach](electronics-tutorials.ws/rc/rc_3.html); let us know if you need help. – Seamus Feb 12 at 1:45
All the Raspberry's GPIO are binary, thus you can not directly generate a sawtooth wave.
With that being said, as the laconic @jsotola's comment suggested, you may use a resistor ladder to create a Digital to Analog circuit and connect it with your GPIO pins. You will then be able to use the GPIO pins like a counter to generate a staircase waveform, which may be sawtooth-like enough depending on you application, but this will demand an even higher GPIO write frequency with every additional GPIO pin you use.
-
Thanks, I think this is the best way to go. For time constraint, I am think to use a CoTs DAC. Do you recommend something? – engahmedtg Feb 11 at 13:41
-
No, sorry, but there are many arduino DAC boards that should be compatible with the raspberry. I would worry about meeting the frequency requirement (depends on the language and library you will use to control the GPIO). – GramThanos Feb 11 at 18:42