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

16F15345 DAC don't work [Solved]

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



Joined: 09 Feb 2004
Posts: 37
Location: TURIN -Italy-

View user's profile Send private message Send e-mail

16F15345 DAC don't work [Solved]
PostPosted: Mon Jul 18, 2022 3:40 pm     Reply with quote

#include <main.h>

void main()
{

while(TRUE)
{

setup_DAC(DAC_VSS_VDD | DAC_OUTPUT);
dac_write(25); // OV DRL-->OFF
delay_ms(1000);
setup_DAC(DAC_VSS_VDD | DAC_OUTPUT);
dac_write(10); // OV DRL-->OFF
//TODO: User Code
}

}
Ttelmah



Joined: 11 Mar 2010
Posts: 19535

View user's profile Send private message

PostPosted: Tue Jul 19, 2022 12:54 am     Reply with quote

Comments:

First, learn to use the code buttons.
Then the code should be something we can compile. So you need to include
the stuff in main.h
Now with those said:
Code:

#include <16LF15345.h>
#fuses NOMCLR
#fuses NOLVP
#fuses NOWDT
#use delay(internal=16MHz)

#BYTE ANSELA=getenv("SFR:ANSELA")

void main()
{
   bit_set(ANSELA,0); //turn on ANSEL bit for DAC1OUT1
   while(TRUE)
   {
      setup_DAC(DAC_VSS_VDD | DAC_OUTPUT);
      dac_write(25); // OV DRL-->OFF
      delay_ms(1000);
      //setup_DAC(DAC_VSS_VDD | DAC_OUTPUT);
      //not needed again
      dac_write(10); // OV DRL-->OFF
      delay_ms(1000); //otherwise you will never see this voltage
   }
}

Now, what I've posted shows the clock setups. Have you actually proved
that the chip is running?. Needed before asking questions about the DAC.

Several further comments.

First, you should enable the ANSEL bit for any pin being used for analog
functions. Otherwise excessive current can be drawn. I show this.
Then I delay after the second voltage. Otherwise this won't be seen.
Where are you checking, and how?. Understand that the DAC outputs
are quite high impedance.

Quote:

Due to the limited current drive capability, a buffer must
be used on the DAC voltage reference output for
external connections to the DAC1OUT1/2 pins.
Figure 21-2 shows an example buffering technique.


Note the 'must' here.

The output is on port A.0.

Also, 'what compiler version'?.
Roberto da Rivoli



Joined: 09 Feb 2004
Posts: 37
Location: TURIN -Italy-

View user's profile Send private message Send e-mail

16F15345 DAC don't work (SOLVED )
PostPosted: Tue Jul 19, 2022 9:49 am     Reply with quote

thanks Ttelmah
I apologize if I was not very clear, and I entered a really badly written piece of code, but the whole project is very complex and needs some elaborate hardware behind it.

I inserted the two lines you recommended and now it works
#BYTE ANSELA = getenv ("SFR: ANSELA")
bit_set (ANSELA, 0); // turn on ANSEL bit for DAC1OUT1

I did not know I had to enter this code, on other micro I had not done it.
Thanks for the support
Ttelmah



Joined: 11 Mar 2010
Posts: 19535

View user's profile Send private message

PostPosted: Wed Jul 20, 2022 12:13 am     Reply with quote

OK. That makes sense then.

Mark the thread as [solved].

The point about ANSEL, is it doesn't exist, except on relatively new 'low
power' chips. It turns off the digital connection to a pin. Needs to be enabled
on things like ADC inputs, the DAC output, inputs to the comparators etc..
You need to set it on for every pin used for analog.
Though it is described as turning off the digital connection (which would
only be to save power), on some chips it seems to actually disconnect the
analog connection unless enabled, which is why you were having problems.
A 'caveat' on such chips...
Ttelmah



Joined: 11 Mar 2010
Posts: 19535

View user's profile Send private message

PostPosted: Wed Jul 20, 2022 7:06 am     Reply with quote

As one final comment, you can do this without accessing the register
yourself, by using:

set_analog_pins(PIN_A0);

This historically had issues on some chips (which is why I went manual),
but on recent compilers works fine.
Roberto da Rivoli



Joined: 09 Feb 2004
Posts: 37
Location: TURIN -Italy-

View user's profile Send private message Send e-mail

[SOLVED] 16F15345 DAC don't work
PostPosted: Wed Jul 20, 2022 3:52 pm     Reply with quote

Laughing
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