ADC settings without ADC library

General discussion on mikroC PRO for PIC32.
Post Reply
Author
Message
vt23
Posts: 44
Joined: 17 Jun 2014 10:36

ADC settings without ADC library

#1 Post by vt23 » 22 Aug 2018 12:00

Hello,
I need to change settings of the AD converter of the PIC32MX460F512L. I have my own control board with TFT RGB display and resistive TP on it. I am not satisfied with the functionality of the touch panel and ADC at higher temperatures in our machine. I would like to do experiments with sampling/conversion times and others. At the same time I am using TFT_Touchpanel library which needs ADC working. Now I found that the data impuls for vertical coordinate is about 600 microseconds and data impuls for the horizontal movement on the TP is about 8.840 ms. Both periodically repeated one after other when the TP point is pressed down.
I am using these functions in the ..._driver.c file:

Code: Select all

static void InitializeTouchPanel() {
  TFT_DataPort_Direction = 0;
  Init_ADC();
  ADC_Get_Sample_Ptr = ADC1_Get_Sam;
  TFT_Set_Active(Set_Index, Write_Command, Write_Data);
  //...
  }

void Init_ADC() {
  AD1PCFG = 0xFFFF;
  PCFG12_bit = 0;
  PCFG13_bit = 0;
  // PMP setup
  //ADC1_Init();  //switch off library func
  
  AD1CON1bits.SSRC = 0b111;
  AD1CON1bits.ASAM = 1;   //auto sampling
  AD1CON3bits.SAMC = 31;  //auto-sample time 31 Tad
  AD1CON3bits.ADCS = 15;  //Tad= 32*Tpb (Tpb=Tahb/2)
  //AD1CON1bits.ON = 1;
  //AD1CON1bits.SAMP = 1;
}
TFT_Touchpanel library needs ADC_Get_Sample_Ptr (pointer to int ADC1_Get_Sample(int ch)) so I created:

Code: Select all

unsigned int ADC1_Get_Sam(unsigned int ch) {
  unsigned int res;
  AD1IF_bit = 0;  //IFS1.B1
  //AD1PCFGCLR = 1<<ch;
  AD1CHSSET = ch<<16;  // Connect RB12/AN12 or RB13/AN13 as CH0 input
  AD1CSSL = 0;  //AD1CSSLSET = 1<<ch; //Contents of AD1CSSL are ignored when AD1CON2.CSCNA = 0
  AD1CON1bits.ON = 1;
  //Delay_ms(10);
  AD1CON1bits.SAMP = 1;  // start sampling then...// after 31Tad go to conversion
  while (!(AD1CON1 & 0x0001));  // conversion done?
  res = (unsigned int) ADC1BUF0;
  AD1CON1bits.ON = 0;
  return res;  // get ADC value
}
I don't know if the ADC with MikroC library is using interrupt routine or not and how to modify it (re-create).
Can someone write me settings of the ADC which can work together with TFT_Touchpanel library? With my setting compilation (build) is OK but the touch panel does not react.

Best regards
Vitek

vt23
Posts: 44
Joined: 17 Jun 2014 10:36

Re: ADC settings without ADC library

#2 Post by vt23 » 11 Sep 2018 08:46

Hello guys,
can someone give me an advice about the ADC settings? I can't go ahead.

Post Reply

Return to “mikroC PRO for PIC32 General”