• AVR Freaks

Helpful ReplyHot!ADC Simple two inputs Read

Author
epareja
Super Member
  • Total Posts : 380
  • Reward points : 0
  • Joined: 2003/11/07 12:53:08
  • Location: Colombia
  • Status: offline
2020/03/31 09:39:49 (permalink)
0

ADC Simple two inputs Read

Hello all,
 
I'm struggling with reading two analog inputs (AN0 and AN1) just once each.
I have configured the ADC driver in different ways (auto sampling, manual sampling, scanning, etc) but when I trigger a new sampling in AD0 I get various interrupts, regardless I configure it to interrupt at 1 sample.
 
Please someone help me in how to configure a simple ADC conversion.
 
  DRV_ADC_PositiveInputSelect(ADC_MUX_A, ADC_INPUT_POSITIVE_AN0);
  PLIB_ADC_SamplingStart(ADC_ID_1);
  DRV_ADC_Start();

 
I'm using a PIC32MX795F512H MPLAB 5.3 and Harmony 2.6
 
Thank you
 
 


Ernesto Pareja J
www.dcctrains.netne.net

#1
nigelwright7557
Super Member
  • Total Posts : 441
  • Reward points : 0
  • Joined: 2006/11/06 08:15:51
  • Location: 0
  • Status: offline
Re: ADC Simple two inputs Read 2020/03/31 10:01:59 (permalink)
0
Working code:
 
//set up a2d for 2 channels auto scan mode
AD1CON1bits.ON=1; //enable a2d
AD1CON2=0X404;
AD1CON3=0X100;
AD1CSSL=3; //SCAN 0 AND 1 A2D
AD1CON1bits.ASAM=1;
AD1CON1bits.CLRASAM=0;
 
 
 
//////////////////////////////////////////////////////////////
//read channels into 2 buffers
 
IFS0bits.AD1IF = 0;
 while (!IFS0bits.AD1IF); // wait for a2d int flag
 *ptr++=ADC1BUF0;
*ptr2++=ADC1BUF1;
 
 
#2
Paul PortSol
Super Member
  • Total Posts : 619
  • Reward points : 0
  • Joined: 2015/07/03 11:52:03
  • Location: Newfoundland, Canada
  • Status: offline
Re: ADC Simple two inputs Read 2020/03/31 12:45:38 (permalink)
0
2 inputs is 2 samples total.
 
 
#3
epareja
Super Member
  • Total Posts : 380
  • Reward points : 0
  • Joined: 2003/11/07 12:53:08
  • Location: Colombia
  • Status: offline
Re: ADC Simple two inputs Read 2020/03/31 18:05:13 (permalink)
0
nigelwright7557
Working code: //set up a2d for 2 channels auto scan modeAD1CON1bits.ON=1; //enable a2dAD1CON2=0X404;AD1CON3=0X100;AD1CSSL=3; //SCAN 0 AND 1 A2DAD1CON1bits.ASAM=1;AD1CON1bits.CLRASAM=0;   ////////////////////////////////////////////////////////////////read channels into 2 buffers IFS0bits.AD1IF = 0; while (!IFS0bits.AD1IF); // wait for a2d int flag *ptr++=ADC1BUF0;*ptr2++=ADC1BUF1;  

Thank you for your answer. I put that code and enabled the interrupt for the ADC but it's not firing the interrupt.
 
this is teh code
 

void RX5808_Setup(void){
rx5808_data.ModuleIndex = 0;
rx5808_data.state = RX5808_IDLE;
AD1CON1bits.ON=1; //enable a2d
AD1CON2=0X404;
AD1CON3=0X100;
AD1CSSL=3; //SCAN 0 AND 1 A2D
AD1CON1bits.ASAM=1;
AD1CON1bits.CLRASAM=0;
PLIB_INT_SourceFlagClear(INT_ID_0, INT_SOURCE_ADC_1);
PLIB_INT_SourceEnable(INT_ID_0, INT_SOURCE_ADC_1);
PLIB_INT_VectorPrioritySet(INT_ID_0, INT_VECTOR_AD1, INT_PRIORITY_LEVEL3);
PLIB_INT_VectorSubPrioritySet(INT_ID_0, INT_VECTOR_AD1, INT_SUBPRIORITY_LEVEL0);
}
 
What am I doing wrong?



Ernesto Pareja J
www.dcctrains.netne.net

#4
Paul PortSol
Super Member
  • Total Posts : 619
  • Reward points : 0
  • Joined: 2015/07/03 11:52:03
  • Location: Newfoundland, Canada
  • Status: offline
Re: ADC Simple two inputs Read 2020/04/01 05:26:18 (permalink) ☄ Helpfulby epareja 2020/04/01 09:51:55
0
See attached for example of reading multiple ADC on PIC32MX in HarmonyV20501, which I use in HarmonyV206.
- Notes__adc=PIC32MX370F512H_v00PR.zip
- I set the ADC to start upon software trigger, then I can trigger when I want and wait for samples to be ready.
- Samples per interrupt MUST match number of ADC inputs if using scan mode, interrupt or flag will occur after last sample.
 
Warnings:
- MHC can loose ADC settings in H206, so backup project and consider setting drv_adc_static.c as read-only so doesn't get overwritten by MHC that lost settings (This mostly seen in PIC32MZ ADC).
- Screen capture working MHC settings to a document and put with code... in case MHC looses settings.
 
Paul
#5
Paul PortSol
Super Member
  • Total Posts : 619
  • Reward points : 0
  • Joined: 2015/07/03 11:52:03
  • Location: Newfoundland, Canada
  • Status: offline
Re: ADC Simple two inputs Read 2020/04/01 05:29:16 (permalink)
0
===removed===
post edited by Paul PortSol - 2020/04/01 05:46:07
#6
nigelwright7557
Super Member
  • Total Posts : 441
  • Reward points : 0
  • Joined: 2006/11/06 08:15:51
  • Location: 0
  • Status: offline
Re: ADC Simple two inputs Read 2020/04/01 05:31:30 (permalink)
0
 
Thank you for your answer. I put that code and enabled the interrupt for the ADC but it's not firing the interrupt.
 
Interupts dont need to be enabled, I just use the interrupt flag.
#7
Paul PortSol
Super Member
  • Total Posts : 619
  • Reward points : 0
  • Joined: 2015/07/03 11:52:03
  • Location: Newfoundland, Canada
  • Status: offline
Re: ADC Simple two inputs Read 2020/04/01 05:46:32 (permalink)
0
If you dig in my posting history you will see much more detailed replies on ADC for HarmonyV206 with PIC32MX and PIC32MZ, I'm not digging through that but likely worth your effort to dig.
 
When doing searches on this form note date at bottom of search limits finds to recent months, widen that to capture good answers from back a ways (i.e. years).
 
Paul
#8
epareja
Super Member
  • Total Posts : 380
  • Reward points : 0
  • Joined: 2003/11/07 12:53:08
  • Location: Colombia
  • Status: offline
Re: ADC Simple two inputs Read 2020/04/01 09:53:37 (permalink)
0
Thank you all I will try the configuration of harmony 2.06 Paul posted.


Ernesto Pareja J
www.dcctrains.netne.net

#9
Jump to:
© 2020 APG vNext Commercial Version 4.5