i already searched in net
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 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 /* * File: Using DACs of PIC16F1777 * Author: Okada * * Created on October 19, 2016, 5:08 PM */ #define _XTAL_FREQ 32000000 #include <xc.h> // CONFIG1 #pragma config FOSC = INTOSC // Oscillator Selection Bits (INTOSC oscillator: I/O function on CLKIN pin) #pragma config WDTE = ON // Watchdog Timer Enable (WDT enabled) #pragma config PWRTE = ON // Power-up Timer Enable (PWRT disabled) #pragma config MCLRE = ON // MCLR Pin Function Select (MCLR/VPP pin function is MCLR) #pragma config CP = ON // Flash Program Memory Code Protection (Program memory code protection is disabled) #pragma config BOREN = ON // Brown-out Reset Enable (Brown-out Reset enabled) #pragma config CLKOUTEN = OFF // Clock Out Enable (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin) #pragma config IESO = ON // Internal/External Switchover Mode (Internal/External Switchover Mode is enabled) #pragma config FCMEN = ON // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is enabled) // CONFIG2 #pragma config WRT = OFF // Flash Memory Self-Write Protection (Write protection off) #pragma config PPS1WAY = ON // Peripheral Pin Select one-way control (The PPSLOCK bit cannot be cleared once it is set by software) #pragma config ZCD = OFF // Zero-cross detect disable (Zero-cross detect circuit is disabled at POR) #pragma config PLLEN = ON // Phase Lock Loop enable (4x PLL is always enabled) #pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will cause a Reset) #pragma config BORV = LO // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.) #pragma config LPBOR = ON // Low-Power Brown Out Reset (Low-Power BOR is disabled) #pragma config LVP = OFF // Low-Voltage Programming Enable (Low-voltage programming enabled) #define LED LATDbits.LATD0 void main(void) { OSCCON = 0b01111010; CM1CON0 = 0x00; CM2CON0 = 0x00; CM3CON0 = 0x00; CM4CON0 = 0x00; CM5CON0 = 0x00; ANSELA = 0x00; ANSELB = 0x00; ANSELC = 0x00; ANSELD = 0x00; ANSELE = 0x00; ODCONA = 0x00; ODCONB = 0x00; ODCONC = 0x00; ODCOND = 0x00; ODCONE = 0x00; INLVLA = 0x00; INLVLB = 0x00; INLVLC = 0x00; INLVLD = 0x00; //INLVLE = 0x00; SLRCONA = 0x00; SLRCONB = 0x00; SLRCONC = 0x00; SLRCOND = 0x00; SLRCONE = 0x00; WPUA = 0x00; WPUB = 0x00; WPUC = 0x00; WPUD = 0x00; WPUE = 0x00; TRISA = 0xC0; TRISB = 0x00; TRISC = 0x00; TRISD = 0x00; TRISE = 0x00; PORTA = 0x00; PORTB = 0x00; PORTC = 0x00; PORTD = 0x00; PORTE = 0x00; LATA = 0x00; LATB = 0x00; LATC = 0x00; LATD = 0x00; LATE = 0x00; OPA1CON = 0x00; OPA2CON = 0x00; DAC1CON0 = 0b10100000; DAC2CON0 = 0b10100000; DAC5CON0 = 0b10100000; DAC6CON0 = 0b10100000; DAC1REFL = 0xFF; DAC1REFH = 0x01; DAC2REFL = 0x66; DAC2REFH = 0x02; DAC5REFL = 0x70; DAC5REFH = 0x01; DAC6REFL = 0xC2; DAC6REFH = 0x01; DACLD = 0x00; while(1){ LED = ~LED; __delay_ms(500); } }
* did you MEASURE the voltage at VDD? Is it precise 3.3V (during DAC output voltage measurement)?
No, There are no load resistors. I have also disabled Weak Pullup resistors. I am just measuring the voltage at DAC output pins w.r.t GND.* Is your DAC output loaded with any current (resistor...)
No, PIC doesn't get hot. I tested for 5 minutes. I have LED blinking at 500 ms rate and I see it working and the voltage at LED pin toggles between 3.288V and 0V.* does your PIC getting warm/hot?
Should I use a Unity Gain Amplifier for each DAC output ?
OPA1CON = 0b10010000
OPA1ORS = 0x00
OPA1NCHS = 0x0F
OPA1PCHS = 0b00000010 (DAC1_out as input to OPA1 Non-Inverting input)
DAC1CON0 = 0b10000000
DAC1REFH = 0x03
DAC1REFL = 0xFF
DACLDbits.DAC1LD = 1
DAC Vref+ = VDD = 3.3V
DAC Vref- = VSS = 0V
10 Bit DAC (Internal DAC and Internal Op Amp)
Will this settings give me 3.3V at OPA1OUT ?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?