View previous topic :: View next topic |
Author |
Message |
mcshawn138
Joined: 12 Dec 2019 Posts: 4
|
DAC output pin for DSPIC33CK64MP102 |
Posted: Thu Dec 12, 2019 4:35 pm |
|
|
I am having trouble setting up the DAC to the output pin RA3. It is not outputing any voltage and appears that the pin is floating. The pic is DSPIC33CK64MP102, and the compiler version is v5.087. Here is the code:
Code: | void DAC_Init(void)
{
output_drive(PIN_A3);
//_bif void setup_comparator(unsigned int8 comparator, unsigned int16 settings);
setup_comparator(1, COMP_DAC_CMPXA | COMP_OUTPUT_DAC);
//_bif void setup_comparator_dac(unsigned int16 settings);
setup_comparator_dac(COMP_COMMON_DAC_ENABLE);
}
void DAC_Write_Value(unsigned int16 DAC_Write_Value)
{
//_bif void dac_write(unsigned int8 comparator, unsigned int16 value);
dac_write(1, DAC_Write_Value);
} |
|
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19358
|
|
Posted: Fri Dec 13, 2019 3:42 am |
|
|
I can't see that you are clocking the DAC.
By default the clock will be from AFvco/2. But nothing is setting up the APLL.
Specify the clock. |
|
![](templates/subSilver/images/spacer.gif) |
mcshawn138
Joined: 12 Dec 2019 Posts: 4
|
|
Posted: Mon Dec 16, 2019 7:26 pm |
|
|
Thanks for your reply. However I still am not able to get it to work. In the beginning of the code before main(), I set up the auxiliary clock using the #use delay() shown in my code. I select the COMP_DAC_CLK_SRC_AFPLLO. Nothing has changed. I read the registers and
have the following values
PIC_DACCTRL1L: 8080
PIC_DACCTRL2L: 0000
PIC_DACCTRL2H: 0000
PIC_DAC1CONL: 8280
PIC_DAC1CONH: 0000
PIC_SLP1CONH: 0000
I am not interested in the slope generation or comparators. I just want to output a DC voltage. Do I still need to enable the slope generator for that? Also the DACOUT pin is also assigned to CMP1C. All I can find in the data sheet is that is Comparator Channels 1C. Could this be messing up my output because the Comparator Channels 1C is assigned to this pin also?
Code: |
#use delay(internal=CLOCK_FREQ, Aux: internal=CLOCK_FREQ, PLL_WAIT)
void DAC_Init(void)
{
output_drive(PIN_A3);
//_bif void setup_comparator(unsigned int8 comparator, unsigned int16 settings);
setup_comparator(1, COMP_DAC_CMPXA | COMP_OUTPUT_DAC);
//_bif void setup_comparator_dac(unsigned int16 settings);
setup_comparator_dac(COMP_COMMON_DAC_ENABLE|COMP_DAC_CLK_SRC_AFPLLO);
}
void DAC_Write_Value(unsigned int16 DAC_Write_Value)
{
//_bif void dac_write(unsigned int8 comparator, unsigned int16 value);
dac_write(1, DAC_Write_Value);
}
|
|
|
![](templates/subSilver/images/spacer.gif) |
mcshawn138
Joined: 12 Dec 2019 Posts: 4
|
|
Posted: Mon Dec 16, 2019 7:27 pm |
|
|
re-posting the code because I did it wrong
Code: | #use delay(internal=CLOCK_FREQ, Aux: internal=CLOCK_FREQ, PLL_WAIT)
void DAC_Init(void)
{
output_drive(PIN_A3);
//_bif void setup_comparator(unsigned int8 comparator, unsigned int16 settings);
setup_comparator(1, COMP_DAC_CMPXA | COMP_OUTPUT_DAC);
//_bif void setup_comparator_dac(unsigned int16 settings);
setup_comparator_dac(COMP_COMMON_DAC_ENABLE|COMP_DAC_CLK_SRC_AFPLLO);
}
void DAC_Write_Value(unsigned int16 DAC_Write_Value)
{
//_bif void dac_write(unsigned int8 comparator, unsigned int16 value);
dac_write(1, DAC_Write_Value);
} |
+++++++++++++++++++++++
You do not have to re-post if you make a mistake
in using the Code button. You can edit your post.
Mod has fixed the error for you.
- Forum Moderator
+++++++++++++++++++++++ |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19358
|
|
Posted: Tue Dec 17, 2019 2:31 am |
|
|
So, what value are you feeding to DAC_Write_Value?. What are you seeing?.
Something like 1200 is needed to give a volt.
It's not capable of giving an output below about 0.2v, so if you are
putting in a low value, you won't see this (data sheet says 0xCD minimum).
The register values look right. DACEN and DACOEN both set. Times set to zero
(this is what MicroChip recommend when using as a voltage source). |
|
![](templates/subSilver/images/spacer.gif) |
mcshawn138
Joined: 12 Dec 2019 Posts: 4
|
|
Posted: Tue Dec 17, 2019 4:47 am |
|
|
I did all differrent values from the makx to the min the data sheet
States do you know what CMPC1 is? |
|
![](templates/subSilver/images/spacer.gif) |
|