Weirdness with 16F1705's eeprom and DAC


Closed Thread
Results 1 to 14 of 14

Hybrid View

  1. #1
    Join Date
    Jun 2005
    Location
    West Australia
    Posts
    116

    Default Weirdness with 16F1705's eeprom and DAC

    Hi Folks,

    First time use of subject PIC chosen for its inbuilt 8bit DAC. Code below runs but throws compile errors with:
    1 onboard eeprom (I'd really like to get this working).
    2 can't use binary to set FVRCON (decimal works fine). This isn't a big deal but why the error and what does it mean?

    Am I missing something obvious? I've RTFM but still scratching my head...

    Thanks,
    Bill

    Code:
    '*********************************************************************************
    '*  Name    : DACtest.pbp                                                        *
    '*  Date    : 16/07/20                                                           *
    '*  Device  : 16F1705                                                            *
    '*  Version : 1     (PBP 3.0.10.4)                                               *
    '*********************************************************************************
    '
    '=========================================================================================================
    '        CONFIGURE DEVICE
    '=========================================================================================================
    #CONFIG ; 16F1705
        __config _CONFIG1, _FOSC_INTOSC & _WDTE_ON & _PWRTE_ON & _MCLRE_ON & _CP_OFF & _BOREN_ON & _CLKOUTEN_OFF
        __config _CONFIG2, _WRT_OFF & _PPS1WAY_OFF & _ZCDDIS_OFF & _PLLEN_OFF & _STVREN_ON & _BORV_LO & _LPBOR_OFF & _LVP_OFF	   
    #ENDCONFIG
    
    ' Connections as follows:
    '     ****16F1705 PIC**** Comments
    '
    ' Vdd          (pin 1)    5 volts.      
    '         RA5  (pin 2)    T1clk.                Spare.       
    '         RA4  (pin 3)	  AN3, T1G.             Spare.
    ' MCLR    RA3  (pin 4)    IOC.  Pull High 10k.  Spare.
    '         RC5  (pin 5)	  Opamp2in+, CCP1.      Spare.
    '         RC4  (pin 6)    Opamp2in-.            Serout for monitoring (9600).
    '         RC3  (pin 7)    AN7, Opamp2Out, CCP2. Serin for setting from laptop (9600).      
    '         RC2  (pin 8)    AN6, Opamp1Out.       Spare.
    '         RC1  (pin 9)    AN5, Opamp1in-.       Spare.
    '         RC0  (pin 10)   AN4, Opamp1in+.       Spare.
    '         RA2  (pin 11)   AN2, DAC1out2.        Initial use with pot to adjust DAC output.
    ' ICSPclk RA1  (pin 12)   AN1, Vref+.           Spare.
    ' ICSPdat RA0  (pin 13)   AN0, DAC1out1.        Output voltage from DAC.
    ' Vss  Ground  (pin 14)   
    
    '=========================================================================================================
    '        PIN ASSIGNMENTS, SYSTEM CONSTANTS, TEMPORARY VARIABLES
    '=========================================================================================================
    ' Alias pins
    DAC1out     var     PortA.0     ' Output voltage from DAC via 1k.
    Iset        var    	PortA.2     ' Pot to adjust DAC output.
    in_pin      var     PortC.3     ' serial in via 22k.            
    out_pin     var     PortC.4     ' serial out via 1k.                
    
    '=========================================================================================================
    ' Variables
    '=========================================================================================================
    pott    var word                ' 10bit value from pot.
    Message var byte                '
    a       var byte                ' Loop counter. 
    
    '=========================================================================================================
    ' Constants
    '=========================================================================================================
     B96	CON	16468				' Baudmode for 9600,8,N,1 inverted.
     
    ' -----[ Initialization ]---------------------------------------------------------------- 
    ' Stored onboard E2... 
    '#### Message below brings:
    '[ERROR] dactest.pbp (58) : Syntax error
    '[MESSAGE] pic16f1705.pbpinc(351): HPWM command only supports CCP channels (not PWM channels).
    
    'Message Data "DACtest 16Jul20"
    
    '    Clear                       ' Reset all variables.
    
    	INCLUDE "modedefs.bas"		' Include serial modes.
    	
        DEFINE DEBUG_REG PORTC      ' Debug pin port.
        DEFINE DEBUG_BIT 4          ' Debug pin.
        DEFINE DEBUG_BAUD 9600      ' Debug baud rate
        DEFINE DEBUG_MODE 1         ' Debug mode: 0 = True, 1 = Inverted
    '    DEFINE DEBUG_PACING 1000    ' Debug character pacing in us
        DEFINE DEBUGIN_BIT 3        ' Input pin.
    
        DEFINE  OSC 4               ' Adjust to suit design.
        OSCCON  = %01101011         ' Internal 4MHz osc.
    '    OSCCON  = %01110011         ' Internal 8MHz osc.
    '    OSCCON  = %01111011         ' Internal 16MHz osc.
    '    OSCCON  = %11110011         ' Internal 32MHz osc PLL.
    
        OPTION_REG.7 = 1            ' Disable weak pullups.
    '    OPTION_REG.7 = 0            ' Enable weak pullups.
    
        DEFINE ADC_BITS 10          ' Set number of bits in result.
        DEFINE ADC_CLOCK 3          ' Set clock source (rc = 3).
        DEFINE ADC_SAMPLEUS 50      ' Set sampling time in microseconds. 
    
    '    ADCON0 = 0                  ' No ADC.
        ADCON0 = %00000001          ' Enable ADC.
        ADCON1 = %10000000          ' Right justify, Frc, use Vdd for Vref.
        ADCON2 = %00000000          ' No Trigger selects.
    
        ANSELA = %00000100          ' AN2 the rest Dig.
    '    ANSELA = 0                  ' Disable ADC.
        ANSELC = %00000000          ' All Dig.
    
        CM1CON0 = 0                  ' Comparators off.
    
    ' #### These Error if uncommented:
    '    FVRCON = $0                 ' Disabled.
    '    FVRCON = $11000101          ' Enabled, Vref 1.024V, DAC1out1 (RA0).
    '    DAC1CON0 = $10101000        ' Vref from FVR.
    '    DAC1CON1 = $10000000        ' Set initial output value to 50% of Vref.
    '[WARNING] dactest.pbp (100) : $11000101 Malformed binary numeric, value truncated
    '[WARNING] dactest.pbp (101) : $10101000 Malformed binary numeric, value truncated
    '[WARNING] dactest.pbp (102) : $10000000 Malformed binary numeric, value truncated
    '[MESSAGE] pic16f1705.pbpinc(351): HPWM command only supports CCP channels (not PWM channels).
    
    ' These compile okay:
        FVRCON = 197                ' Enabled, Vref 1.024V, DAC1out1 (RA0).
    '    FVRCON = 201                ' Enabled, Vref 2.048V, DAC1out1 (RA0).
    '    FVRCON = 205                ' Enabled, Vref 4.096V, DAC1out1 (RA0).
        DAC1CON0 = 168              ' Vref from FVR.
        DAC1CON1 = 128              ' Set initial output value to 50% of Vref.
        
        TRISA = %000100             ' A.2 pot input.
        TRISC = %001000             ' C.3 serial in.
    
        Pause 1000					' Short wait for things to settle.
    debug "I'm Alive!", 13,10       ' Eureka moment.
        pause 3000                  ' Time enough to gloat.
        goto First                  ' Jump subs.
    
    '=========================================================================================================
    ' Subroutines
    '=========================================================================================================
    
    '=========================================================================================================
    ' Main
    '=========================================================================================================
    First:  
        for a = 0 to 255 step 7 ' Some coarse jumps.
        DAC1CON1 = a
    debug "DAC = ",#a,13,10     ' 
        pause 2000              ' Let the DMM settle.
        next
        goto first              ' Cycle.
    
        end

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: Weirdness with 16F1705's eeprom and DAC

    1) This device doesn't have on board EEPROM. Instead it's using a specific section of "program memory" for the same purpose. I don't think I've played around with that feature but my guess would be to use WRITECODE/READCODE/ERASECODE. Since this type of memory is erased in blocks you can't overwrite a single a byte, instead you need to read out the block, erase the block, then write it back again with the single (or more obviously) values changed.

    Code:
    ' #### These Error if uncommented:
    '    FVRCON = $0                 ' Disabled.
    '    FVRCON = $11000101          ' Enabled, Vref 1.024V, DAC1out1 (RA0).
    '    DAC1CON0 = $10101000        ' Vref from FVR.
    '    DAC1CON1 = $10000000        ' Set initial output value to 50% of Vref.
    2) When writing numbers in binary you need to put a %-sign in front of it - not a $-sign which is used for hexadecimal. FVRCON = $0 would work though, are you saying it won't compile with that either?

  3. #3
    Join Date
    Oct 2011
    Posts
    54


    Did you find this post helpful? Yes | No

    Default Re: Weirdness with 16F1705's eeprom and DAC

    Yes it is something obvious


    ' FVRCON = $11000101 ' Enabled, Vref 1.024V, DAC1out1 (RA0).
    should be
    FVRCON = %11000101

    Phil

  4. #4
    Join Date
    May 2013
    Location
    australia
    Posts
    2,389


    Did you find this post helpful? Yes | No

    Default Re: Weirdness with 16F1705's eeprom and DAC

    bill you might get some use from this re hef as eeprom

    http://support.melabs.com/forum/picb...-accessing-hef
    Warning I'm not a teacher

  5. #5
    Join Date
    Jun 2005
    Location
    West Australia
    Posts
    116


    Did you find this post helpful? Yes | No

    Default Re: Weirdness with 16F1705's eeprom and DAC

    Doh! Oh dear how basic a mistake is that?

    I'm feeling very red-faced now for missing the obvious. I think a case of not seeing the forest with the trees in the way...

    Thanks folks for showing me the way, TBH digging deeper shows these HEF chips have been around a while now and I'm surprised the PBPro improvement team (is there one?) haven't written anything to access HEF seamlessly - if I'm wrong please correct me.

    Richard, check your in box I'll send you a PM shortly.

    Cheers, stay safe,
    Bill

  6. #6
    Join Date
    Jun 2005
    Location
    West Australia
    Posts
    116


    Did you find this post helpful? Yes | No

    Default Re: Weirdness with 16F1705's DAC

    Hi Folks,

    I went ahead and made a pcb for the application and during layout decided to use the alternate DAC output of RA2 instead of RA0 to keep it free for ICSP.

    Of course after etching and populating the pcb I have some nonsense happening on RA2 despite correctly reconfiguring the DAC registers (at least I think so!). The code below compiles, loads and runs correctly when configured for RA0 but RA2 Sits at 2.277V with RA0 running correctly. When set for RA2 it sits about 700mV varying slightly and RA0 is at 0V as you'd expect.

    Have I missed something or am I having another senior's moment? While I can hack my pcb to achieve a solution using RA0 I'd like to have the option of being able to use RA2 as it was intended.

    Thanks, stay safe,
    Bill

    Code:
    
    '*********************************************************************************
    '*  Name    : DACtest.pbp                               #### 1/2 Working code ####   *
    '*  Date    : 02/08/20                                                           *
    '*  Device  : 16F1705                                                            *
    '*  Version : 1     (PBP 3.0.10.4)                                               *
    '*********************************************************************************
    '
    '=========================================================================================================
    '        CONFIGURE DEVICE
    '=========================================================================================================
    #CONFIG ; 16F1705
        __config _CONFIG1, _FOSC_INTOSC & _WDTE_ON & _PWRTE_ON & _MCLRE_ON & _CP_OFF & _BOREN_ON & _CLKOUTEN_OFF
        __config _CONFIG2, _WRT_OFF & _PPS1WAY_OFF & _ZCDDIS_OFF & _PLLEN_OFF & _STVREN_ON & _BORV_LO & _LPBOR_OFF & _LVP_OFF	   
    #ENDCONFIG
    
    ' Connections as follows:
    '     ****16F1705 PIC**** Comments
    '
    ' Vdd          (pin 1)    5 volts.      
    '         RA5  (pin 2)    T1clk.                Spare.       
    '         RA4  (pin 3)	  AN3, T1G.             Spare.
    ' MCLR    RA3  (pin 4)    IOC.  Pull High 10k.  Spare.
    '         RC5  (pin 5)	  Opamp2in+, CCP1.      Spare.
    '         RC4  (pin 6)    Opamp2in-.            Serin for setting from laptop (9600).
    '         RC3  (pin 7)    AN7, Opamp2Out, CCP2. Serout for monitoring (9600).      
    '         RC2  (pin 8)    AN6, Opamp1Out.       Spare.
    '         RC1  (pin 9)    AN5, Opamp1in-.       Spare.
    '         RC0  (pin 10)   AN4, Opamp1in+.       Spare.
    '         RA2  (pin 11)   AN2, DAC1out2.        DAC alternate output.
    ' ICSPclk RA1  (pin 12)   AN1, Vref+.           Spare.
    ' ICSPdat RA0  (pin 13)   AN0, DAC1out1.        Default output voltage from DAC.
    ' Vss  Ground  (pin 14)   
    
    '=========================================================================================================
    '        PIN ASSIGNMENTS, SYSTEM CONSTANTS, TEMPORARY VARIABLES
    '=========================================================================================================
    ' Alias pins
    
    '=========================================================================================================
    ' Variables
    '=========================================================================================================
    a   var byte                    ' Loop counter. 
    
    '=========================================================================================================
    ' Constants
    '=========================================================================================================
     
    ' -----[ Initialization ]---------------------------------------------------------------- 
    
    '    Clear                       ' Reset all variables.
    
    	INCLUDE "modedefs.bas"		' Include serial modes.
    	
        DEFINE DEBUG_REG PORTC      ' Debug pin port.
        DEFINE DEBUG_BIT 3          ' Debug pin.
        DEFINE DEBUG_BAUD 9600      ' Debug baud rate
        DEFINE DEBUG_MODE 1         ' Debug mode: 0 = True, 1 = Inverted
    '    DEFINE DEBUG_PACING 1000    ' Debug character pacing in us
        DEFINE DEBUGIN_BIT 4        ' Input pin.
    
        DEFINE  OSC 4               ' Adjust to suit design.
        OSCCON  = %01101011         ' Internal 4MHz osc.
    '    OSCCON  = %01110011         ' Internal 8MHz osc.
    '    OSCCON  = %01111011         ' Internal 16MHz osc.
    '    OSCCON  = %11110011         ' Internal 32MHz osc PLL.
    
        OPTION_REG.7 = 1            ' Disable weak pullups.
    '    OPTION_REG.7 = 0            ' Enable weak pullups.
    
    '    DEFINE ADC_BITS 10          ' Set number of bits in result.
    '    DEFINE ADC_CLOCK 3          ' Set clock source (rc = 3).
    '    DEFINE ADC_SAMPLEUS 50      ' Set sampling time in microseconds. 
    
        ADCON0 = 0                  ' No ADC.
    '    ADCON0 = %00000001          ' Enable ADC.
    '    ADCON1 = %10000000          ' Right justify, Frc, use Vdd for Vref.
    '    ADCON2 = %00000000          ' No Trigger selects.
    
        ANSELA = 0                  ' Disable ADC.
    '    ANSELA = %00000100          ' AN2 the rest Dig.
    '    ANSELC = %00000000          ' All Dig.
    
        CM1CON0 = 0                  ' Comparators off.
    
    '    FVRCON = %0                 ' Disabled.
        FVRCON = %11000101          ' Enabled, Vref 1.024V.
    '    DAC1CON0 = %10101000        ' Vref from FVR, DAC1out1 (RA0).
    '=========================================================================================================
    ' ####### RA2 Sits at 2.277V with RA0 selected and running correctly.
        DAC1CON0 = %10011000        ' Vref from FVR, DAC1out2 (RA2).  
    '=========================================================================================================
    '    DAC1CON0 = %10111000        ' Vref from FVR, both outputs (RA0, RA2).  [Not sure if this is possible]
        DAC1CON1 = %10000000        ' Set initial output value to 50% of Vref.
    
        TRISA = %000000             ' All output.
        TRISC = %010000             ' C.4 serial in.
    
        latC.3 = 0                  ' Else first serial chars can be garbled...
        Pause 1000					' Short wait for things to settle.
    debug "I'm Alive!", 13,10       ' Eureka moment.
        pause 3000                  ' Time enough to gloat.
        goto First                  ' Jump subs.
    
    '=========================================================================================================
    ' Subroutines
    '=========================================================================================================
    
    '=========================================================================================================
    ' Main
    '=========================================================================================================
    First:  
        for a = 0 to 255 step 7 ' Some coarse jumps.
        DAC1CON1 = a
    debug "DAC = ",#a,13,10     ' 
        pause 2000              ' Let the DMM settle.
        next
        goto first              ' Cycle.
    
        end

  7. #7
    Join Date
    Apr 2014
    Location
    OK
    Posts
    557


    Did you find this post helpful? Yes | No

    Default Re: Weirdness with 16F1705's eeprom and DAC

    Try ANSELA = 5 ;%00000101, Configures RA0 & RA2 as Analog

Similar Threads

  1. Select Case Weirdness
    By rocket_troy in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 19th June 2014, 00:33
  2. Ti Dac 7553
    By GeoJoe in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 28th August 2008, 20:29
  3. Looking for a DAC
    By RussMartin in forum Off Topic
    Replies: 4
    Last Post: - 25th November 2007, 06:21
  4. Using DAC's with pics
    By J_norrie in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 27th March 2007, 14:00
  5. dac
    By kaisersystems in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 10th June 2005, 20:23

Members who have read this thread : 1

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

Posting Permissions

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