Author Topic: PIC DAC register not working in XC8  (Read 2418 times)

0 Members and 1 Guest are viewing this topic.

Offline step_sTopic starter

  • Regular Contributor
  • *
  • Posts: 138
  • Country: dk
PIC DAC register not working in XC8
« on: February 07, 2016, 05:32:04 pm »
Fixed it, and can't remove my post. Sorry.

For the sake of others I have edited the post to include the simple solution.
Most smaller PICs have only 1 digital to analog converter, and even though the datasheet will say "DACxCON0" and "DACxCON1" as the DAC registers, the X is misleading.
In the case of the PIC only having 1 DAC, the registers will be "DACCON0" and "DACCON1", and NOT "DAC1CON0" etc.
Hope this helps :)
« Last Edit: February 09, 2016, 09:30:01 pm by step_s »
 

Offline miguelvp

  • Super Contributor
  • ***
  • Posts: 5550
  • Country: us
Re: DAC register not implemented in XC8
« Reply #1 on: February 07, 2016, 07:14:02 pm »
Fixed it, and can't remove my post. Sorry.

It might be helpful to have left the problem you encountered and what was the mistake for others having the same problem in the future.

Even if it was a simple oversight, it might trap others as well.
 

Offline Daving

  • Contributor
  • Posts: 34
Re: PIC DAC register not working in XC8
« Reply #2 on: February 12, 2016, 04:34:28 pm »
Thanks for putting the solution back in.
 

Offline Bruce Abbott

  • Frequent Contributor
  • **
  • Posts: 627
  • Country: nz
    • Bruce Abbott's R/C Models and Electronics
Re: PIC DAC register not working in XC8
« Reply #3 on: February 14, 2016, 01:37:51 am »
In the case of the PIC only having 1 DAC, the registers will be "DACCON0" and "DACCON1", and NOT "DAC1CON0" etc.
It's not quite that simple. The 16F1704, 1782/3/4/5/6/7 and 1788 all have a single 8 bit DAC with control register 0 at sfr address 118h. In some PICs it is named DACCON0, and in others DAC1CON0. However some PIC have different DACs on other addresses.

Therefore it is vitally important to tell the compiler exactly which MCU you have. If you have a PIC16F1782 (for example) then referring to DAC1CON0 should fail because it is not defined in pic16f1782.h. However if you selected 16F1764 it would compile, but to the wrong address!

Code: [Select]
  MCU       DAC        name    address
16F753    1 x 9 bit  DAC1CON0    91h

16F1704   1 x 8 bit  DAC1CON0   118h

16F1764   1 x 10 bit DAC1CON0   591h
          1 x 5 bit  DAC3CON0   597h

16F1782-7 1 x 8 bit  DACCON0    118h

16F1788   1 x 8 bit  DAC1CON0   118h
          3 x 5 bit  DAC2CON0   591h
                     DAC3CON0   593h
                     DAC4CON0   595h
         
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf