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.

timing in PICs

Status
Not open for further replies.

pouchito

New Member
Hello Dudes!!!

Need your help in writing a code that performs the following ( assembly or picbasic it does not matter)

I have no problem in using any of the following PIC16F84, F877 , F73

What i need is produce a 1 V for 20 seconds
and then produces 2 V for 30 seconds
of course we must play with the hardware part too.

What are your suggestions???
 
The quick and easy way to get an analog voltage out of a micro controller is to use PWM. If you turn a pin on and off 1000 times a second and vary the duty cycle the average voltage is going to be equivilant to the duty cycle (on time) So if your PWM signal is on 50% of the time the voltage should be approximatly 2.5 volts (if you're running your pic at 5 volts) But that's average voltage. In order to turn that into an actual analog signal you need to use a resistor in series with the load and a capacitor shorted to ground. This will let the low frequency (signal) through and shunt the higher frequency (PWM frequency) to ground. There is ripple in this output voltage though so it would help if you told us what this 1 or 2 volt signal was going to do.
 
There is more than enough available examples of how to use a PIC's PWM output as a digital to analog converter out there, a simple google search will keep your reading for hours. You simply set a PWM output at the highest possible frequency that will still give it an 8 bit wide duty cycle. Any basic tutorial on a PIC's PWM output abilities will teach you all you need to know.
Also look up "Low pass filter" in wikipedia, The most basic form of it is as I described above, a resistor in series with the output and a capacitor shorted to signal ground. But it depends on how fast you need your voltage to change. You will still always have some ripple (related to the PWM frequency) on the output, but the higher the frequency you use for PWM the easier it is to filter out, especially if you only need the signal to change slowly.
 
You can also use the comparator reference pin on the 16F628 mcu to get voltages like 0.8, 1.5,2 etc.
 
The cutoff frequency should match the highest frequency component of the signal you're trying to create. The lower the cutoff frequency compared to the PWM frequency the less ripple.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top