Variable voltage output from a Pic?


Closed Thread
Results 1 to 9 of 9
  1. #1
    Join Date
    Jul 2004
    Posts
    6

    Question Variable voltage output from a Pic?

    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

  2. #2
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762


    Did you find this post helpful? Yes | No

    Default

    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.
    regards

    Ralph

    _______________________________________________
    There are only 10 types of people:
    Those who understand binary, and those who don't ...
    _______________________________________________



  3. #3
    mytekcontrols's Avatar
    mytekcontrols Guest


    Did you find this post helpful? Yes | No

    Lightbulb

    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,
    Last edited by mytekcontrols; - 6th July 2005 at 23:20.

  4. #4
    Join Date
    Jul 2004
    Posts
    6


    Did you find this post helpful? Yes | No

    Smile Pwm

    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
    Attached Images Attached Images  
    Last edited by Dan_lay; - 7th July 2005 at 19:10.

  5. #5
    mytekcontrols's Avatar
    mytekcontrols Guest


    Did you find this post helpful? Yes | No

    Default

    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.

  6. #6
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    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.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  7. #7
    Join Date
    Sep 2004
    Location
    Mentor, Ohio
    Posts
    352


    Did you find this post helpful? Yes | No

    Default

    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

  8. #8
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by BobK
    ...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.
    regards

    Ralph

    _______________________________________________
    There are only 10 types of people:
    Those who understand binary, and those who don't ...
    _______________________________________________



  9. #9
    Join Date
    Jun 2013
    Posts
    1


    Did you find this post helpful? Yes | No

    Default Re: Variable voltage output from a Pic?

    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

Similar Threads

  1. Serial VB 2005 pic 16f877a problems
    By Snap in forum mel PIC BASIC Pro
    Replies: 28
    Last Post: - 8th July 2013, 00:52
  2. Replies: 5
    Last Post: - 30th April 2008, 20:01
  3. Serious Serial Situation Setbacks...
    By Dansdog in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 7th February 2007, 03:46
  4. Output PIC module
    By freelancebee in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 12th September 2005, 20:10
  5. can a pic remember a variable?
    By peterdeco1 in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 18th January 2005, 09:50

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts