Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Sawtooth generation internal to the PIC microcontroller

Status
Not open for further replies.

dazed2

New Member
Hi

I want to generate sawtooth wave of amplitude 0.5v - 3v with frequency of 50khz.

I am not using DAC , I need to use this as reference signal to compare with the error signal (which is DC voltage , which I will converting in digital using ADC)

I am using Explorer 16 board with PICFJ128GA010.

Your help will be appreciated. Thank you.
 
I would place a pull up resistor and a pull down capacitor onto the PIC I/O pin you plan to use. Then I would drive the I/O pin in "open drain" fashion by writing a 0 to the pin's port latch bit, then toggling the pin's TRIS bit instead at a rate of 20uS.
 
Last edited:
OP said:
[I want to do] Sawtooth generation internal to the PIC microcontroller

You can't do such things internal to the PIC alone unless it has the hardware for doing this. PICs are digital/binary devices, and waveform generation is an analog/variable thing. So, if you were hoping to be able to do it with just pure software... Nope, sorry, not guna happen. Now, if you are talking about using a PIC and external analog support parts to synthesize a waveform... then you can keep reading.

Jon said:
I would place a pull up resistor and a pull down capacitor onto the PIC I/O pin you plan to use. Then I would drive the I/O pin in "open drain" fashion by writing a 0 to the pin's port latch bit, then toggling the pin's TRIS bit instead at a rate of 20uS.

This could probably work, there are just some minor issues.

(1) Discharging a charged capacitor through PIC port pins without a resistor *MAY* be able to exceed I/O max peek current.
(2) The RC time constant and parts would have to be calculated/chosen very carefully.
(3) The result would not be a digitally synthesized ramp/sawtooth wave form, it would be created in analog.
(4) You really couldn't change the wave in any way if it was done as above. It would be immutable.

Again, minor issues. None of the above are necessarily show stoppers, depending on what exactly it is the OP is doing and needs.


My two cents
If it were me, and I needed a precise and pure digitally synthed Ramp/Sawtooth waveform. And I wasn't in the market for a chip that could do it for me. I would build a precision resistor ladder[1][2] on an 8 bit I/O port. R ladders are tricky beasts form time to time, but when done right changing to a different frequency or waveform is a simple matter of changing the data sent to the port. Also it's simpler to conceptualize the data you need to get a particular waveform because you are working directly with "8 bit magnitude = voltage out" from the start. Finally, an R-R2 ladder is fast... really fast. You can make them go as fast as you can toggle pins. So creating time complex waveforms is no problem.

*HERE* is a link to simulation of something I whipped up for the OP in the last 30 mins. And in case you can't/don't want to view the link, here is a picture for you instead...

View attachment 68447

Notes:
(1): IE has problems running the falstad simulator. I recommend Google Chrome, as it's a safer browser.
(2): You need to enable Java to be able to use/see the sim as well.
(3): Precision resistors are a must. Matching needs to be to at least 1%.
(4): The MOSFETS are arranged as current sources/limiters. It won't work right without.
(5): The wave in the image was VERY easy to create with just timers at multiples of 50Khz.
(6): The voltages and resistances can and will need to be adjusted for your needs.
(7): The glitches in the waveform are from how the sim renders diagonal lines, not from the circuit.
(8): Such a high frequency wave will likely cause significant distortion in the LSb's with standard components.
(9): the simulator has known bugs. A real device may preform differently. Your mileage may vary.
(10): They make these circuits in prebuilt modules or in IC form for reasonable prices.
(11): I reserve the right to make mistakes, and to not be held accountable for them.
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top