Cos'è ElectroYou | Login Iscriviti

ElectroYou - la comunità dei professionisti del mondo elettrico

mplabx e xc8 problemi con libreria adc

Raccolta di codici sorgenti

Moderatore: Foto UtentePaolino

0
voti

[1] mplabx e xc8 problemi con libreria adc

Messaggioda Foto Utentelcua31989 » 12 apr 2015, 17:12

Ciao a tutti,

finalmente ho fatto il grande passo a convertirmi con l'ambiente di sviluppo MPLAB X installando il compilatore xc8. Dopo la corretta installazione dei software IDE e IPE ho fatto le seguenti configurazioni:

1) Tools --> option --> embedded: ho cliccato scanfor bulid tools ed ha aggiunto il compilatore xc8 quando creo il nuovo programma.
2) Ho creato il primo progetto e ho messo la path delle librerie in: File --> Project property --> Xc8 Compiler --> Include directories --> messo la path C:\Program Files (x86)\Microchip\xc8\v1.34\include\plib --> ok --> apply.

Con questa ultima modifica riesco ad importare correttamente la liberia adc.h, ma quando provo a usare uno dei suoi metodi dichiarati e compilo viene fuori l'errore che non può trovare il metodo anche se esso è dichiarato nel file adc.h. Non contento ho provato lo stesso ad usare il metodo "OpenADC(ADC_FOSC_2 & ADC_RIGHT_JUST & ADC_20_TAD, ADC_CH0 & ADC_INT_ON & ADC_VREFPLUS_VDD & ADC_VREFMINUS_VSS, ADC_0ANA);" ma ottengo una bellissima sottolineatura rossa per tutto ad ecezzione della costante "ADC_RIGHT_JUST".

Ad ogni modo allego il mio progetto:

MAIN
Codice: Seleziona tutto
/******************************************************************************/
/* Files to Include                                                           */
/******************************************************************************/


#include <xc.h>         /* XC8 General Include File */

#include "system.h"        /* System funct/params, like osc/peripheral config */
#include "user.h"          /* User funct/params, such as InitApp */

#include <stdint.h>        /* For uint8_t definition */
#include <stdbool.h>       /* For true/false definition */

#include <adc.h>

/******************************************************************************/
/* User Global Variable Declaration                                           */
/******************************************************************************/

/* i.e. uint8_t <variable_name>; */

/******************************************************************************/
/* Main Program                                                               */
/******************************************************************************/

void main(void)
{
    /* Configure the oscillator for the device */
    ConfigureOscillator();

    /* Initialize I/O and Peripherals for application */
    InitApp();

    OpenADC(ADC_FOSC_2 & ADC_RIGHT_JUST & ADC_20_TAD, ADC_CH0 & ADC_INT_ON & ADC_VREFPLUS_VDD & ADC_VREFMINUS_VSS, ADC_0ANA);

    while(1)
    {
      ;
    }

}


USER
Codice: Seleziona tutto
/******************************************************************************/
/* Files to Include                                                           */
/******************************************************************************/

#include <xc.h>         /* XC8 General Include File */

#include <stdint.h>         /* For uint8_t definition */
#include <stdbool.h>        /* For true/false definition */

#include "user.h"

/******************************************************************************/
/* User Functions                                                             */
/******************************************************************************/

/* <Initialize variables in user.h and insert code for user algorithms.> */

void InitApp(void)
{
    APFCON = 0B00100001; //RX=RA1, CWGOUTA=RA2, CWGOUTB=RA4, T1G=RA3, TX=RA0,
                          //P2SEL=RA0, P1SEL=RA5

    OPTION_REG = 0B11000000;

    TRISA = 0B00000100;  //Program all pins as output except the RA2 as input
    ODCONA = 0B00000000; //No open drain pins are required
    SLRCONA = 0B00000000; //No baud rate limits are required
    INLVLA = 0B00000000; //TTL imputs are enabled when on change interrupt match
    ANSELA = 0B00000100; //Program RA2 as analog input
    WPUA = 0B00000000;   //No pull up resistors are required
    PORTA = 0B00000000;  // Clear PortA
    LATA = 0B00000000;   // Clear LatA

    INTCON = 0B00000000; //Disable all interrupts
    IOCAP = 0B00000000; //Interrupt on change are disable of all imputs pins
    IOCAN = 0B00000000; //Interrupt disable for the associated pin
    IOCAF = 0B00000000; //Clear interrupts request

    FVRCON = 0B11000010; //FVR = enabled, DAC = disable, ADFVR = 2.048 V

    ADCON0 = 0B00001001; //ADC from AN2, adc not in progress, adc module en.
    ADCON1 = 0B10000011; //ADRSEH = 8 bit significant, FOSC/2,
                          //FVR = selected for ADC module
    ADCON2 = 0B00000000; //As default to the datasheet

    DACCON0 = 0B00000000; //DAC is disabled

    CM1CON0 = 0B00000000; //Comparators are disabled
    CM1CON1 = 0B00000000; //As default

    TXSTA = 0B00000000;   //As default
    RCSTA = 0B00000000;   //Disable EUSART module

    PWM1CON = 0B00000000; //Disable PWM 1 modules
    PWM2CON = 0B00000000; //Disable PWM 2 modules
    PWM3CON = 0B00000000; //Disable PWM 3 modules

    CWG1CON0 = 0B00000000; //Disable CWG modules
}


SYSTEM

Codice: Seleziona tutto
/******************************************************************************/
/* Files to Include                                                           */
/******************************************************************************/

#include <xc.h>         /* XC8 General Include File */

#include <stdint.h>        /* For uint8_t definition */
#include <stdbool.h>       /* For true/false definition */

#include "system.h"

/* Refer to the device datasheet for information about available
oscillator configurations and to compiler documentation for macro details. */
void ConfigureOscillator(void)
{

    /*If the PIC12 device has an OSCCAL value, the HiTech Compiler provides
    a macro called _READ_OSCCAL_DATA which can be loaded using this: */

    /* TODO Configure OSCCAL if the device has an OSCCAL register */

#if 0

    OSCCAL=_READ_OSCCAL_DATA(); /* _READ_OSCCAL_DATA macro unloads cal memory */

#endif

    /*Not all PIC12 devices require this.

    /* TODO Add clock switching code if appropriate.  */

    /* Typical actions in this function are to tweak the oscillator tuning
    register, select new clock sources, and to wait until new clock sources
    are stable before resuming execution of the main project. */

    OSCCON = 0B01111000; //PLL = disable, clock = 16 MHz, Internal block en.
    OSCTUNE = 0B00000000; //Oscillator is running as factory calibration
    OSCSTAT = 0B00000000; //They are control bits, as well see datasheet

}


CONFIGURATION BIT

Codice: Seleziona tutto
/******************************************************************************/
/* Main Files to Include                                                      */
/******************************************************************************/


#include <htc.h>        /* HiTech General Include File */


/******************************************************************************/
/* Configuration Bits                                                         */
/*                                                                            */
/* Refer to your Hi-Tech User Manual in the PICC installation directory       */
/* /doc folder for more information on filling in configuration bits.         */
/* In addition, configuration bit mnemonics can be found in your              */
/* PICC\version\include\<processor name>.h file for your device.  The XC8     */
/* compiler contains documentation on the configuration bit macros within     */
/* the compiler installation /docs folder in a file called                    */
/* pic18_chipinfo.html.                                                       */
/*                                                                            */
/* For additional information about what the hardware configurations mean in  */
/* terms of device operation, refer to the device datasheet.                  */
/*                                                                            */
/* A feature of MPLAB X is the 'Generate Source Code to Output' utility in    */
/* the Configuration Bits window.  Under Window > PIC Memory Views >          */
/* Configuration Bits, a user controllable configuration bits window is       */
/* available to Generate Configuration Bits source code which the user can    */
/* paste into this project.                                                   */
/*                                                                            */
/******************************************************************************/

/* TODO Fill in your config bits here.  Use the configuration bits generator. */

// CONFIG1
#pragma config FOSC = INTOSC    //  (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)

// CONFIG2
#pragma config WRT = OFF        // Flash Memory Self-Write Protection (Write protection off)
#pragma config PLLEN = OFF      // PLL Enable (4x PLL disabled)
#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 LPBOREN = OFF    // Low Power Brown-out Reset enable bit (LPBOR is disabled)
#pragma config LVP = ON         // Low-Voltage Programming Enable (Low-voltage programming enabled)


Sapete se c'è qualche altro settaggio che ignoro da qualche parte?
Come posso risolvere senza dovermi fare la libreria da capo?

Grazie a tutti,
ciao lcua31989
Avatar utente
Foto Utentelcua31989
58 1 1 7
Frequentatore
Frequentatore
 
Messaggi: 194
Iscritto il: 28 nov 2012, 23:37

0
voti

[2] Re: mplabx e xc8 problemi con libreria adc

Messaggioda Foto Utentebobina » 12 apr 2015, 20:04

Che PIC stai usando?
Le librerie plib sono disponibili solo per i PIC della serie PIC18 e quindi per le famiglie 10, 12 e 16 supportati dal compilatore XC8 non hai il supporto delle PLIB, comunque hai la possibilità di ricompilarle partendo dai sorgenti che la microchip mette a disposizione.
Qui qualcuno ha già affrontato il problema.
Avatar utente
Foto Utentebobina
212 6
Frequentatore
Frequentatore
 
Messaggi: 177
Iscritto il: 27 dic 2009, 14:22

0
voti

[3] Re: mplabx e xc8 problemi con libreria adc

Messaggioda Foto Utentelcua31989 » 12 apr 2015, 20:08

Ciao,


Il PIC che sto usando è il 12f1572.

Cos'è il supporto a plib?

Ciao
lcua31989
Avatar utente
Foto Utentelcua31989
58 1 1 7
Frequentatore
Frequentatore
 
Messaggi: 194
Iscritto il: 28 nov 2012, 23:37

0
voti

[4] Re: mplabx e xc8 problemi con libreria adc

Messaggioda Foto Utentebobina » 12 apr 2015, 20:23

plib è l'abbreviazione di Peripheral Library e sono le librerie messe a disposizione dalla Microchip per implementare delle funzioni di utilizzo dell'hardware dei PIC.
Dentro la directory di installazione del compilatore XC8 dovresti avere una directory sources e qui hai
.\pic18\plib\ADC\adcopen.c dove trovi il sorgente della funzione che stai usando, dovrai importare anche questo nel tuo progetto e provare a compilare.
Avatar utente
Foto Utentebobina
212 6
Frequentatore
Frequentatore
 
Messaggi: 177
Iscritto il: 27 dic 2009, 14:22

0
voti

[5] Re: mplabx e xc8 problemi con libreria adc

Messaggioda Foto Utentelcua31989 » 12 apr 2015, 21:28

Ciao,

ho dato un occhiata al documento che mi hai linkato, credo che il problema sia un po differente, da quanto ho capito a lui non compilava correttamente perché ometteva delle istruzioni da preinserire prima di includere la libreria stessa. Ho capito giusto?

Ciao
lcua31989
Avatar utente
Foto Utentelcua31989
58 1 1 7
Frequentatore
Frequentatore
 
Messaggi: 194
Iscritto il: 28 nov 2012, 23:37

0
voti

[6] Re: mplabx e xc8 problemi con libreria adc

Messaggioda Foto Utentebobina » 12 apr 2015, 21:51

A me sembra il tuo stesso problema solo che lui usa le funzioni I2C mentre a te serve ADC.
L'errore che ricevi non è "error: undefined symbols:" oppure non trova la funzione dentro il file adc.h?
Se vedi nel file adc.h ci sono delle #if defined con le versioni ADC_VXX, solo che queste define vengono definite solo per i PIC18.
Magari l'errore è leggermente differente ma il problema è lo stesso le PLIB non si possono usare con microcontrollori diversi dal PIC18 a meno che non prendi i sorgenti e li includi nel tuo progetto cercando di adattarli alle tue esigenze.
Avatar utente
Foto Utentebobina
212 6
Frequentatore
Frequentatore
 
Messaggi: 177
Iscritto il: 27 dic 2009, 14:22


Torna a Firmware e programmazione

Chi c’è in linea

Visitano il forum: Nessuno e 3 ospiti