mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-23 19:21:59 +03:00
Added setAnalogResolution() method.
This commit is contained in:
@ -22,6 +22,12 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static int _analogResolution = 10;
|
||||||
|
|
||||||
|
void setAnalogResolution(int res) {
|
||||||
|
_analogResolution = res;
|
||||||
|
}
|
||||||
|
|
||||||
eAnalogReference analog_reference = AR_DEFAULT;
|
eAnalogReference analog_reference = AR_DEFAULT;
|
||||||
|
|
||||||
void analogReference(eAnalogReference ulMode)
|
void analogReference(eAnalogReference ulMode)
|
||||||
@ -51,11 +57,11 @@ uint32_t analogRead(uint32_t ulPin)
|
|||||||
case ADC5 :
|
case ADC5 :
|
||||||
case ADC6 :
|
case ADC6 :
|
||||||
case ADC7 :
|
case ADC7 :
|
||||||
// Enable the corresponding channel
|
// Enable the corresponding channel
|
||||||
adc_enable_channel( ADC, ulChannel );
|
adc_enable_channel( ADC, ulChannel );
|
||||||
|
|
||||||
// Start the ADC
|
// Start the ADC
|
||||||
adc_start( ADC );
|
adc_start( ADC );
|
||||||
|
|
||||||
// Wait for end of conversion
|
// Wait for end of conversion
|
||||||
while ((adc_get_status(ADC) & ADC_SR_DRDY) != ADC_SR_DRDY)
|
while ((adc_get_status(ADC) & ADC_SR_DRDY) != ADC_SR_DRDY)
|
||||||
@ -64,12 +70,12 @@ uint32_t analogRead(uint32_t ulPin)
|
|||||||
// Read the value
|
// Read the value
|
||||||
ulValue = adc_get_latest_value(ADC);
|
ulValue = adc_get_latest_value(ADC);
|
||||||
|
|
||||||
// Disable the corresponding channel
|
// Disable the corresponding channel
|
||||||
adc_disable_channel( ADC, ulChannel );
|
adc_disable_channel( ADC, ulChannel );
|
||||||
|
|
||||||
// Stop the ADC
|
// Stop the ADC
|
||||||
// adc_stop( ADC ) ; // never do adc_stop() else we have to reconfigure the ADC each time
|
// adc_stop( ADC ) ; // never do adc_stop() else we have to reconfigure the ADC each time
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Handling ADC 12 bits channels
|
// Handling ADC 12 bits channels
|
||||||
case ADC8 :
|
case ADC8 :
|
||||||
@ -80,11 +86,11 @@ uint32_t analogRead(uint32_t ulPin)
|
|||||||
case ADC13 :
|
case ADC13 :
|
||||||
case ADC14 :
|
case ADC14 :
|
||||||
case ADC15 :
|
case ADC15 :
|
||||||
// Enable the corresponding channel
|
// Enable the corresponding channel
|
||||||
adc12b_enable_channel( ADC12B, ulChannel );
|
adc12b_enable_channel( ADC12B, ulChannel );
|
||||||
|
|
||||||
// Start the ADC12B
|
// Start the ADC12B
|
||||||
adc12b_start( ADC12B );
|
adc12b_start( ADC12B );
|
||||||
|
|
||||||
// Wait for end of conversion
|
// Wait for end of conversion
|
||||||
while ((adc12b_get_status(ADC12B) & ADC12B_SR_DRDY) != ADC12B_SR_DRDY)
|
while ((adc12b_get_status(ADC12B) & ADC12B_SR_DRDY) != ADC12B_SR_DRDY)
|
||||||
@ -93,24 +99,24 @@ uint32_t analogRead(uint32_t ulPin)
|
|||||||
// Read the value
|
// Read the value
|
||||||
ulValue = adc12b_get_latest_value(ADC12B) >> 2;
|
ulValue = adc12b_get_latest_value(ADC12B) >> 2;
|
||||||
|
|
||||||
// Stop the ADC12B
|
// Stop the ADC12B
|
||||||
// adc12_stop( ADC12B ) ; // never do adc12_stop() else we have to reconfigure the ADC12B each time
|
// adc12_stop( ADC12B ) ; // never do adc12_stop() else we have to reconfigure the ADC12B each time
|
||||||
|
|
||||||
// Disable the corresponding channel
|
// Disable the corresponding channel
|
||||||
adc12b_disable_channel( ADC12B, ulChannel );
|
adc12b_disable_channel( ADC12B, ulChannel );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Compiler could yell because we don't handle DAC pins
|
// Compiler could yell because we don't handle DAC pins
|
||||||
default :
|
default :
|
||||||
ulValue=0;
|
ulValue=0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined __SAM3X8E__ || defined __SAM3X8H__
|
#if defined __SAM3X8E__ || defined __SAM3X8H__
|
||||||
switch ( g_APinDescription[ulPin].ulAnalogChannel )
|
switch ( g_APinDescription[ulPin].ulAnalogChannel )
|
||||||
{
|
{
|
||||||
// Handling ADC 10 bits channels
|
// Handling ADC 12 bits channels
|
||||||
case ADC0 :
|
case ADC0 :
|
||||||
case ADC1 :
|
case ADC1 :
|
||||||
case ADC2 :
|
case ADC2 :
|
||||||
@ -135,10 +141,16 @@ uint32_t analogRead(uint32_t ulPin)
|
|||||||
;
|
;
|
||||||
|
|
||||||
// Read the value
|
// Read the value
|
||||||
ulValue = adc_get_latest_value(ADC) >> 2;
|
ulValue = adc_get_latest_value(ADC);
|
||||||
|
|
||||||
// Disable the corresponding channel
|
// Disable the corresponding channel
|
||||||
adc_disable_channel(ADC, ulChannel);
|
adc_disable_channel(ADC, ulChannel);
|
||||||
|
|
||||||
|
// Map result into user selected resolution
|
||||||
|
if (_analogResolution > ADC_RESOLUTION)
|
||||||
|
ulValue <<= _analogResolution - ADC_RESOLUTION;
|
||||||
|
if (_analogResolution < ADC_RESOLUTION)
|
||||||
|
ulValue >>= ADC_RESOLUTION - _analogResolution;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Compiler could yell because we don't handle DAC pins
|
// Compiler could yell because we don't handle DAC pins
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
#define _WIRING_ANALOG_
|
#define _WIRING_ANALOG_
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -56,6 +56,13 @@ extern void analogWrite( uint32_t ulPin, uint32_t ulValue ) ;
|
|||||||
*/
|
*/
|
||||||
extern uint32_t analogRead( uint32_t ulPin ) ;
|
extern uint32_t analogRead( uint32_t ulPin ) ;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* \brief Set the resolution of analogRead return values. Default is 10 bits (0..1024).
|
||||||
|
*
|
||||||
|
* \param res
|
||||||
|
*/
|
||||||
|
void setAnalogResolution(int res);
|
||||||
|
|
||||||
extern void analogOutputInit( void ) ;
|
extern void analogOutputInit( void ) ;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -162,12 +162,14 @@ static const uint8_t DA0 = 66;
|
|||||||
static const uint8_t DA1 = 67;
|
static const uint8_t DA1 = 67;
|
||||||
static const uint8_t CANRX0 = 68;
|
static const uint8_t CANRX0 = 68;
|
||||||
static const uint8_t CANTX0 = 69;
|
static const uint8_t CANTX0 = 69;
|
||||||
|
#define ADC_RESOLUTION 12
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* DACC
|
* DACC
|
||||||
*/
|
*/
|
||||||
#define DACC_INTERFACE DACC
|
#define DACC_INTERFACE DACC
|
||||||
#define DACC_INTERFACE_ID ID_DACC
|
#define DACC_INTERFACE_ID ID_DACC
|
||||||
|
#define DACC_RESOLUTION 12
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* PWM
|
* PWM
|
||||||
|
Reference in New Issue
Block a user