View previous topic :: View next topic |
Author |
Message |
Roberto da Rivoli
Joined: 09 Feb 2004 Posts: 37 Location: TURIN -Italy-
|
16F15345 DAC don't work [Solved] |
Posted: Mon Jul 18, 2022 3:40 pm |
|
|
#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
}
} |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19369
|
|
Posted: Tue Jul 19, 2022 12:54 am |
|
|
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'?. |
|
![](templates/subSilver/images/spacer.gif) |
Roberto da Rivoli
Joined: 09 Feb 2004 Posts: 37 Location: TURIN -Italy-
|
16F15345 DAC don't work (SOLVED ) |
Posted: Tue Jul 19, 2022 9:49 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19369
|
|
Posted: Wed Jul 20, 2022 12:13 am |
|
|
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... |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19369
|
|
Posted: Wed Jul 20, 2022 7:06 am |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
Roberto da Rivoli
Joined: 09 Feb 2004 Posts: 37 Location: TURIN -Italy-
|
[SOLVED] 16F15345 DAC don't work |
Posted: Wed Jul 20, 2022 3:52 pm |
|
|
![Laughing](images/smiles/icon_lol.gif) |
|
![](templates/subSilver/images/spacer.gif) |
|