CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

18F16Q41 - AD converter issue (solved - pin damage)

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
pet007



Joined: 25 Jan 2023
Posts: 21

View user's profile Send private message

18F16Q41 - AD converter issue (solved - pin damage)
PostPosted: Sun Feb 11, 2024 11:41 am     Reply with quote

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: 19538

View user's profile Send private message

PostPosted: Sun Feb 11, 2024 12:02 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Feb 11, 2024 1:20 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Feb 11, 2024 2:29 pm     Reply with quote

I've changed MCU and it's working already - it seems this pin was damaged.......
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Mon Feb 12, 2024 3:49 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Feb 12, 2024 2:25 pm     Reply with quote

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......
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group