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.

Has anyone tried the DAC on a pic16f18855

Status
Not open for further replies.

be80be

Well-Known Member
I been playing with the 16f18855 DAC making waves with some code that was for a 8 bit DAC
The DAC1R how do you set this
I ran this code
Code:
/**
 #include "mcc_generated_files/mcc.h"

/*
                         Main application
 */
void main(void)
{
    // initialize the device
    SYSTEM_Initialize();

    // When using interrupts, you need to set the Global and Peripheral Interrupt Enable bits
    // Use the following macros to:

    // Enable the Global Interrupts
    //INTERRUPT_GlobalInterruptEnable();

    // Enable the Peripheral Interrupts
    //INTERRUPT_PeripheralInterruptEnable();

    // Disable the Global Interrupts
    //INTERRUPT_GlobalInterruptDisable();

    // Disable the Peripheral Interrupts
    //INTERRUPT_PeripheralInterruptDisable();
 uint8_t count=0;

 DAC_Initialize();
    while (1)
    {
      for(count=0; count<=32; count++)
        {
            DAC_SetOutput(count);
            __delay_ms(50);

        }
    }
}
/**
 End of File
*/
 
I'm sorry, but this is getting worse.. Mcc Generated files?? The only one that can view them is you..

This chip only has a 5 bit DAC... Hopefully the generated function DAC_SetOutput() should control the DAC1R register.
 
This chip only has a 5 bit DAC... Hopefully the generated function DAC_SetOutput() should control the DAC1R register.

I've always wondered at the lack of decent D2A on PIC's, although I suppose mostly it's a pretty rarely used feature anyway - and of course it's not just PIC's, it's most processors. Easy enough of course to generate decent D2A using PWM, and at more than 8 bits if required.
 
Im sorry the DAC_SetOutput() dose control the DAC1R register.

I figured that out I should get a ramp up but my scope rolls up.
 
There is no knowing what mcc generated code looks like. It may be expecting an 8 bit value or a left justified 5 bit. Only way to tell is to look at the generated code.

Mike.
Edit, just had a look and the generated code is
Code:
void DAC_SetOutput(uint8_t inputData){
    DAC1CON1  = inputData;
}
So it expects 5 bits right justified.
Did you turn on the output in MCC?
 
Last edited:
Yep it works but its not a ramp it rolls up.
The FVR made it worst. So this is what going on Im sending the 32 steps but it's maybe not getting all of the bits right.
This is not doing what I think it should be doing.
Code:
 for(count=0; count<=32; count++)
        {
            DAC_SetOutput(count);
            __delay_ms(50);

        }
    }
 
When you say "it rolls up", what do you mean? Something like exponential? Is there any capacitance involved?

Mike.
 
Maybe this helps
dac1.jpg
 

Attachments

  • dac.zip
    31.6 KB · Views: 187
It looks like there is too much load on the pin. The datasheet states that the output must be buffered.

Mike.
Edit, the resistor ladder uses 5k resistors for a total of 160k.
 
The input of your scope should be in the Megohm range. Do you have anything else on the output?

Mike.
 
Nope lol it was the pickit3 unhooked it and now it looks good.
that was dumb the pickit was loading it lol
i'm just playing with it to make waves
 
Last edited:
Do you have a high impedance meter? If so, try setting the DAC to 15 and see if it reads half the supply voltage.

Mike.
 
It's working now I move the output to pin RA2 I didn't think about loading cause I'm using a scope the pickit was loading RB7
I now have a nice wave 0 to 5.10 volts
 
I thought the same thing. They could have at least made it inline. Probably find that is one of the optimizations that the paid compiler sorts out.

Mike.
 
Funny i have one of them 16f18446 nano
They changed its name when they updated there progrsmmer frimware
 
Status
Not open for further replies.

Latest threads

Back
Top