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

DAC Programming PIC
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
cavoti



Joined: 29 Jul 2016
Posts: 11

View user's profile Send private message

DAC Programming PIC
PostPosted: Fri Jul 29, 2016 2:51 am     Reply with quote

Hello I am using a PIC16F1709 and tried to use the DAC. The DAC does something but I have a strange problem. When I write to the DAC the highest value the output is 0.3V and when I write the lowest value the output is 0.9V but my Reference is 3.3V(VDD). I've done all the necessary steps but it still doesn't work. Could someone help me?
guy



Joined: 21 Oct 2005
Posts: 297

View user's profile Send private message Visit poster's website

PostPosted: Fri Jul 29, 2016 4:59 am     Reply with quote

Please post your code and write your compiler version.
Quote:
I've done all the necessary steps but it still doesn't work.

There must be something wrong or it would work, right? Cool
Let's keep an open mind when chasing bugs.
temtronic



Joined: 01 Jul 2010
Posts: 9246
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Jul 29, 2016 5:20 am     Reply with quote

as Guy says we NEED to see your code and compiler version.
It could be simple MIScoding or a bug in your version of the compiler. We don't know....until we see your code!

Though I don't use that PIC, most have 'multi use' I/O pins so some other peripheral could still be 'attached' to the DAC pin ?

Jay
cavoti



Joined: 29 Jul 2016
Posts: 11

View user's profile Send private message

PostPosted: Fri Jul 29, 2016 5:38 am     Reply with quote

Code:

//Mikrokontrollerangabe und Includes
#device PIC16F1709 //Angabe für PIC-Device
#include "16F1709.h" //Standart Bibliothek  von PIC16F1709 

//Anfangskonfiguration Mikrocontroller
#fuses NOFCMEN, NOIESO, CLKOUT, NOBROWNOUT, NOPROTECT, MCLR, NOPUT, NOWDT, HS //Konfigurationswort 1 konfigurieren
#fuses NOLVP, DEBUG, NOLPBOR, BORV19, NOSTVREN, NOPLLEN, NOZCDDIS, NOPPS1WAY, NOWRT //Konfigurationswort 2 konfigurieren

//Konfigurationen für Gebrauch von zukünftigen Funktionen
#use FAST_IO(C) //Richtungsbestimmung von PORTC-Bits bestimmen
#use delay(clock=16000000,crystal = 16000000)   //Clock- und Clocktypangabe

//Konfiguration um uC Register manuell anzusteuern
#byte DAC1CON0 = 0x118 //DAC Konfigurationsregister
#byte DAC = 0x119   //DAC Wertregister

//Definierungen Ports-Bits
#define DAC_Ausgang        PIN_A2 //Ausgang Digital-Analog-Wandler

//Initialisierung Globale Variablen
//Variablen  für DAC
int8 dac_ausgangswert = 255; //Referenzspannung für Stromregeleschaltung

//DAC Ansteuerung (Hauptprogramm)
void main(void)
{
    set_tris_a(0x3B); //PORTA konfigurieren
    DAC = 0;    //Ausgabewert DAC auf 0 setzen
    DAC1CON0 = 0x90;    //DAC Konfigurationsregister konfigurieren
    delay_ms(10);   //Verzögerung 10ms
   
    while(1)
    {
        DAC = dac_ausgangswert; //Wert ausgeben
    }
}


Last edited by cavoti on Fri Jul 29, 2016 5:41 am; edited 1 time in total
cavoti



Joined: 29 Jul 2016
Posts: 11

View user's profile Send private message

PostPosted: Fri Jul 29, 2016 5:39 am     Reply with quote

sry for answering so late
cavoti



Joined: 29 Jul 2016
Posts: 11

View user's profile Send private message

PostPosted: Fri Jul 29, 2016 5:42 am     Reply with quote

I'm from Switzerland and so I wrote the comments in german
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jul 29, 2016 9:13 pm     Reply with quote

You never told us your CCS compiler version. Ttelmah asked you to do
that in the other thread you opened.

The version is given at the top of the .LST file. The .LST file will be in
your project directory after a successful compilation.
cavoti



Joined: 29 Jul 2016
Posts: 11

View user's profile Send private message

PostPosted: Mon Aug 22, 2016 12:21 am     Reply with quote

This is my Compiler Version "CCS PCM C Compiler, Version 5.060"
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Mon Aug 22, 2016 9:09 am     Reply with quote

Comments:

Code:


//Mikrokontrollerangabe und Includes
//#device PIC16F1709 //Angabe für PIC-Device
#include "16F1709.h" //Standart Bibliothek  von PIC16F1709 


Loading the processor library automatically defines the processor. You don't need the device line, and having it increases the risk of getting something wrong here.

Code:

//Anfangskonfiguration Mikrocontroller
#fuses NOFCMEN, NOIESO, CLKOUT, NOBROWNOUT, NOPROTECT, MCLR, NOPUT, NOWDT, HS //Konfigurationswort 1 konfigurieren
#fuses NOLVP, DEBUG, NOLPBOR, BORV19, NOSTVREN, NOPLLEN, NOZCDDIS, NOPPS1WAY, NOWRT //Konfigurationswort 2 konfigurieren

Why have you got NOZCDDIS selected?.

This means the ZCD source is permanently enabled on the pin you are using for the DAC output..... You need ZCDDIS.

Also, honestly you want STVREN enabled.

Once you have turned off the ZCD, the remaining question will be the load you are trying to drive?. Remember this is a high impedance output, and requires a buffer.
cavoti



Joined: 29 Jul 2016
Posts: 11

View user's profile Send private message

PostPosted: Mon Aug 22, 2016 11:38 pm     Reply with quote

The ZCD and STVREN are both already disabled. Are you saying that I have enable it both?
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Tue Aug 23, 2016 12:00 am     Reply with quote

Not quite.

NOZCDDIS _enables_ the ZCD....

ZCDDIS, disables the ZCD. ZCD disable.

You have the ZCD turned on.

NOSTVREN, means do not reset the chip when a stack full occurs. If you use this, then your code will have to check the stack overflow flag, and do some form of error recovery when an overflow occurs. Much easier (and safer), to have STVREN, which then means if something goes wrong and a stack overflow occurs, the chip will reset (Stack overflow reset enable).

Use:
Code:

//Anfangskonfiguration Mikrocontroller
#fuses NOFCMEN, NOIESO, CLKOUT, NOBROWNOUT, NOPROTECT, MCLR, NOPUT, NOWDT, HS //Konfigurationswort 1 konfigurieren
#fuses NOLVP, DEBUG, NOLPBOR, BORV19, STVREN, NOPLLEN, ZCDDIS, NOPPS1WAY, NOWRT //Konfigurationswort 2 konfigurieren


The ZCD being enabled, is almost certainly what is stopping the DAC2 output from working (on the same pin).
cavoti



Joined: 29 Jul 2016
Posts: 11

View user's profile Send private message

PostPosted: Tue Aug 23, 2016 12:02 am     Reply with quote

Thank you very much:) Sry but I taught that NOZCDDIS means that ZCD ist disabled.
cavoti



Joined: 29 Jul 2016
Posts: 11

View user's profile Send private message

PostPosted: Tue Aug 23, 2016 12:10 am     Reply with quote

I tried it but it still doesn't work. It's really strange because I think I did all the configurations in the right way.
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Tue Aug 23, 2016 12:30 am     Reply with quote

cavoti wrote:
Thank you very much:) Sry but I taught that NOZCDDIS means that ZCD ist disabled.


You were taught wrong.
You can check very easily by compiling the code, and looking at what bits are set in the hex file.

The reason for the naming, is it is an inverted bit. '0' enables the ZCD:

Code:

bit 7 ZCDDIS: ZCD Disable bit
1 = ZCD disabled. ZCD can be enabled by setting the ZCDSEN bit of ZCDCON
0 = ZCD always enabled


NOZCDDIS, sets this bit to '0' (ZCD always enabled). ZCDDIS enables the bit (disabling the ZCD).

However if it still doesn't work, then try the obvious simple test. Remove the PIC. Put a resistor of (say) 4K7 on the DAC2 output, up to your supply voltage. Does it go up to the supply rail?. If it doesn't, then the problem is in the circuit the pin is driving....


Last edited by Ttelmah on Tue Aug 23, 2016 2:15 am; edited 1 time in total
cavoti



Joined: 29 Jul 2016
Posts: 11

View user's profile Send private message

PostPosted: Tue Aug 23, 2016 12:35 am     Reply with quote

Thank you again i will try it:)
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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