Weirdness with 16F1705's eeprom and DAC


Results 1 to 14 of 14

Threaded View

  1. #12
    Join Date
    May 2013
    Location
    australia
    Posts
    2,386


    Did you find this post helpful? Yes | No

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

    theres more to than i first thought.
    i tried the microchip example in mplabx , guess what both pins are exactly equal and produce the exact predicted output by the datasheet,
    we are missing something

    Code:
    #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
    
    
    counts   var byte                    ' Loop counter. 
    
    
    
    
    
    
        DEFINE  OSC 4               ' Adjust to suit design.
        OSCCON  = $68         ' Internal 4MHz osc.
    
    
    
    
        ANSELA = 0
        ANSELC = 0       
    
    
    
    
    
    
    ' ####### RA2 Sits at 2.277V with RA0 selected and running correctly.
        DAC1CON0 = %10110000        ' Vref from FVRb2, DAC1out2 (RA2).  
    
    
       
      
    
    
        
    
    
    
    
    First:  
        for counts= 0 to 250
        DAC1CON1 = counts
        pause 5            ' Let the DMM settle.
       next
        goto first              
    
    
        end

    Code:
    void main(void){
        // initialize the device
        SYSTEM_Initialize();
    
    
        // When using interrupts, you need to set the Global and Peripheral Interrupt Enable bits
        // Use the following macros to:
    
    
        // Enable the Global Interrupts
        //INTERRUPT_GlobalInterruptEnable();
    
    
        // Enable the Peripheral Interrupts
        //INTERRUPT_PeripheralInterruptEnable();
    
    
        // Disable the Global Interrupts
        //INTERRUPT_GlobalInterruptDisable();
    
    
        // Disable the Peripheral Interrupts
        //INTERRUPT_PeripheralInterruptDisable();
     uint8_t count=0;
    
    
        
        while (1)
        {
                    for(count=0; count<=250; count++)
            {
                DAC_SetOutput(count);
                __delay_ms(5);
    
    
            }
        }
    }
    /**
     End of File
    
    void DAC_Initialize(void)
    {
        // DAC1EN enabled; DAC1NSS VSS; DAC1PSS VDD; DAC1OE1 enabled; DAC1OE2 enabled; 
        DAC1CON0 = 0xB0;
        // DAC1R 51; 
        DAC1CON1 = 0x33;
    }
    
    
    void DAC_SetOutput(uint8_t inputData)
    {
        DAC1CON1  = inputData;
    }
    
    
    uint8_t DAC_GetOutput(void)
    {
        return DAC1CON1;
    }
    
    
    // CONFIG1
    #pragma config FOSC = INTOSC    // Oscillator Selection Bits->INTOSC oscillator: I/O function on CLKIN pin
    #pragma config WDTE = OFF    // Watchdog Timer Enable->WDT disabled
    #pragma config PWRTE = OFF    // Power-up Timer Enable->PWRT disabled
    #pragma config MCLRE = ON    // MCLR Pin Function Select->MCLR/VPP pin function is MCLR
    #pragma config CP = OFF    // 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 ZCDDIS = ON    // Zero-cross detect disable->Zero-cross detect circuit is disabled at POR  the culprit
    #pragma config PLLEN = OFF    // Phase Lock Loop enable->4x PLL is enabled when software sets the SPLLEN bit
    #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 = OFF    // Low-Power Brown Out Reset->Low-Power BOR is disabled
    #pragma config LVP = ON    // Low-Voltage Programming Enable->Low-voltage programming enabled
    
    
    
    
    void PIN_MANAGER_Initialize(void)
    {
        /**
        LATx registers
        */
        LATA = 0x00;
        LATC = 0x00;
    
    
        /**
        TRISx registers
        */
        TRISA = 0x37;
        TRISC = 0x3F;
    
    
        /**
        ANSELx registers
        */
        ANSELC = 0x3F;
        ANSELA = 0;//0x17;
    
    
        /**
        WPUx registers
        */
        WPUA = 0x00;
        WPUC = 0x00;
        OPTION_REGbits.nWPUEN = 1;
    
    
        /**
        ODx registers
        */
        ODCONA = 0x00;
        ODCONC = 0x00;
    
    
        /**
        SLRCONx registers
        */
        SLRCONA = 0x37;
        SLRCONC = 0x3F;
    
    
        /**
        INLVLx registers
        */
        INLVLA = 0x3F;
        INLVLC = 0x3F;
    
    
    
    
    
    
    
    
    
    
       
        
    }
      
    void SYSTEM_Initialize(void)
    {
    
    
        PIN_MANAGER_Initialize();
        OSCILLATOR_Initialize();
        WDT_Initialize();
        DAC_Initialize();
    }
    
    
    void OSCILLATOR_Initialize(void)
    {
        // SCS FOSC; SPLLEN disabled; IRCF 4MHz_HF; 
        OSCCON = 0x68;
        // SOSCR disabled; 
        OSCSTAT = 0x00;
        // TUN 0; 
        OSCTUNE = 0x00;
        // SBOREN disabled; BORFS disabled; 
        BORCON = 0x00;
    }
    
    
    void WDT_Initialize(void)
    {
        // WDTPS 1:65536; SWDTEN OFF; 
        WDTCON = 0x16;
    }
    Last edited by richard; - 5th August 2020 at 05:04.
    Warning I'm not a teacher

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