16f753 DAC


Today 16:28
Forum: Proton Plus Compiler v3
Starter: Valter
Views: 0
Replies: 0
Today 15:57
Forum: Proton Plus Compiler v3
Starter: gtv_pic
Views: 0
Replies: 20
Today 14:55
Forum: Proton Plus Compiler v3
Starter: kuhrig
Views: 0
Replies: 1
Today 12:39
Forum: The Lounge
Starter: shantanu@india
Views: 0
Replies: 9
Today 02:48
Forum: Proton Plus Compiler v3
Starter: BenBarber
Views: 4587
Replies: 41
+ Reply to Thread
Results 1 to 9 of 9

Thread: 16f753 DAC341 days old

  1. #1
    fofo
    Guest fofo's Avatar

    0 Not allowed!

    Default 16f753 DAC

    16f753 Is there a DAC usage example?

  2. 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.

  3. #2
    Fanatical Contributor Les's Avatar
    Join Date
    Feb 2002
    Posts
    3,158
    Thumbs Up
    Received: 360
    Given: 130
    Total Downloaded
    1.53 GB

    0 Not allowed!

    Default Proton 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__
    Here's a simple demo that works the DAC routines:
    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

  4. 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.

  5. #3
    Junior Member acel's Avatar
    Join Date
    Mar 2014
    Posts
    5
    Thumbs Up
    Received: 0
    Given: 0
    Total Downloaded
    906.76 MB

    0 Not allowed!

    Default Re: 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

  6. 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.

  7. #4
    Prolific Poster charliecoultas's Avatar
    Join Date
    Sep 2010
    Posts
    1,278
    Thumbs Up
    Received: 77
    Given: 39
    Total Downloaded
    3.21 GB

    0 Not allowed!

    Default Re: 16f753 DAC

    What happens when you try to run it?

  8. 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.

  9. #5
    Junior Member acel's Avatar
    Join Date
    Mar 2014
    Posts
    5
    Thumbs Up
    Received: 0
    Given: 0
    Total Downloaded
    906.76 MB

    0 Not allowed!

    Default Re: 16f753 DAC

    MCU does not respond at all.

  10. 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.

  11. #6
    Senior Member tumbleweed's Avatar
    Join Date
    May 2011
    Posts
    414
    Thumbs Up
    Received: 79
    Given: 0
    Total Downloaded
    205.07 MB

    0 Not allowed!

    Default Re: 16f753 DAC

    At a minumum, remove this line:
    Code:
        DAC1CON0=0
    You're overwriting the setup that's done by DAC_Initialise()

    I would also leave the DAC output pin set to analog mode (but I think that may be done automatically)

  12. 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.

  13. #7
    Junior Member acel's Avatar
    Join Date
    Mar 2014
    Posts
    5
    Thumbs Up
    Received: 0
    Given: 0
    Total Downloaded
    906.76 MB

    0 Not allowed!

    Default Re: 16f753 DAC

    I think the problem stems from the compiler. LED do not even work.

  14. 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.

  15. #8
    Junior Member acel's Avatar
    Join Date
    Mar 2014
    Posts
    5
    Thumbs Up
    Received: 0
    Given: 0
    Total Downloaded
    906.76 MB

    0 Not allowed!

    Default Re: 16f753 DAC

    can be a problem in the 16F753 PPI file.

  16. 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.

  17. #9
    Fanatical Contributor Les's Avatar
    Join Date
    Feb 2002
    Posts
    3,158
    Thumbs Up
    Received: 360
    Given: 130
    Total Downloaded
    1.53 GB

    0 Not allowed!

    Default Tested 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__
    And use the code below as a demo for the DAC.inc file (above):

    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 
    Note that the DAC output does not supply much current, so a buffer will be required to power anything. So don't expect an LED to illuminate from it without an op-amp buffer between them.
    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

  18. 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

  1. DAC on dsPIC33FJ128GP802
    By charliecoultas in forum Proton 24
    Replies: 31
    Last Post: 2nd July 2016, 00:48
  2. Dac
    By ADLIN SYSTEMS in forum The Lounge
    Replies: 3
    Last Post: 13th September 2015, 11:35
  3. Trinary DAC.
    By david in forum The Lounge
    Replies: 1
    Last Post: 22nd July 2008, 14:58

Members who have read this thread : 63

Actions :  (Set Date)

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts