-
Notifications
You must be signed in to change notification settings - Fork 0
Analog Functions and Additions
Analog functions like analogRead and analogWrite etc. have changed after V1.2.1 to have extra safety measures to ensure invalid settings cannot be done and report errors.
Additionally extra getter functions have been added so other libraries can access the resolution of read and write functions as number of bits and current maximum value possible.
These functions return the analogue resolution as number of bits
- uint8_t getAnalogReadBits( ) - range 8 to 12
- uint8_t getAnalogWriteBits( ) - range 8 to 16
These functions return the analogue resolution as its maximum value
- uint16_t getAnalogReadMaximum( ) - range 255 to 4095
- uint16_t getAnalogWriteMaximum( ) - range 255 to 65535
This function enables the analog amplifiers at the ADC inputs with adjustible gain (for XMC1000 series)
- uint32_t analogRead_variableGain( uint8_t channel, uint8_t gain_value )
The gain factor values can be found here.
Read resolution default is 10 bits (0 to 1023)
Write resolution default is 8 bits (0 to 255)
Where possible functions do NOT action invalid parameters passed in.
Functions return error codes or valid values so be sure which error code you are looking for as some functions can return 0 as a valid value (e.g. analogRead) so an out of range value is returned instead.
Function | Valid Return | Errors |
analogReadResolution | 8 to 12 as passed in |
255 |
getAnalogReadBits | 8 to 12 | none |
getanalogReadMaximum | 255 to 4095 | none |
analogWriteResolution | 8 to 16 as passed in |
255 |
getAnalogWriteBits | 8 to 16 | none |
getanalogWriteMaximum | 255 to 65535 | none |
analogRead | 0 to Maximum for Resolution | 0xFFFFFFFF usually invalid channel |
analogWrite | 0 success | -1 = invalid value -2 = wrong pin |
setAnalogWriteFrequency | 0 success | -1 = invalid frequency -2 = wrong pin |
analogReference | none | NULL function see below |
On all boards the Analogue Reference is set to use the internal power supply (however noisy), so the AREF pin is an OUTPUT of the AREF in use. Do NOT connect any external voltage source to this pin, or use shields that change this voltage.
CAUTION any shorts on this pin especially to 0V (GND) will bring down the supply of the chip.
The pin voltage is the current supply voltage to AREF for analogue conversions.
This pin CANNOT be reassigned as GPIO (pinMode has no effect).
This function has NO operation and will not match any call on parameters passed in with other libraries or examples that use this call.
Any shields and examples that try to change this, will NOT function the same on these boards.
Each analog input channel can be configured to be amplified by an adjustable gain factor, for XMC1000 series. To configure the gain, the gain value
is to be selected in the analogRead_variableGain()
function which translates to a gain factor
as per the following table:
Gain value | Gain factor |
0 | 1 |
1 | 3 |
2 | 6 |
3 | 12 |
For more information, please refer to the application note here.
-
Supported Boards
-
Legacy board (Supported until 1.7.0)
-
Arduino Variations