hello, i have 13 analog inputs which i would like to convert A/D and save the A/D inputs into external memory. however, i have a condition where-in at times, i need to sample 5 channels, at times, i have to sample 7 or 8 depending on various conditions. all these conditions would be INITIALIZED in the init routine of the code.Once fixed during the INIT routine, the no. of channels would be fixed until a PUC.
how can i achieve this objective? the way i am doing right now is i sample all the channels, however, save only those which are required. this requires a lot of computations and waste of cycles... it would be nice to sample only those channels which i have to save to mem. pseudo code is below:
//// a d c i n t e r r u p t r o u t i n e ////
{
switch(ADC_INTERRUPT_VECTOR)
{
case 0x0C:// do something
case 0x32://do something
default:
break;
}
//save_data_to_memory()
}
save_data_to_memory()
{
if(channel1== enabled)
{
buff[1]= ADC12MEM1;
}
if(channel2== enabled)
{
buff[2]= ADC12MEM2;
}
if(channel3== enabled)
{
buff[3]= ADC12MEM3;
}
if(channel4== enabled)
{
buff[4]= ADC12MEM4;
}
if(channel5== enabled)
{
buff[5]= ADC12MEM1;
}
if(channel6== enabled)
{
buff[6]= ADC12MEM2;
}
if(channel7== enabled)
{
buff[7]= ADC12MEM3;
}
if(channel8== enabled)
{
buff[8]= ADC12MEM4;
}
//and so on... till the end of channels