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 CCS Technical Support

XLP: 5-bit DAC not working ??

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



Joined: 14 May 2010
Posts: 20

View user's profile Send private message

XLP: 5-bit DAC not working ??
PostPosted: Thu Nov 18, 2010 1:19 am     Reply with quote

Has anyone tried to run the 5-bit-DAC inside the new XLP PICs?

My 16LF1823 don't want to do anything. Output is everytime 0,0V at PIN12 = DACOUT (no external load, debugger or programmer - only scope).
I tried several settings for PORT A, several clock settings and several settings for #use delay.

Code:

#include <16LF1823.h>     
#include <STDLIB.h>
#fuses INTRC,NOMCLR,NoBROWNOUT,PUT,NoIESO,NOCPD,NOPROTECT
#use fast_IO(A)   
//#USE DELAY (clock=32k)
//#use delay(clock=32k,Aux: crystal=32k, int=32k)
#use delay(clock=4M, int=4M)

int x;   

Main() {
setup_oscillator(OSC_4Mhz|OSC_INTRC);
output_a(0b11111100);
set_tris_A(0b00111011);   
setup_dac(DAC_VDD | DAC_OUTPUT);

while(1){
  delay_cycles(20);               
  dac_write(x);
  ++x;
  if(x>31) x=0;
 }

}

It seems, that you can't do anything wrong:

Datasheet says "Selecting the DAC reference voltage for output
on the DACOUT pin automatically overrides the digital output buffer
and digital input."

Registers in 16LF1823.h seem to be O.K.:
Code:

////////////////////////////////////////////////////////////////// DAC
// Digital to Analog Functions: SETUP_DAC(), DAC_WRITE()
// Constants used in SETUP_DAC() are:
#define DAC_OFF  0         // off
#define DAC_VDD  0x80      // 100% = Ubat
#define DAC_VREF 0x81      // Voltage at ref. - PIN
#define DAC_VR   0x82      // internal voltage reference
#define DAC_OUTPUT 0x40      // DAC switched to PIN

"#use delay" seems to be not very important, I can't find anything time relevant in datasheet and following post:
http://www.ccsinfo.com/forum/viewtopic.php?p=137620
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Nov 18, 2010 1:25 pm     Reply with quote

All these features are version dependent. Always post your compiler
version.
buchtsucht



Joined: 14 May 2010
Posts: 20

View user's profile Send private message

PostPosted: Thu Nov 18, 2010 10:23 pm     Reply with quote

Yes, this is true: compiler is CCS 4.106.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Nov 19, 2010 2:20 pm     Reply with quote

Your version (vs. 4.106) has several things wrong with the setup_dac()
and dac_write() functions. The register addresses are swapped for
the dac registers and the constants in the 16F1823.h file are not correct
or complete.

I made a test program with some work-arounds to fix it for you.
I've used the dac constants from the 16F1823.h file for vs. 4.114 as
shown below. I've also made two macros to re-define the setup_dac()
and dac_write() functions so they will write to the correct register
addresses. I don't have a 16F1823 to test, but I think this program
will probably work:
Code:

#include <16F1823.h>
#fuses INTRC_IO,NOWDT,BROWNOUT,PUT
#use delay(clock=4000000)

// Constants used in SETUP_DAC() are:
#define DAC_OFF  0
#define DAC_VSS_VDD   0x80
#define DAC_VREF_VDD  0x81
#define DAC_VSS_VREF  0x84
#define DAC_VREF_VREF 0x85
#define DAC_VSS_FVR   0x88
#define DAC_FVR_VREF  0x89
// The following may be OR'ed in with the above using |
#define DAC_OUTPUT    0x20
#define DAC_LVP_POS   0x40
#define DAC_LVP_NEG   0

#byte DACCON0 = 0x118
#byte DACCON1 = 0x119

#define setup_dac(value)  DACCON0 = value

#define dac_write(data)  DACCON1 = data


//===========================
void main(void)
{
int8 i;

// Turn on the DAC and enable output on the DACOUT pin, and use
// the Vdd and Vss as the limits for the DAC output voltage.
setup_dac(DAC_OUTPUT | DAC_VSS_VDD);

// Create a sawtooth waveform by ramping up the DAC
// from 0 to 31, one step at a time, continuously.
i = 0;

while(1)
  {
   for(i=0; i< 32; i++)
       dac_write(i);

   delay_us(10);
  }

while(1);
}
 
 
buchtsucht



Joined: 14 May 2010
Posts: 20

View user's profile Send private message

PostPosted: Thu Nov 25, 2010 5:07 am     Reply with quote

wow! Thank you!!!
I had some other problems, but I will test it the next days and tell you if it works!
buchtsucht



Joined: 14 May 2010
Posts: 20

View user's profile Send private message

PostPosted: Tue Dec 07, 2010 1:29 am     Reply with quote

Thanks PCM programmer, it works perfect without any problems - exactly as you wrote it!
mvanvliet



Joined: 02 Jun 2009
Posts: 123
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed Apr 20, 2011 4:15 am     Reply with quote

I want to get the Vref voltage of 4.096 out of the processor, I thought it was the easiest to use the DAC. Because I also use V4.106 (the maintainance renewal is in progress) I tried PCM programmer's code and it's working, I modified it a bit, but when I try to change the SETUP_DAC() into the Vref it doesn't work anymore. What is wrong??

Code:

#include <12F1822.H>

#FUSES INTRC_IO, NOMCLR, NOCPD, NOWDT, NOBROWNOUT, NOPUT, NOPROTECT, NOFCMEN, NOIESO
#use delay(clock=4000000)

// Constants used in SETUP_DAC() are:
#define DAC_OFF  0
#define DAC_VSS_VDD   0x80
#define DAC_VREF_VDD  0x81
#define DAC_VSS_VREF  0x84
#define DAC_VREF_VREF 0x85
#define DAC_VSS_FVR   0x88
#define DAC_FVR_VREF  0x89
// The following may be OR'ed in with the above using |
#define DAC_OUTPUT    0x20
#define DAC_LVP_POS   0x40
#define DAC_LVP_NEG   0

#byte DACCON0 = 0x118
#byte DACCON1 = 0x119

#define setup_dac(value)  DACCON0 = value

#define dac_write(data)  DACCON1 = data

void main(void)
{
setup_vref(VREF_4v096);
setup_dac(DAC_OUTPUT | DAC_VREF_VREF);

while(1)
  {
  dac_write(31);
  delay_us(10);
  }

while(1);
}
mvanvliet



Joined: 02 Jun 2009
Posts: 123
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed Apr 20, 2011 7:38 am     Reply with quote

Code:
#bit CDAFVR0 = 0X117.2
#bit CDAFVR1 = 0X117.3
#bit FVREN = 0X117.7
#bit DACPSS0 = 0X118.2
#bit DACPSS1 = 0X118.3

CDAFVR0 = 1;
CDAFVR1 = 1;
FVREN = 1;
DACPSS0 = 0;
DACPSS1 = 1;


Looking at the registers in the MPLAB simulator I noticed that a few bits aren't set at the right value. Put them manual on the right value solved my problem.
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