PIC16F1778 10-bit DAC, anyone?

32 views
Skip to first unread message

Mike

unread,
Nov 27, 2020, 9:37:53 PM11/27/20
to jallib
I'm trying to get the 10-bit DAC of the PIC16F1778 working and am not being successful.  Has anyone used this, or similar?  I'm scoping the output pin and getting nothing.  Below is my code.  Any push in the right direction is appreciated.

Regards,
Mike


--
include 16f1778                     -- target PICmicro
--
pragma target clock    8_000_000       -- oscillator frequency
--
pragma target OSC      INTOSC_NOCLKOUT           -- internal oscillator
pragma target PLLEN    DISABLED                  -- PLL off
pragma target CLKOUTEN DISABLED                  -- no clock output
pragma target WDT      DISABLED                  -- watchdog off
pragma target BROWNOUT DISABLED                  -- no brownout reset
pragma target FCMEN    DISABLED                  -- no clock monitoring
pragma target IESO     DISABLED                  -- no int/ext osc switching
pragma target LVP      DISABLED                  -- low voltage programming off
pragma target MCLR     INTERNAL                  -- internal reset
--
--
OSCCON_SCS = 0                      -- select primary oscillator
OSCCON_IRCF = 0b1110                -- 8 MHz
OSCCON_SPLLEN = FALSE               -- software PLL off
--
enable_digital_io()                 -- make all pins digital I/O
--
LATA = 0
LATB = 0
LATC = 0
TRISA = 0
TRISB = 0
TRISC = 0

DAC1REFL = 0
DAC1REFH = 0
DAC1CON0 = 0b1010_0000 -- DAC on and output to the pin
--
var byte c = 0
--
forever loop
for 255 using c loop
    DAC1REFL = c
    DACLD_DAC1LD = true
    _usec_delay(100_000)
end loop
end loop
--

Mike

unread,
Nov 27, 2020, 10:04:58 PM11/27/20
to jallib
Well, I got it working, but I'm not sure what I did.  Needs some more research.

Regards,
Mike

Mike

unread,
Nov 27, 2020, 10:13:11 PM11/27/20
to jallib
By the way, this 10-bit DAC could be very nice for audio applications.  And this PIC16F1778 also has an op-amp.  If I get something interesting working I'll post it.

Regards,
Mike

Rob CJ

unread,
Nov 28, 2020, 2:04:07 AM11/28/20
to jal...@googlegroups.com
Hi Mike,

I used a 10-bit DAC with PIC16F1765 in my Digital Controlled Power Supply:

I used two functions.

; Initialize the 10-bit Digital to Analog Converter (DAC)
procedure dac_init() is
   ; Enable, right justified, output enable, use VDD as reference, VRef- to VSS.
    DAC1CON0 = 0b1010_0000 ; VDD reference.
    dac_set(MIN_DAC_VALUE) ; Output at minimum    
end procedure

; Write the given value to the 10-bit DAC.
procedure dac_set(word in value) is
   DAC1REF = value
   DACLD_DAC1LD = TRUE
   while DACLD_DAC1LD loop
      ; Wait for DAC to complete transfer.
   end loop
end procedure

This was a very fruitful project for JAL since I extracted two JAL libraries from it, one to control a digital potentiometer and one to write data into HEF (this PIC does not have EEPROM but HEF instead) 😊

Hope this helps.

Kind regards,

Rob



Van: 'Mike' via jallib <jal...@googlegroups.com>
Verzonden: zaterdag 28 november 2020 03:37
Aan: jallib <jal...@googlegroups.com>
Onderwerp: [jallib] PIC16F1778 10-bit DAC, anyone?
 
--
You received this message because you are subscribed to the Google Groups "jallib" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jallib+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jallib/58400326-e940-49be-894a-87edbc767a72n%40googlegroups.com.

vsurducan

unread,
Nov 28, 2020, 2:08:12 AM11/28/20
to jal...@googlegroups.com
Hi Rob,
Which is the meaning of the word "ROJA" ? :)
thx,
Vasile

Rob CJ

unread,
Nov 28, 2020, 2:13:14 AM11/28/20
to jal...@googlegroups.com
Haha,

ROb JAnsen 😊

Kind regards,

Rob

Van: jal...@googlegroups.com <jal...@googlegroups.com> namens vsurducan <vsur...@gmail.com>
Verzonden: zaterdag 28 november 2020 08:07
Aan: jal...@googlegroups.com <jal...@googlegroups.com>
Onderwerp: Re: [jallib] PIC16F1778 10-bit DAC, anyone?
 

Mike

unread,
Nov 28, 2020, 7:48:48 AM11/28/20
to jallib
Hi Rob,

Thank you for posting that.  I'll definitely take a look at it.

Regards,
Mike
Reply all
Reply to author
Forward
0 new messages