It's now time to port the Analogue functions as defined by Wiring language: analogRead()
Now, in reference to the board and pin mapping, it's good to recap:
Where: the analogRead() method reads the value of an analog input pin. Possible values range is 0-1023, where 0 is 0 volts and 1023 is 3.3 volts.
Now, in reference to the board and pin mapping, it's good to recap:
Where: the analogRead() method reads the value of an analog input pin. Possible values range is 0-1023, where 0 is 0 volts and 1023 is 3.3 volts.
To implement such, I use the background scan: "the Versatile Analog-to-Digital Converter (VADC) is configured to measure multiple analog signals in a sequence using background scan request".
Such is done by:
- configuring the respective analogue ports (AN0 .. AN5)
- configuring the VADC to background scan (done by "wiring_analog_init(void)")
- wrap the analogRead() function
configuring the respective analogue ports (AN0 .. AN5)
Such is realized by:
[..]
// Port Numeric Definition - Analogue Pins
#define A0 20
#define A1 21
#define A2 22
#define A3 23
#define A4 24
#define A5 25
#define TRIMM 26
//...
// Port Numeric Definition - Analogue Pins
#define A0 20
#define A1 21
#define A2 22
#define A3 23
#define A4 24
#define A5 25
#define TRIMM 26
//...
configuring the VADC to background scan
Such is realized by:
void wiring_analog_init(void)
{
initVADCModule(); /* Initialize the VADC module */
initVADCGroup(); /* Initialize the VADC group */
initVADCChannels(); /* Initialize the used channels */
/* Start the scan */
IfxVadc_Adc_startBackgroundScan(&g_vadc);
}
{
initVADCModule(); /* Initialize the VADC module */
initVADCGroup(); /* Initialize the VADC group */
initVADCChannels(); /* Initialize the used channels */
/* Start the scan */
IfxVadc_Adc_startBackgroundScan(&g_vadc);
}
wrap the analogRead() function
Such is realized by:
uint16 analogRead(uint8 pin)
{
uint16 value = 0;
// Select the required channel in channel pending register
switch(pin)
{
// A0 P40.9 ADC0: AN39 / VADCG4.7
case A0:
value = readADCValue(CHN_39);
break;
// A1 P40.8 ADC1: AN38 / VADCG4.6
case A1:
value = readADCValue(CHN_38);
break;
// A2 P40.7 ADC2: AN37 / VADCG4.5
case A2:
value = readADCValue(CHN_37);
break;
// A3 P40.6 ADC3: AN36 / VADCG4.4
case A3:
value = readADCValue(CHN_36);
break;
[..]
}
// Return ADC Conversion
return (value);
}
{
uint16 value = 0;
// Select the required channel in channel pending register
switch(pin)
{
// A0 P40.9 ADC0: AN39 / VADCG4.7
case A0:
value = readADCValue(CHN_39);
break;
// A1 P40.8 ADC1: AN38 / VADCG4.6
case A1:
value = readADCValue(CHN_38);
break;
// A2 P40.7 ADC2: AN37 / VADCG4.5
case A2:
value = readADCValue(CHN_37);
break;
// A3 P40.6 ADC3: AN36 / VADCG4.4
case A3:
value = readADCValue(CHN_36);
break;
[..]
}
// Return ADC Conversion
return (value);
}
Comments
Post a Comment