
Thread: 16f753 DAC – 311 days old
-
10th April 2018, 20:12 #1
-
11th April 2018, 15:28 #2
- Join Date
- Feb 2002
- Posts
- 3,118
- Total Downloaded
- 1.53 GB
Thumbs Up Received: 356
Given: 129
0Proton PIC16F753 DAC peripheral routines
I don't have one of these devices, but the 9-bit DAC looks easy to setup and use, from reading the datasheet.
Here's a piece of code that you can copy and create an include file named "DAC.inc"
Code:$ifndef __DAC_INC__ $define __DAC_INC__ ' ' Routines to read and write the 9-bit DAC on a PIC16F753 device ' Auto sets up the DAC peripheral when the include file is used in the program ' ' Written by Les Johnson for the Proton BASIC compiler ' $define _DAC_Pin PORTA.0 ' ' Create a 16-bit SFR from 2 8-bit SFRs ' Dim wDAC1REF As DAC1REFL .Word Symbol DAC1REFLH = DAC1REFH '-------------------------------------------------------------------------------- ' Initialise the DAC ' Input : None ' Output : None ' Notes : DACOE enabled, DACFM right justified, DACEN enabled, DACPSS is VDD ' : DAC1CON0bits_DACEN: DAC Enable bit ' 1 = DAC is enabled ' 0 = DAC is disabled ' DAC1CON0bits_DACFM: DAC Output Format bit ' 1 = DAC output result is right justified ' 0 = DAC output result is left justified ' DAC1CON0bits_DACOE: DAC Voltage Output Enable bit ' 1 = DAC voltage level is also an output on the DACOUT pin ' 0 = DAC voltage level is disconnected from the DACOUT pin ' DAC1CON0bits_DACPSS1, DAC1CON0bits_DACPSS0: DAC Positive Source Select bits ' 11 = FVR output ' 10 = VREF+ pin ' 01 = OPA1OUT pin ' 00 = VDD ' $define DAC_Initialise() ' DAC1CON0 = $E0 ' wDAC1REF = $0000 ' Output _DAC_Pin '-------------------------------------------------------------------------------- ' Write 9-bit data into the DAC voltage reference control register. ' Input : pValue holds the 9-bit data to write to the DAC ' Output : None ' Notes : None ' $define DAC_Write(pValue) wDAC1REF = pValue '-------------------------------------------------------------------------------- ' Read 9-bit data from the DAC SFRs ' Input : None ' Output : Returns the 9-bit data from the DAC ' Notes : None ' $define DAC_Read() wDAC1REF '-------------------------------------------------------------------------------- _DAC_Main_: DAC_Initialise() ' Initialise the DAC $endif ' __DAC_INC__
Code:' ' A demo of the routines to control the 9-bit DAC on a 16F753 device ' Device = 16F753 Declare Xtal = 8 Include "DAC.inc" ' Load the DAC peripheral routines into the program Dim wDAC_Value As Word Main: Do ' Create a loop For wDAC_Value = 0 To 511 ' Create a loop for the 9-bits of data to send to the DAC DAC_Write(wDAC_Value) ' Send the data to the DAC DelayMS 100 ' Slow things down so we can see the output alter Next ' Do it forever Loop
Last edited by Les; 11th April 2018 at 15:55.
For more example programs for Proton and Proton24 or updates, please visit: Proton WIKI or Proton Files
-
13th January 2019, 18:15 #3
0Re: 16f753 DAC
Hi Les, I could not run 16F753 with the following program. What could be the reason?
Code:Device = 16F753 Config FOSC0_INT,WDTE_OFF, PWRTE_ON , MCLRE_ON , BOREN_DIS , WRT_OFF, CP_ON, CLKOUTEN_OFF OSCCON = 110100 Declare Xtal =8 Include "DAC753.inc" ' Load the DAC peripheral routines into the program All_Digital true TRISA=000000 TRISC=000000 CM1CON0=0 DAC1CON0=0 FVR1CON0=0 OPA1CON0=0 SLPCCON0=0 PORTA=0:PORTC=0 ANSELA = 000000 'All digital. A/D disabled ANSELC = 000000 'All digital. A/D disabled CCP1CON = 000000 APFCON=000000 ' Symbol SO = PORTA.2 'Symbol CS = PORTA.0 'Symbol SCK = PORTA.1 Symbol Led=PORTC.5 Dim wDAC_Value As Word Dim M As Word Dim ISI As Word Dim x As Byte Dim z As Byte Clear init: For z=0 To 20 DelayMS 200 Toggle Led Next Main: For wDAC_Value=0 To 511 DAC_Write (wDAC_Value) ' Send the data to the DAC Next GoTo Main
-
14th January 2019, 12:41 #4
- Join Date
- Sep 2010
- Posts
- 1,251
- Total Downloaded
- 2.98 GB
Thumbs Up Received: 77
Given: 39
0Re: 16f753 DAC
What happens when you try to run it?
-
14th January 2019, 14:12 #5
0Re: 16f753 DAC
MCU does not respond at all.
-
14th January 2019, 15:00 #6
- Join Date
- May 2011
- Posts
- 407
- Total Downloaded
- 186.00 MB
Thumbs Up Received: 79
Given: 0
0Re: 16f753 DAC
At a minumum, remove this line:
Code:DAC1CON0=0
I would also leave the DAC output pin set to analog mode (but I think that may be done automatically)
-
14th January 2019, 15:44 #7
0Re: 16f753 DAC
I think the problem stems from the compiler. LED do not even work.
-
14th January 2019, 18:45 #8
0Re: 16f753 DAC
can be a problem in the 16F753 PPI file.
-
31st January 2019, 16:11 #9
- Join Date
- Feb 2002
- Posts
- 3,118
- Total Downloaded
- 1.53 GB
Thumbs Up Received: 356
Given: 129
0Tested Proton BASIC PIC16F753 DAC peripheral routines
Since Acel sent me a few 16F753 devices (many thanks), I have come up with the correction for the device with Proton.
Change the BANK0_START=0x00 to BANK0_START=0x20 in the device's PPI file. I've also done some tests for the DAC and here is a modified set of routines that write to the DAC, and work. :-)
Create a file named "DAC.inc" with the code below:
Code:$ifndef __DAC_INC__ $define __DAC_INC__ ' ' /\\\\\\\\\ ' /\\\///////\\\ ' \/\\\ \/\\\ /\\\ /\\\ ' \/\\\\\\\\\\\/ /\\\\\ /\\\\\\\\\\ /\\\\\\\\ /\\\\\\\\\\\ /\\\\\\\\\\\ /\\\\\\\\\ ' \/\\\//////\\\ /\\\///\\\ \/\\\////// /\\\/////\\\ \////\\\//// \////\\\//// \////////\\\ ' \/\\\ \//\\\ /\\\ \//\\\ \/\\\\\\\\\\ /\\\\\\\\\\\ \/\\\ \/\\\ /\\\\\\\\\\ ' \/\\\ \//\\\ \//\\\ /\\\ \////////\\\ \//\\/////// \/\\\ /\\ \/\\\ /\\ /\\\/////\\\ ' \/\\\ \//\\\ \///\\\\\/ /\\\\\\\\\\ \//\\\\\\\\\\ \//\\\\\ \//\\\\\ \//\\\\\\\\/\\ ' \/// \/// \///// \////////// \////////// \///// \///// \////////\// ' Let's find out together what makes a PIC Tick! ' ' Routines to write to the 9-bit DAC on a 16F753 device ' Auto sets up the DAC peripheral when the include file is used in the program ' ' Written by Les Johnson for the Proton BASIC compiler ' $define _DAC_Pin PORTA.0 ' ' Create a 16-bit SFR from 2 8-bit SFRs ' Dim wDAC1REF As DAC1REFL .Word Symbol DAC1REFLH = DAC1REFH '-------------------------------------------------------------------------------- ' Initialise the DAC ' Input : None ' Output : None ' Notes : bit 7 DACEN: DAC Enable bit ' 1 = DACx is enabled ' 0 = DACx is disabled ' bit 6 DACFM: DAC Output Format bit ' 1 = DACx output result is right justified ' 0 = DACx output result is left justified ' bit 5 DACOE: DAC Voltage Output Enable bit ' 1 = DACx voltage level is also an output on the DACxOUT pin ' 0 = DACx voltage level is disconnected from the DACxOUT pin ' bit 4 Unimplemented: Read as 0 ' bits 3-2 DACPSS<1:0>: DAC Positive Source Select bits ' 11 = FVR output ' 10 = VREF+ pin ' 01 = OPA1OUT pin ' 00 = VDD ' bits 1-0 Unimplemented: Read as 0 ' $define DAC_Initialise() ' Low _DAC_Pin ' wDAC1REF = $0066 ' DAC1CON0 = $E0 '-------------------------------------------------------------------------------- ' Write 16-bit data into the 9-bit DAC voltage reference control register. ' Input : pValue holds the 16-bit data to write to the DAC ' Output : None ' Notes : Data is right justified ' $define DAC_Write16(pValue) ' Clear DAC1CON0bits_DACFM ' wDAC1REF = pValue '-------------------------------------------------------------------------------- ' Write 9-bit data into the DAC voltage reference control register. ' Input : pValue holds the 9-bit data to write to the DAC ' Output : None ' Notes : Data is left justified ' $define DAC_Write(pValue) ' Set DAC1CON0bits_DACFM ' wDAC1REF = pValue '-------------------------------------------------------------------------------- ' Write 8-bit data into the 9-bit DAC voltage reference control register. ' Input : pValue holds the 8-bit data to write to the DAC ' Output : None ' Notes : Data is right justified ' $define DAC_Write8(pValue) ' Clear DAC1CON0bits_DACFM ' DAC1REFL = pValue '-------------------------------------------------------------------------------- _DAC_Main_: DAC_Initialise() ' Initialise the DAC $endif ' __DAC_INC__
Code:' ' /\\\\\\\\\ ' /\\\///////\\\ ' \/\\\ \/\\\ /\\\ /\\\ ' \/\\\\\\\\\\\/ /\\\\\ /\\\\\\\\\\ /\\\\\\\\ /\\\\\\\\\\\ /\\\\\\\\\\\ /\\\\\\\\\ ' \/\\\//////\\\ /\\\///\\\ \/\\\////// /\\\/////\\\ \////\\\//// \////\\\//// \////////\\\ ' \/\\\ \//\\\ /\\\ \//\\\ \/\\\\\\\\\\ /\\\\\\\\\\\ \/\\\ \/\\\ /\\\\\\\\\\ ' \/\\\ \//\\\ \//\\\ /\\\ \////////\\\ \//\\/////// \/\\\ /\\ \/\\\ /\\ /\\\/////\\\ ' \/\\\ \//\\\ \///\\\\\/ /\\\\\\\\\\ \//\\\\\\\\\\ \//\\\\\ \//\\\\\ \//\\\\\\\\/\\ ' \/// \/// \///// \////////// \////////// \///// \///// \////////\// ' Let's find out together what makes a PIC Tick! ' ' A demo of the routines to control the 9-bit DAC on a 16F753 device ' Device = 16F753 Declare Xtal= 8 Declare Optimiser_Level= 1 OSCCON = $30 ' Internal Oscillator Frequency select to 8MHz Repeat: Until OSCCONbits_HTS = 1 ' Wait for oscillator stability Include "DAC.inc" ' Load the DAC peripheral routines into the program Dim wDAC_Value As Word ' Holds the value to send to the DAC '---------------------------------------------- Main: Do ' Create an infinite loop For wDAC_Value = 0 To 511 ' Create a loop for the 9-bits of data to send to the DAC DAC_Write(wDAC_Value) ' Send the data to the DAC DelayMS 100 ' Slow things down so we can see the output alter Next Loop ' Do it forever '---------------------------------------------- ' Configure the fuses ' Config FOSC0_INT, CLKOUTEN_OFF, WDTE_OFF, PWRTE_ON, MCLRE_ON, BOREN_DIS, WRT_OFF, CP_OFF
Last edited by Les; 31st January 2019 at 16:14.
For more example programs for Proton and Proton24 or updates, please visit: Proton WIKI or Proton Files
This valuable resource relies upon the very
small amount of revenue generated by displaying online advertisements
to our visitors.
The advertisements we display are relevant to this web site and your
browsing history
Please consider supporting us by disabling your ad blocker.
Note: Some users have reported issues related to ad-blockers rendering
parts of this wesite unusable,
where possible we will rectify the issues to enable you to use this
resource with adblocking enabled.
If you can, please report issues in the forum area WebSite / Forum Issues
Thank you for your attention.
This valuable resource relies upon the very
small amount of revenue generated by displaying online advertisements
to our visitors.
The advertisements we display are relevant to this web site and your
browsing history
Please consider supporting us by disabling your ad blocker.
Note: Some users have reported issues related to ad-blockers rendering
parts of this wesite unusable,
where possible we will rectify the issues to enable you to use this
resource with adblocking enabled.
If you can, please report issues in the forum area WebSite / Forum Issues
Thank you for your attention.
This valuable resource relies upon the very
small amount of revenue generated by displaying online advertisements
to our visitors.
The advertisements we display are relevant to this web site and your
browsing history
Please consider supporting us by disabling your ad blocker.
Note: Some users have reported issues related to ad-blockers rendering
parts of this wesite unusable,
where possible we will rectify the issues to enable you to use this
resource with adblocking enabled.
If you can, please report issues in the forum area WebSite / Forum Issues
Thank you for your attention.
This valuable resource relies upon the very
small amount of revenue generated by displaying online advertisements
to our visitors.
The advertisements we display are relevant to this web site and your
browsing history
Please consider supporting us by disabling your ad blocker.
Note: Some users have reported issues related to ad-blockers rendering
parts of this wesite unusable,
where possible we will rectify the issues to enable you to use this
resource with adblocking enabled.
If you can, please report issues in the forum area WebSite / Forum Issues
Thank you for your attention.
This valuable resource relies upon the very
small amount of revenue generated by displaying online advertisements
to our visitors.
The advertisements we display are relevant to this web site and your
browsing history
Please consider supporting us by disabling your ad blocker.
Note: Some users have reported issues related to ad-blockers rendering
parts of this wesite unusable,
where possible we will rectify the issues to enable you to use this
resource with adblocking enabled.
If you can, please report issues in the forum area WebSite / Forum Issues
Thank you for your attention.
This valuable resource relies upon the very
small amount of revenue generated by displaying online advertisements
to our visitors.
The advertisements we display are relevant to this web site and your
browsing history
Please consider supporting us by disabling your ad blocker.
Note: Some users have reported issues related to ad-blockers rendering
parts of this wesite unusable,
where possible we will rectify the issues to enable you to use this
resource with adblocking enabled.
If you can, please report issues in the forum area WebSite / Forum Issues
Thank you for your attention.
This valuable resource relies upon the very
small amount of revenue generated by displaying online advertisements
to our visitors.
The advertisements we display are relevant to this web site and your
browsing history
Please consider supporting us by disabling your ad blocker.
Note: Some users have reported issues related to ad-blockers rendering
parts of this wesite unusable,
where possible we will rectify the issues to enable you to use this
resource with adblocking enabled.
If you can, please report issues in the forum area WebSite / Forum Issues
Thank you for your attention.
This valuable resource relies upon the very
small amount of revenue generated by displaying online advertisements
to our visitors.
The advertisements we display are relevant to this web site and your
browsing history
Please consider supporting us by disabling your ad blocker.
Note: Some users have reported issues related to ad-blockers rendering
parts of this wesite unusable,
where possible we will rectify the issues to enable you to use this
resource with adblocking enabled.
If you can, please report issues in the forum area WebSite / Forum Issues
Thank you for your attention.
This valuable resource relies upon the very
small amount of revenue generated by displaying online advertisements
to our visitors.
The advertisements we display are relevant to this web site and your
browsing history
Please consider supporting us by disabling your ad blocker.
Note: Some users have reported issues related to ad-blockers rendering
parts of this wesite unusable,
where possible we will rectify the issues to enable you to use this
resource with adblocking enabled.
If you can, please report issues in the forum area WebSite / Forum Issues
Thank you for your attention.
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads
-
DAC on dsPIC33FJ128GP802
By charliecoultas in forum Proton 24Replies: 31Last Post: 2nd July 2016, 00:48 -
Dac
By ADLIN SYSTEMS in forum The LoungeReplies: 3Last Post: 13th September 2015, 11:35 -
Trinary DAC.
By david in forum The LoungeReplies: 1Last Post: 22nd July 2008, 14:58
Members who have read this thread since 15th February 2019, 17:30 : 0
Actions : (Set Date) (Clear Date)
You do not have permission to view the list of names.
Proton Compiler Updates
Full install of 8-bit Proton and Proton24 Download the full compiler...
1st January 1970, 01:00