• AVR Freaks

Helpful ReplyPIC32MZ : Class 2 ADC Configuration Harmony 2_06 : Mixing Analog Inputs

Author
TS9
Super Member
  • Total Posts : 791
  • Reward points : 0
  • Joined: 2010/05/07 10:52:22
  • Status: offline
2019/11/08 05:25:42 (permalink)
0

PIC32MZ : Class 2 ADC Configuration Harmony 2_06 : Mixing Analog Inputs

Hi,
 
Microchip MCU: PIC32MZ2048EFM144
TFT Interface  :  GFX LCC
 
I have successfully configured  Class 2 AN5,AN6, AN7 as Analog Pins for 12-bit ADC .
While display the result of GFX TFT Text Box I am observing the values of three channels mixing among each other . 
Let check code and attachment . What is am doing properly ? 
 

// This is APP_INIT
case APP_STATE_INIT:
{
bool appInitialized = true;

if (appInitialized)
{
DRV_ADC_Start();
DRV_TMR1_Start();
PLIB_ADCHS_ChannelDigitalFeatureEnable
(
DRV_ADC_ID_1,
ADCHS_CHANNEL_7
);
PLIB_ADCHS_GlobalSoftwareTriggerEnable( DRV_ADC_ID_1 );
appData.state = APP_STATE_SERVICE_TASKS;
}
break;
}
 


 
uSDelay();
if(true == DRV_ADC_SamplesAvailable(7))
{
sampleResult = DRV_ADC_SamplesRead(7);
/* Clear ADC Interrupt Flag of INT_SOURCE_ADC_1*/
PLIB_INT_SourceFlagClear(INT_ID_0, INT_SOURCE_ADC_1);
if(ADCFlag3 == 25)
{
sprintf(myBuff,"%d",sampleResult);
laString str3 ;
str3 = laString_CreateFromCharBuffer(myBuff,
GFXU_StringFontIndexLookup(&stringTable,string_PowerValue ,0));
 
laLabelWidget_SetText(PowerValue, str3) ;
laString_Destroy(&str3) ;
ADCFlag3 = 0 ;
}
ADCFlag3++;
}
uSDelay();
if(true == DRV_ADC_SamplesAvailable(5))
{
sampleResult = DRV_ADC_SamplesRead(5);
/* Clear ADC Interrupt Flag of INT_SOURCE_ADC_1*/
PLIB_INT_SourceFlagClear(INT_ID_0, INT_SOURCE_ADC_1);

sprintf(myBuff,"%d",sampleResult);
if(ADCFlag2 == 25)
{
laString str2 ;
str2 = laString_CreateFromCharBuffer(myBuff,
GFXU_StringFontIndexLookup(&stringTable,string_FrequencyValue ,0));

laLabelWidget_SetText(FrequencyBK, str2) ;
laString_Destroy(&str2) ;
ADCFlag2 = 0 ;
}
ADCFlag2++;
}
uSDelay();
if(true == DRV_ADC_SamplesAvailable(6))
{
sampleResult = DRV_ADC_SamplesRead(6);
/* Clear ADC Interrupt Flag of INT_SOURCE_ADC_1*/
PLIB_INT_SourceFlagClear(INT_ID_0, INT_SOURCE_ADC_1);

if(ADCFlag4 == 25)
{
sprintf(myBuff,"%d",sampleResult);
laString str ;
str = laString_CreateFromCharBuffer(myBuff,
GFXU_StringFontIndexLookup(&stringTable,string_WorkPieceString ,0));
 
laLabelWidget_SetText(WorkPieceTimeValue, str) ;
laString_Destroy(&str) ;
ADCFlag4 = 0 ;
}
ADCFlag4++;
}
}
 

 
Thanks is advance..
 
--
TS9
post edited by TS9 - 2019/11/08 05:28:07

Attached Image(s)

#1
Paul PortSol
Super Member
  • Total Posts : 503
  • Reward points : 0
  • Joined: 2015/07/03 11:52:03
  • Location: Newfoundland, Canada
  • Status: offline
Re: PIC32MZ : Class 2 ADC Configuration Harmony 2_06 : Mixing Analog Inputs 2019/11/08 07:30:29 (permalink) ☄ Helpfulby TS9 2019/11/08 09:46:40
0
1. Careful, Harmony 2 can loose ADC settings for PIC32MZ. When you get it right set the generated file to read only so it isn't overwritten if you do an MHC regenerate (See my previous PIC32MZ ADC posts for details).
 
2a. If you are getting leakage between ADC channels check:
- Input resistance versus capacitance. If you have a high impedance input then the input capacitance of the ADC may cause the previous channel to leak into the next, especially for the "sampled" ADCs. 
Quick test: Put a 100nF cap on each ADC input to see if it helps. 
*PIC32MZ is different from the PIC32MX I've used as they didn't have this problem.
 
2b. It may help to slow your ADC sampling, but if the input is high impedance then there simply won't be enough charge available to drive the ADC input when it is sampled.
 
2c. For mine happily the 100nF fixed my higher impedance inputs, and for the ones driven by amplifier circuits I just reduced the series resistor between circuit and PIC32MZ to provide appropriate response. Some of your circuits may require a buffer/follower/amplifier before the PIC, or use the other ADC class pins that have independent input circuits.
 
Paul
#2
Paul PortSol
Super Member
  • Total Posts : 503
  • Reward points : 0
  • Joined: 2015/07/03 11:52:03
  • Location: Newfoundland, Canada
  • Status: offline
Re: PIC32MZ : Class 2 ADC Configuration Harmony 2_06 : Mixing Analog Inputs 2019/11/08 07:37:09 (permalink) ☄ Helpfulby TS9 2019/11/08 09:46:37
0
Also:
Check that your "number of samples" matches your "number of ADCs", if there is a mismatch then the "samples" will fill up with values from different ADCs each cycle.
Again refer to my previous posts and sample projects about PIC32MZ ADCs. 
 
#3
TS9
Super Member
  • Total Posts : 791
  • Reward points : 0
  • Joined: 2010/05/07 10:52:22
  • Status: offline
Re: PIC32MZ : Class 2 ADC Configuration Harmony 2_06 : Mixing Analog Inputs 2019/11/08 08:45:06 (permalink)
0
Hi,
 
Thanks for update ...
Is the really a hardware problem (100nF Cap as suggested) ?
But I only see this in PIC32MZ Class 2 ADC Configuration ? 
Not for Class 1.
 
Did you see the code ? If that right ?
 
--
Thanks
 
#4
Paul PortSol
Super Member
  • Total Posts : 503
  • Reward points : 0
  • Joined: 2015/07/03 11:52:03
  • Location: Newfoundland, Canada
  • Status: offline
Re: PIC32MZ : Class 2 ADC Configuration Harmony 2_06 : Mixing Analog Inputs 2019/11/08 09:35:40 (permalink)
0
See "ADC Block Diagram" figure 28-1 in the PIC32MZ datasheet. 
See how AN0-AN4(AN45-AN48) have dedicated inputs ADC0-ADC4, while AN5-AN42 are sharing ADC7.
The input capacitance can carry signal between AN5-AN42 as they are switched to ADC7, your input signal has to drive through that capacitance else you'll see signal leakage.
 
I have no idea what your input circuits are, I can only tell you what worked for me.
 
I suggest you try putting a 100nF on one of your trouble inputs. If it works then you can go though finding the optimum input cap (10nF~220nF), or modifying your circuits for appropriate drive. If it doesn't then maybe it is software.
 
Paul
#5
TS9
Super Member
  • Total Posts : 791
  • Reward points : 0
  • Joined: 2010/05/07 10:52:22
  • Status: offline
Re: PIC32MZ : Class 2 ADC Configuration Harmony 2_06 : Mixing Analog Inputs 2019/11/08 09:47:53 (permalink)
0
Thanks ... I will check , connect 100nF and update to you tomorrow .
 
--
TS9
#6
TS9
Super Member
  • Total Posts : 791
  • Reward points : 0
  • Joined: 2010/05/07 10:52:22
  • Status: offline
Re: PIC32MZ : Class 2 ADC Configuration Harmony 2_06 : Mixing Analog Inputs 2019/11/08 22:48:31 (permalink)
0


I have no idea what your input circuits are, I can only tell you what worked for me.

 


As for now , I am testing with Simple 10K Potentiometers (Three POT for Three Channels) .                                            

PIC32MZ ADC Pin   <-------------   Potentiometer  .


- TS9
post edited by TS9 - 2019/11/09 05:52:27
#7
Jump to:
© 2019 APG vNext Commercial Version 4.5