Connect with us

PIC 1.5V Output

Discussion in 'Microcontrollers, Programming and IoT' started by Angus, Mar 3, 2015.

Scroll to continue with content
  1. Angus

    Angus

    29
    0
    Jul 4, 2014
    Hello,

    I would like to get a 1.5V output from a microcontroller.

    I am using the PICkit3 Microcontroller starter kit - and it came with a PIC16F1829. I am using MPLAB IDE X V2.3 and the compiler XC8.

    I am using 5V as the supply voltage - and can successfully light up LED's in various sequences......however for the end product/ project I would like to supply 1.5V to another circuit (that will be controlled ON/OFF from the microcontroller). I could use an external voltage reducer (like an LM317T) - however circuit board realestate will be limited - so if can come straight out of the microcontroller with 1.5V......this would be a big win!

    Can this be done?
    What would the 'C' code look like?

    I am very new to micro-controllers.

    All answers welcome and appreciated.

    Thankyou - Angus
     
  2. Gryd3

    Gryd3

    4,098
    875
    Jun 25, 2014
    You have three options...
    PWM and some filter hardware... ie capacitor or inductor to average out the PWM to the voltage you want.
    That, or a voltage divider. 2 resistors will do it.
    Finally.. using the built-in DAC (if this model has it.) I am not familiar enough to provide the code though.
    Please note that both methods here are for a signal only... if you plan to power a device by 1.5V then you need to determine what the current draw will be, and if it won't be stable you will need some form of feedback to keep it at 1.5V
    Of course, more details will always help.
     
  3. BHARGAV SHANKHALPARA

    BHARGAV SHANKHALPARA

    35
    0
    Nov 6, 2013
    With the use of PWM you can generate any voltage between 0-5 Volts. If you dont know what is PWM ,google it. With the use of microcontroller internal timer you can generate PWM Easily.
     
  4. BobK

    BobK

    7,682
    1,687
    Jan 5, 2010
    Look at chapter 17 of your datasheet. There is a 5-bit DAC that can be output to a pin.

    With your 5V supply as the reference:

    DACR = 10 would give you 9/32 * 5 = 1.56V

    But, as GRYD3 points out, this is only as a signal, it cannot supply any power.

    Bob
     
  5. Arouse1973

    Arouse1973 Adam

    5,165
    1,087
    Dec 18, 2013
    You could buffer the DAC with an Opamp couldn't you?
    Adam
     
  6. Gryd3

    Gryd3

    4,098
    875
    Jun 25, 2014
    I don't see why not. Or any other regulator and a transistor to switch the 1.5V source on/off.
    Soo many options ;)
     
  7. Colin Mitchell

    Colin Mitchell

    1,417
    313
    Aug 31, 2014
    Rather than building the TaJ Mahal to deliver 1.5v with PWM, you need to specify how much current you need. Nothing can be answered without this specification.
     
  8. Gryd3

    Gryd3

    4,098
    875
    Jun 25, 2014
    When the op finally tells us it's purpose everyone can give a better solution...
    Theorycrafting like this end up getting out of control.
    You are right though, the PWM method with the filter circuitry is grossly overkill. It has it's uses, but should certainly be avoided for a more simplistic robust approach.
     
  9. Angus

    Angus

    29
    0
    Jul 4, 2014
    Thank-you for the replies above - very much appreciated.

    The 1.5V is to power a sparker unit - ie. astable circuit powering on/off a coil to create a spark. This coil is tiny - I pulled out of a hand held battery powered BBQ lighter.

    I'm away from home at the moment but I'll measure the current/ amp draw and post it in a week when I get back home.

    Thanks again for everyone's input.
     
  10. Angus

    Angus

    29
    0
    Jul 4, 2014
    I loaded up some PWM code which lights an LED - with excellent results to achieve 1.5V - (dimming with a POT).

    Another question......I would like the PWM to turn off completely after say 2 seconds......

    Here is the code:


    void main(void) {
    OSCCON = 0b00111000; //500KHz clock speed
    TRISC = 0; //all LED pins are outputs
    LATC = 0;

    //setup ADC
    TRISAbits.TRISA4 = 1; //Potentiamtor is connected to RA4...set as input
    ANSELAbits.ANSA4 = 1; //analog
    ADCON0 = 0b00001101; //select RA4 as source of ADC and enable the module (AN3)
    ADCON1 = 0b00010000; //left justified - FOSC/8 speed - Vref is Vdd

    //setup the PWM
    CCP2CON = 0b00001100; //PWM mode single output
    PR2 = 255; //Frequency at 486Hz. Anything over ~60Hz will get rid of any flicker
    //PWM Period = [PR2 + 1]*4*Tosc*T2CKPS = [255 + 1] * 4 * (1 / 500KHz) * 1
    CCPTMRSbits.C2TSEL = 0b00; //select timer2 as PWM source
    T2CONbits.T2CKPS = 0b00; //1:1 prescaler
    T2CONbits.TMR2ON = 1; //start the PWM
    __delay_ms(2000);
    T2CONbits.TMR2ON = 0;

    while (1) {
    __delay_us(5); //wait for ADC charging cap to settle
    GO = 1; //start the ADC conversion
    while (GO) continue; //wait for conversion to be finished
    CCPR2L = ADRESH; //put the top 8 MSbs into CCPR2L
    CCP2CONbits.DC2B = (ADRESL>>6); //put the 2 LSbs into DC2B register to complete the 10bit resolution
    }

    }


    To get the PWM to turn off after 2 seconds I have added the code in bold/ red - however the PWM does not turn off. I've tried different configurations of where to put the code etc - nothing works 100% yet.

    Can someone please help with the code which will turn the PWM after 2 seconds.

    Thankyou very much.

    Angus
     
  11. Angus

    Angus

    29
    0
    Jul 4, 2014
    I've answered my own question......the code now works:

    void main(void) {
    OSCCON = 0b00111000; //500KHz clock speed
    TRISC = 0; //all LED pins are outputs
    LATC = 0;

    LATCbits.LATC1 = 1;
    LATCbits.LATC2 = 1;


    //setup ADC
    TRISAbits.TRISA4 = 1; //Potentiamtor is connected to RA4...set as input
    ANSELAbits.ANSA4 = 1; //analog
    ADCON0 = 0b00001101; //select RA4 as source of ADC and enable the module (AN3)
    ADCON1 = 0b00010000; //left justified - FOSC/8 speed - Vref is Vdd

    //setup the PWM
    CCP2CON = 0b00001100; //PWM mode single output
    PR2 = 255; //Frequency at 486Hz. Anything over ~60Hz will get rid of any flicker
    //PWM Period = [PR2 + 1]*4*Tosc*T2CKPS = [255 + 1] * 4 * (1 / 500KHz) * 1
    CCPTMRSbits.C2TSEL = 0b00; //select timer2 as PWM source
    T2CONbits.T2CKPS = 0b00; //1:1 prescaler
    T2CONbits.TMR2ON = 1; //start the PWM


    while (1) {
    __delay_us(5); //wait for ADC charging cap to settle
    GO = 1; //start the ADC conversion
    while (GO) continue; //wait for conversion to be finished
    CCPR2L = ADRESH; //put the top 8 MSbs into CCPR2L
    CCP2CONbits.DC2B = (ADRESL>>6); //put the 2 LSbs into DC2B register to complete the 10bit resolution
    __delay_ms(5000);
    T2CONbits.TMR2ON = 0;
    __delay_ms(2000);
    LATCbits.LATC1 = 0;
    __delay_ms(1000);
    LATCbits.LATC2 = 0;
    }

    }
     
  12. gorgon

    gorgon

    603
    24
    Jun 6, 2011
    Why not use a standard LDO regulator for a 1.5V supply, at least if you need some accuracy. You can get regulaors with several 100s mA outputs at SOT23 like sizes or less. Not much real estate on the PCB.
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Similar Threads
There are no similar threads yet.
Loading...
Electronics Point Logo
Continue to site
Quote of the day

-