CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

DAC output pin for DSPIC33CK64MP102

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
mcshawn138



Joined: 12 Dec 2019
Posts: 4

View user's profile Send private message

DAC output pin for DSPIC33CK64MP102
PostPosted: Thu Dec 12, 2019 4:35 pm     Reply with quote

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);
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19358

View user's profile Send private message

PostPosted: Fri Dec 13, 2019 3:42 am     Reply with quote

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



Joined: 12 Dec 2019
Posts: 4

View user's profile Send private message

PostPosted: Mon Dec 16, 2019 7:26 pm     Reply with quote

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);
}
mcshawn138



Joined: 12 Dec 2019
Posts: 4

View user's profile Send private message

PostPosted: Mon Dec 16, 2019 7:27 pm     Reply with quote

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
+++++++++++++++++++++++
Ttelmah



Joined: 11 Mar 2010
Posts: 19358

View user's profile Send private message

PostPosted: Tue Dec 17, 2019 2:31 am     Reply with quote

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).
mcshawn138



Joined: 12 Dec 2019
Posts: 4

View user's profile Send private message

PostPosted: Tue Dec 17, 2019 4:47 am     Reply with quote

I did all differrent values from the makx to the min the data sheet
States do you know what CMPC1 is?
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group