View previous topic :: View next topic |
Author |
Message |
pet007
Joined: 25 Jan 2023 Posts: 21
|
18F16Q41 - AD converter issue (solved - pin damage) |
Posted: Sun Feb 11, 2024 11:41 am |
|
|
Hi, I'm a bit confused to setup ADC for the "new gen" PIC family.
So even if I define a whole ADC sample/convert procedure via 'getenv' SFR byte(+bits), I'm not able to convert ANC3 (RC3) channel. When I try to convert Internal Temp Sensor - it's working fine. Please where should be a problem ? It seems there is some issue with switching RC3 to analog input ?
Code: |
#include <main.h>
/*
main.h:
#device PIC18F16Q41 ADC=12
*/
#bit ADCON0GObit = getenv("SFR:ADCON0").0;
#bit ADCON0FMbit = getenv("SFR:ADCON0").2;
#bit ADCON0CSbit = getenv("SFR:ADCON0").4;
#bit ADCON0ONbit = getenv("SFR:ADCON0").7;
#byte ANSELA = getenv("SFR:ANSELA");
#byte ANSELC = getenv("SFR:ANSELC");
#byte ADPCH = getenv("SFR:ADPCH");
#byte ADACQL = getenv("SFR:ADACQL");
#byte ADACQH = getenv("SFR:ADACQH");
#byte ADRESH = getenv("SFR:ADRESH");
#byte ADRESL = getenv("SFR:ADRESL");
#byte FVRCON = getenv("SFR:FVRCON");
u16 pwm=0, adc16=0;
void main
{
set_tris_a(0b00111110);
set_tris_b(0b00010000);
set_tris_c(0b00111111);
ANSELA = 0b00111000;
ANSELC = 0b00001000;
//set_analog_pins(PIN_C3,PIN_A4,PIN_A5);
//setup_adc_ports(sAN4 | sAN5 | sAN19);
FVRCON = 0b00100000; // Temp sensor enabled
ADCON0FMbit = 1;
ADCON0CSbit = 1;
// ADPCH = 19; // ANC3 / RC3
ADPCH = 0b00111100; // Internal Temp Sensor - OK
ADACQH = 0; ADACQL = 32;
ADCON0ONbit = 1;
while(TRUE)
{
ADCON0GObit = 1;
while (ADCON0GObit);
adc16 = (ADRESH << 8);
adc16 += ADRESL;
//set_adc_channel(19);
//adc16 = read_adc();
delay_ms(1000);
fprintf(PORT1,"ADC= %Lu\r",adc16); //ADRESH, ADRESL);
} // while1
} |
Last edited by pet007 on Mon Feb 12, 2024 2:21 pm; edited 1 time in total |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Sun Feb 11, 2024 12:02 pm |
|
|
Read note 6 on the data sheet. Section 40.7.7. That connection does not
connect to the pin it connects to the op amp. You have to configure this.
Also you should not select a channel and then immediately read. Min about
5uSec between a selection and the read. |
|
|
pet007
Joined: 25 Jan 2023 Posts: 21
|
|
Posted: Sun Feb 11, 2024 1:20 pm |
|
|
Hmm I don't understand - I'm selecting ADPCH = 0b00010011b (d19) - RC3/ANC3. There is any note written for this channel. It's e.g. for channel 0b10010011 (d147) - RC3(OPA1IN1+). |
|
|
pet007
Joined: 25 Jan 2023 Posts: 21
|
|
Posted: Sun Feb 11, 2024 2:29 pm |
|
|
I've changed MCU and it's working already - it seems this pin was damaged....... |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Mon Feb 12, 2024 3:49 am |
|
|
Apologies I was thinking of another chip.
There are a couple of the chips now where the pin is shown as ANxx, but
when selected routes only to the _output_ of the internal op-amp.
Have to wonder what you actually connected to kill the ADC multiplexer
input connection here?. Pins on PIC's are not that easy to kill in general. |
|
|
pet007
Joined: 25 Jan 2023 Posts: 21
|
|
Posted: Mon Feb 12, 2024 2:25 pm |
|
|
Nevermind ;)
Yes, PIC's are very robust, but +13V is too much for RC3. My PCB design is a bit unlucky, when you are trying to measure divider output voltage with fuc..ng thick multimeter probe and near by is +13V input connector pin...... |
|
|
|