Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] PIC18F25Q10 A/D module functionality

Status
Not open for further replies.

HasHx

Member level 4
Member level 4
Joined
Oct 17, 2016
Messages
78
Helped
14
Reputation
28
Reaction score
14
Trophy points
1,288
Activity points
1,925
Hello everyone,

I am using a PIC18F25Q10-I/SP MCU in one of my designs and one of its main function is to read a changing value of 0-5v coming from an inverting Op-Amp.

the input is tested before with a different MCU and is working properly but when it's connected to the bespoke MCU it malfunctions and gets stuck at 5v DC andthe MCU would Reset if we short any signal to the A/D pin (e.g. trying to touch the pin with 5v signal).

I am not sure but i am assuming this is a software issue, am I right with this? has anyone came across something similar?

Thanks.
 
Hi,

No schematic, no code... impossible to give good assistance.

Klaus
 

Hi, here is the code we wrote for this:

C:
/**
* Initialization routine
*/
void init(void)
{
#ifdef _PIC16F876A_H_   
    // Conversion Clock:
    // Fosc/2:000
    // Fosc/4:100
    // Fosc/8:001
    // Fosc/16:101
    // Fosc/32:010
    // Fosc/64:110
    // must be selected to ensure a minimum TAD time of 1.6 �s.
    ADCS0 = 0;
    ADCS1 = 1;
    ADCS2 = 1;

    // PCFG 0000 -> All analog
    // PCFG 0001 -> All analog Vref+ @ AN3
#ifdef EXTERNAL_REF
    PCFG0 = 1;
#else
    PCFG0 = 0; // 1;
#endif
    PCFG1 = 0;
    PCFG2 = 0;
    PCFG3 = 0; // 1;
#elif defined(_PIC18F25Q10_H_)
#ifdef EXTERNAL_REF
    ADREFbits.ADPREF = 2;       //VREF+ is connected external reference
#else
    ADREFbits.ADPREF = 0;       //VREF+ is connected to VDD
#endif
    ADREFbits.ADNREF = 0; // VREF- is connected to AVSS

    ADCON0bits.ADCS =   0;       //Clock supplied by Fosc, divided according to ADCLK register
    ADCLK           =   0x1F;    //ADC Clock frequency = FOSC/(2*(ADCLK+1))

    TRISAbits.TRISA0 = 1;
    ANSELAbits.ANSELA0 = 1;
#endif

    // Left Justified = 0
    // Right justified = 1
#ifdef RIGHT_JUSTIFIED
    ADFM = 1;
#else
    ADFM = 0;
#endif
    
    GIE = 1;
    PEIE = 1;
    PIE1bits.ADIE = 1;
}

/**
* A/D Reading ISR
*/
void ISR() {
    if ( PIR1bits.ADIF ) {
        reading =
#ifdef RIGHT_JUSTIFIED
        ((ADRESH << 8) | ADRESL)
#else
        ((ADRESH << 2) | (ADRESL >> 6))
#endif
        ;

        ADCON0bits.ADON = 0;
        PIR1bits.ADIF = 0;
    }
}

/**
* Start reading routine
*/
void readThisChannel(uint8_t channel) {
#ifdef _PIC16F876A_H_
    PCFG0            = 0;          // Internal reference
    ADCON0bits.CHS   = channel;
#elif defined(_PIC18F25Q10_H_)
    ADREFbits.ADPREF = 0x0;
    ADPCH            = channel;    //ADC Positive Input Channel Selections
#endif

    ADCON0bits.ADON  = 1;          //Enable ADC module
    ADCON0bits.GO    = 1;          //Start conversion
}

--- Updated ---


And the schematic is attached, the input is supposed to be a single value between 0 and 5v.

Thanks in advance.
 

Attachments

  • shock_sensor 3p1.pdf
    77.9 KB · Views: 138
Last edited by a moderator:

Hi,

strange schematic.

some issues:
* driving VRef from a 2.5KOhms source is rather optimistc.
* driving VRef without a capacitor to GND is a non go ( for me)
* driving Vref from another 5V source than the microcontroller supply needs careful power sequencing, else you violate input voltage range
* ADC input from another source than the microcontroller supply needs careful power sequencing, else you violate input voltage range
* ADC input can be negative (I see it should not happen in normal operating mode), it might violate input voltage range

code:
we don´t see the main loop, thus you need to check it on your own.
we dont see all the compiler setting variable values, thus you need to check them on your own.
we don´t see port setup, thus you need to check it on your own: especially
* Analog inputs (all)
* VRef input
* don´t leave any (unused) input floating. Neither digital ones nor analog ones.

It seems to be code from a code generator. You may omit all the "complier IFs" and shorten code to make it more readable.

Sadly with the given informations it´s hard to help.

Klaus
 

Hello,


SHOCK signal coms from an AOP witch has symetrical power supply
but RA0 AN0 can't measure negatives DC value !
a Rail to rail AOP could be better , even don't reach excatly Zero Volt..

it seems LOW BAT is used for comparator
compare with what ?
RA0 Analog value ?
RA3 is used for +VREF ? replaced by +VREF=+VDD

to test your RA0 analog input , begin to test with a Pot , like Pot R33
to separate problems from the analogue parts..

I did some test on a Curiosity nano board wit a PIC18F47Q10 , near same family as 25Q10
ADC is very much more sofisticate , more complex with a lot of additional functions
i tested first with classic ADC use .. and get results ...OK
MPLABX MCC is a powerfull tools/ Help for that.
Have a look on this simple project ..
 

Hi,

strange schematic.

some issues:
* driving VRef from a 2.5KOhms source is rather optimistc.
* driving VRef without a capacitor to GND is a non go ( for me)
* driving Vref from another 5V source than the microcontroller supply needs careful power sequencing, else you violate input voltage range
* ADC input from another source than the microcontroller supply needs careful power sequencing, else you violate input voltage range
* ADC input can be negative (I see it should not happen in normal operating mode), it might violate input voltage range

Hello,

Regarding schematic issues, we had this same schematic setup done to a different MCU:pIC16F876A-ISP (Schematic attached), it worked just fine! now I am just trying to upgrade the MCU and got too many problems.

Some points we can do for the design to improve such as points 2,3 and 4.
for point 5 we are aware of this and we plan to fix this in future versions.

I don't get your first point.
--- Updated ---

code:
we don´t see the main loop, thus you need to check it on your own.
we dont see all the compiler setting variable values, thus you need to check them on your own.
we don´t see port setup, thus you need to check it on your own: especially
* Analog inputs (all)
* VRef input
* don´t leave any (unused) input floating. Neither digital ones nor analog ones.

It seems to be code from a code generator. You may omit all the "complier IFs" and shorten code to make it more readable.

Sadly with the given informations it´s hard to help.

Klaus

these are the flags
The code posted before is not auto-generated, but we have posted code for both PICs so you can see the differences, and the conversion is done using ISR


#ifdef PIC16F876A_H
#pragma config FOSC = HS // Oscillator Selection bits (HS oscillator)
#pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
#elif defined(PIC18F25Q10_H)
#pragma config WRTD = OFF // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
#pragma config FEXTOSC = HS // Oscillator Selection bits (HS oscillator)
#pragma config XINST = OFF // Use extended instructions set
#pragma config LVP = OFF // Low-voltage programming disabled
#pragma config WRTB = ON // Boot Block write protected (1 = not write protected)
#endif
// Common configs
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT enabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = OFF // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = OFF // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
#pragma config CPD = OFF // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)
--- Updated ---

Hello,


SHOCK signal coms from an AOP witch has symetrical power supply
but RA0 AN0 can't measure negatives DC value !
a Rail to rail AOP could be better , even don't reach excatly Zero Volt..

it seems LOW BAT is used for comparator
compare with what ?
RA0 Analog value ?
RA3 is used for +VREF ? replaced by +VREF=+VDD

to test your RA0 analog input , begin to test with a Pot , like Pot R33
to separate problems from the analogue parts..

I did some test on a Curiosity nano board wit a PIC18F47Q10 , near same family as 25Q10
ADC is very much more sofisticate , more complex with a lot of additional functions
i tested first with classic ADC use .. and get results ...OK
MPLABX MCC is a powerfull tools/ Help for that.
Have a look on this simple project ..

Hi,

AN0 does not read negative and it is not supposed to do that, so it's cool for us and as i mentioned we are working on a better version.


Low Bat indicates battery voltage level, it is not a comparator input, we use the voltage divider to make the MCU capable of reading the battery voltage level.

RA0 is analog yes.

We use Vref for calibrating using a Pot.

we will try your suggestions, thanks.
 

Attachments

  • SHOCK_SENSOR.pdf
    190 KB · Views: 113
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top