This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Reading multiple analog voltages from multiple pins

Other Parts Discussed in Thread: HALCOGEN

Hey,

I used HALCoGen to enable the ADC drivers (as per your Hercules ADC Tutorial). My Code is here:

void readAnalogVoltage()
{
	unsigned int value;

	adcData_t adc_data;
	adcData_t *adc_data_ptr = &adc_data;

	adcInit();

	while(1){

	adcStartConversion(adcREG1, adcGROUP1); //Start ADC conversion
	while (!adcIsConversionComplete(adcREG1, adcGROUP1)); //Wait for ADC conversion
	adcGetData(adcREG1, 1U, adc_data_ptr);
	value = (unsigned int)adc_data_ptr->value;

	value = map(value, XLOWER, XUPPER, -90, 90);

	printf("X Range: %d\n", value);
	}
		//waitLongTimeMS(1000);
}

This worked when I enabled Pin 9 using HALCoGen---I was able to read analog voltages from the on-board ambient light sensor. However, when I enabled multiple pins on HALCoGen (Analog pins 0, 1, 2) I'm not exactly sure how to read an analog voltage from EACH of those pins. Could you show me how?

Thanks!

  • Hi Mukund,

    Please refer to the Halcogen example 'example_adcDisplay.c' . It has the configuration for 2 channels. You can extend it to 4 channels. Basically you have to enable the corresponding pins in ADC group tab in halcogen and initialise the variable adc_data(in the example_adcDisplay.c) array length to number of channels.

    Please let know if you need any more help

    Regards,
    Praveen