PDA

View Full Version : Variable voltage output from a Pic?



Dan_lay
- 4th July 2005, 18:36
Just wondering if this is possible,
I need a PIC that can give me a variable voltage from aprox. 0-2.5 volts on an output pin.

Can this be done with an Analogue port of a eg.: PIC16F84?

I'm programming in PIC Basic, any source code would be aprecheated.

I need to be able to set multiple pins on my PIC to be different voltages at the same time.

Thanks in advance.

Dan

NavMicroSystems
- 4th July 2005, 19:41
Dan,

nothing is impossible, but:

The 16F84 doesn't have any analog ports at all.
And even if there was one, would be an Input, not an Output.

There are many ways to solve your problem.

You could use an ADC, chip, or use PWM to generate the required voltages, or an R/2R Network etc.

It all depends on what precision, resolution and speed your application requires.

You have got to give us some more details.

mytekcontrols
- 6th July 2005, 23:17
Sounds like you need to do some PWM, filter it with an RC network, and if you need to pump this into a low impedance load, use an opamp to buffer the output (Check out the PWM command in your PicBasic Pro Manual).

Here's a link to something that might interest you:LED fade without PWM command

However if you need the ability to do other things while the pic is maintaining the PWM output, you would be better off changing over to a PICF628 instead which has a hardware PWM output. Using this pic with PBP's HPWM command, you basically have a set it and forget it situation, with the pic handling the PWM in the background. Check out this link for more info on this chip and its built-in PWM capabilities: http://www.rentron.com/PIC16F628.htm

I hope that helps you out,

Dan_lay
- 7th July 2005, 19:06
Hi Guys, thanks for your thoughts on this.
What i'm trying to do is control the colour of a tri-colour LED (red, green and blue) I want to be able to set the overall colour of my LED at any colour using different voltages on each pin.

I wasn't aware of the PWM command until now, it works well but goes low when I come out of the PWM loop.

In my code, i'm using the SerIn command to listen for the RGB values, set the colour of the LED acordingly and then wait for another input.

The hardware HPWM command sounds perfect, that way I can just alter the colour and go back to SerIn.

My other problem is that I have 100x tri-colour leds to control. It shouldn't be too much of a problem to address them all, thats if the 16F628 supports SerIn?
I don't mind having 30 of these pics (10 for each colour), each controling 1 colour of 10 separate led's. Do you know if there are enough outputs on the 16F628 to do this?

Many Thanks,

Dan

mytekcontrols
- 8th July 2005, 02:06
Dan,

Bad news on the hardware PWM. The 16F628 only has one port with this feature. There are other chips that have more, but off the top of my head I do believe the maximum is 4 PWM ports.

PWM is definately a good way to go, in fact since I now know you'll be controlling LEDs, you don't need to convert this to analog (controlling the duty cycle should be sufficient). The 16F628 has 16 I/O ports available, but like I said only one of them supports the HPWM function. Perhaps you can do it as a software PWM, but not via PBP's PWM command. Instead do it with a bit of embedded ASM code. Check out this link: http://www.dattalo.com/technical/software/pic/pwm8.asm

It describes a method of producing 8 PWM outputs. If you used this with a PIC chip that has a built-in USART, you should be able to do what you have in mind, and not use too many pic chips (perhaps extend it to 10 PWM outputs).

Better still, would be if the software PWM was done as an interrupt service routine. This would allow you to write everything else in PBP, but still have stable PWM pulses. If I come across a good way to do this I'll post it here.

mister_e
- 8th July 2005, 03:12
Timer interrupt is also a way to go and do PWM on multipl output... much trickier but not impossible..

Another Idea is to use Multiples DAC like MAX517/518 on few I2C BUS.

BobK
- 8th July 2005, 12:38
Hello,

From the picture you provided and the description of your project it looks like each color has it's own pin plus a common for all 3 colors. Why then would you need PWM? It would seem like you only need an "ON" or "OFF" for each color which then is 1 pin per color which would then mean 5 LEDs per PIC.

Let me know if I'm off base here but after reading the above posts that's the way I interpret what you want to do.

BOBK

NavMicroSystems
- 8th July 2005, 18:28
...It would seem like you only need an "ON" or "OFF" for each color which then is 1 pin per color which would then mean 5 LEDs per PIC.

Let me know if I'm off base here but after reading the above posts that's the way I interpret what you want to do.

BOBK

Bob,

that way you would only be able to produce 7 different colors.
If you want the full spectrum you have to control the intensity of every base color individually.

rafteryd
- 24th June 2013, 20:25
Hey Im looking for help picking a pic suitable for a smoothly stepped voltage between 0 and 10 volts DC over say 5 seconds, Controllable with a button array one that could call for 0v 3v 6v and 10v looking to step in around .3v per step.
Also is there a pic that would support Bluetooth control a swell as the button array
Thanks
Dave