Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Issue with DAC of PIC16F18877 [Getting No DAC Output]

Status
Not open for further replies.

edaboard.user

Newbie
Joined
Mar 23, 2024
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
96
Issue with DAC of PIC16F18877 [Getting No DAC Output]

I am trying to use the 5-Bit DAC of PIC16F18877 but I am not getting any output.
External Oscillator of 16MHz Crystal is used.

Led Blink Test code is okay.

This is my MPLAB X IDE's XC8 Compiler code.

I need to get 1kHz Sine Wave.

Edit:

I am checking the output with my genuine Saleae Logic Analayzer.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// PIC16F18877 Configuration Bit Settings
 
// 'C' source line config statements
 
// CONFIG1
#pragma config FEXTOSC = HS     // External Oscillator mode selection bits (HS (crystal oscillator) above 4MHz; PFM set to high power)
#pragma config RSTOSC = EXT1X   // Power-up default value for COSC bits (EXTOSC operating per FEXTOSC bits)
#pragma config CLKOUTEN = OFF   // Clock Out Enable bit (CLKOUT function is disabled; i/o or oscillator function on OSC2)
#pragma config CSWEN = ON       // Clock Switch Enable bit (Writing to NOSC and NDIV is allowed)
#pragma config FCMEN = ON       // Fail-Safe Clock Monitor Enable bit (FSCM timer enabled)
 
// CONFIG2
#pragma config MCLRE = OFF      // Master Clear Enable bit (MCLR pin function is port defined function)
#pragma config PWRTE = OFF      // Power-up Timer Enable bit (PWRT disabled)
#pragma config LPBOREN = OFF    // Low-Power BOR enable bit (ULPBOR disabled)
#pragma config BOREN = OFF      // Brown-out reset enable bits (Brown-out reset disabled)
#pragma config BORV = LO        // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (VBOR) set to 1.9V on LF, and 2.45V on F Devices)
#pragma config ZCD = OFF        // Zero-cross detect disable (Zero-cross detect circuit is disabled at POR.)
#pragma config PPS1WAY = ON     // Peripheral Pin Select one-way control (The PPSLOCK bit can be cleared and set only once in software)
#pragma config STVREN = ON      // Stack Overflow/Underflow Reset Enable bit (Stack Overflow or Underflow will cause a reset)
 
// CONFIG3
#pragma config WDTCPS = WDTCPS_31// WDT Period Select bits (Divider ratio 1:65536; software control of WDTPS)
#pragma config WDTE = OFF       // WDT operating mode (WDT Disabled, SWDTEN is ignored)
#pragma config WDTCWS = WDTCWS_7// WDT Window Select bits (window always open (100%); software control; keyed access not required)
#pragma config WDTCCS = SC      // WDT input clock selector (Software Control)
 
// CONFIG4
#pragma config WRT = OFF        // UserNVM self-write protection bits (Write protection off)
#pragma config SCANE = available// Scanner Enable bit (Scanner module is available for use)
#pragma config LVP = OFF        // Low Voltage Programming Enable bit (High Voltage on MCLR/Vpp must be used for programming)
 
// CONFIG5
#pragma config CP = OFF         // UserNVM Program memory code protection bit (Program Memory code protection disabled)
#pragma config CPD = OFF        // DataNVM code protection bit (Data EEPROM code protection disabled)
 
// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.
 
#include <xc.h>
 
#define _XTAL_FREQ 16000000
 
 
unsigned int index;
 
const unsigned char TableSineWave[128] = {
16,16,17,18,19,19,20,21,21,22,23,23,24,25,25,26,26,27,27,28,
28,29,29,30,30,30,30,31,31,31,31,31,31,31,31,31,31,31,30,30,
30,30,29,29,28,28,27,27,26,26,25,25,24,23,23,22,21,21,20,19,
19,18,17,16,16,15,14,13,12,12,11,10,10,9,8,8,7,6,6,5,
5,4,4,3,3,2,2,1,1,1,1,0,0,0,0,0,0,0,0,0,
0,0,1,1,1,1,2,2,3,3,4,4,5,5,6,6,7,8,8,9,
10,10,11,12,12,13,14,15
};
 
///Timer1
//Prescaler 1:1; TMR1 Preload = 61536; Actual Interrupt Time : 1 ms
//Place/Copy this part in declaration section
void InitTimer1(){
    T1CON = 0x01;
    PIR4bits.TMR1IF = 0;
    TMR1H = 0xF0;
    TMR1L = 0x60;
    PIE4bits.TMR1IE = 1;
    INTCON = 0xC0;
}
 
void __interrupt() ISR(void) {
    if((PIE4bits.TMR1IE) && (PIR4bits.TMR1IF)) {
        PIR4bits.TMR1IF = 0;
        TMR1H = 0xF0;
        TMR1L = 0x60;
        //Enter your code here
        if(++index > 127)index = 0;
        DAC1CON1 = TableSineWave[index];
    }
}
 
void main() {
    CM1CON0 = 0;
    CM2CON0 = 0;
 
    WPUA = 0b00001010;
 
    ANSELA = 0b00000000;
 
    TRISA = 0b00001010;
 
    SLRCONA = 0;
    ODCONA = 0;
    INLVLA = 0;
 
    PORTA = 0;
 
    LATA = 0;
 
    DAC1CON0 = 0b10100000;        // RA2-sinu wave 1kHz
 
    InitTimer1();
 
    while(1) {
    
    }
}




Edit2:

I referred this article.

https://onlinedocs.microchip.com/ox...UID-BA0192AA-4BD9-4C5C-8F70-30FDA64058E4.html

I made a quick test and DAC is working but it is the interrupt that is not firing.
What might be the issue?
 
Last edited:

The issue got solved.

Firstly the issue was with both XC8 and mikroC PRO PIC Compiler regarding DAC part of PIC16F18877 Microcontroller.
So, I switched the device to PIC18F46K22.

2. ANSELA had to be set to 0b00000100 to get Analog Voltages of the DAC on the RA2 Pin.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top