STC15W408AS library 0.15.0
Loading...
Searching...
No Matches
Enumerations
ADC

Enumerations

enum  adc_speed_t { ADC_SPEED_540 = 0b00000000 , ADC_SPEED_360 = 0b00100000 , ADC_SPEED_180 = 0b01000000 , ADC_SPEED_90 = 0b01100000 }
 ADC speed enum. More...
 

init

ADC initializaion and destroy routines

#define adc_init_input_only(p1_pin, adrj_flag, speed)
 ADC initialization in pin input only mode.
 
#define adc_init_open_drain(p1_pin, adrj_flag, speed)
 ADC initialization in pin open drain mode.
 
#define adc_destroy(void)
 Deinitialize ADC module.
 

sync

ADC sync routines

#define adc_read_sync(value)
 ADC read routine.
 

async

ADC async routines

#define adc_async_read_start()
 Start async ADC read operation if not started.
 
#define is_adc_async_read_started()   (test_if_bit_set(ADC_CONTR, 1 << ADC_START_BIT) && (ADC_CONTR & ADC_POWER_ON_MSK))
 get ADC start and power flags
 
#define adc_async_read_finish()   (bit_clr(ADC_CONTR, ~(1 << ADC_FLAG_BIT)))
 Clear ADC result ready flag.
 
#define adc_async_get_result()   (test_if_bit_set(CLK_DIV, 1 << ADRJ_BIT) ? (ADC_RESL << ADC_LOW_BITS_COUNT) | (ADC_RES & ADC_LOW_BITS_MSK) : (ADC_RES << ADC_LOW_BITS_COUNT) | (ADC_RESL & ADC_LOW_BITS_MSK))
 Async get ADC result.
 

Detailed Description

Functions and data structures related to ADC module

ADC could be used in sync or async modes.

In sync mode read ADC result blocks until result is not ready.

In async mode read is started in non blocking mode. ADC ready raise an interrupt. In async mode mcu interrupts and ADC interrupt should be enabled before start reading.

Author
Michael Golovanov

Macro Definition Documentation

◆ adc_async_get_result

#define adc_async_get_result ( )    (test_if_bit_set(CLK_DIV, 1 << ADRJ_BIT) ? (ADC_RESL << ADC_LOW_BITS_COUNT) | (ADC_RES & ADC_LOW_BITS_MSK) : (ADC_RES << ADC_LOW_BITS_COUNT) | (ADC_RESL & ADC_LOW_BITS_MSK))

Async get ADC result.

Retrieves the result of a completed asynchronous ADC conversion

This routine should be used inside ADC interrupt handler. Typically after call this routine adc_async_read_finish() should be called to clear ADC result ready flag.

Returns
uint16_t 10-bit ADC result

◆ adc_async_read_finish

#define adc_async_read_finish ( )    (bit_clr(ADC_CONTR, ~(1 << ADC_FLAG_BIT)))

Clear ADC result ready flag.

Note
This routine suppose to be called inside ADC interrupt handler

◆ adc_async_read_start

#define adc_async_read_start ( )
Value:
do { \
{ \
bit_set(ADC_CONTR, 1 << ADC_START_BIT); \
} \
} while(0);
#define ADC_START_BIT
ADC CONTR register ADC_START bit position.
Definition adc.h:29
#define is_adc_async_read_started()
get ADC start and power flags
Definition adc.h:220

Start async ADC read operation if not started.

Set ADC start flag if it does not set After that program is not bloked. When result is ready MCU generate ADC interrupt.

Note
ADC interrupt should be enabled

◆ adc_destroy

#define adc_destroy (   void)
Value:
do { \
/* Stop ADC */ \
bit_clr(ADC_CONTR, ~(1 << ADC_START_BIT)); \
/* Clear ADC result ready flag */ \
bit_clr(ADC_CONTR, ~(1 << ADC_FLAG_BIT)); \
\
/* Set all gpio P1 port pins */ \
/* as general purpose pins mode */ \
P1ASF = 0; \
\
/* ADC power off*/ \
bit_clr(ADC_CONTR, ~ADC_POWER_ON_MSK); \
} while(0)
#define ADC_POWER_ON_MSK
Definition adc.h:35
#define ADC_FLAG_BIT
ADC CONTR register ADC_FLAG bit position.
Definition adc.h:31

Deinitialize ADC module.

Stops ongoing conversion, clears status flag, and disables analog function on all P1 pins.

◆ adc_init_input_only

#define adc_init_input_only (   p1_pin,
  adrj_flag,
  speed 
)
Value:
do { \
/* Set input only pin mode */ \
pin_input_only_init(P1, p1_pin); \
\
/* Set P1ASF bit for using pin as ADC input */ \
bit_set(P1ASF, 1 << p1_pin); \
\
/* Set ADC power on, speed and source channel pin */\
ADC_CONTR = ADC_POWER_ON_MSK | p1_pin | speed; \
\
/* Set ADC_RES-ADC_RESL or ADC_RESL-ADC_RES */ \
/* result bits order */ \
adrj_flag ? \
bit_set(CLK_DIV, 1 << ADRJ_BIT) : \
bit_clr(CLK_DIV, ~(1 << ADRJ_BIT)); \
} while(0)
#define ADRJ_BIT
CLKDIV register ADRJ bit position.
Definition adc.h:33

ADC initialization in pin input only mode.

Configures the ADC for 10-bit resolution, uses the internal voltage reference.

Parameters
p1_pinuint8_t P1 pin number. Values from 0 to 7.
adrj_flagbool ADC_RES-ADC_RESL or ADC_RESL-ADC_RES result bits order
speedadc_speed_t ADC convertion speed

◆ adc_init_open_drain

#define adc_init_open_drain (   p1_pin,
  adrj_flag,
  speed 
)
Value:
do { \
/* Set input only pin mode */ \
pin_open_drain_init(P1, p1_pin); \
\
/* Set P1ASF bit for using pin as ADC input */ \
bit_set(P1ASF, 1 << p1_pin); \
\
/* Set ADC power on, speed and source channel pin */\
ADC_CONTR = ADC_POWER_ON_MSK | p1_pin | speed; \
\
/* Set ADC_RES-ADC_RESL or ADC_RESL-ADC_RES */ \
/* result bits order */ \
adrj_flag ? \
bit_set(CLK_DIV, 1 << ADRJ_BIT) : \
bit_clr(CLK_DIV, ~(1 << ADRJ_BIT)); \
} while(0)

ADC initialization in pin open drain mode.

Configures the ADC for 10-bit resolution, uses the internal voltage reference.

Parameters
p1_pinuint8_t P1 pin number. Values from 0 to 7.
adrj_flagbool ADC_RES-ADC_RESL or ADC_RESL-ADC_RES result bits order
speedadc_speed_t ADC convertion speed

◆ adc_read_sync

#define adc_read_sync (   value)
Value:
do { \
/* Clear ADC result ready flag */ \
bit_clr(ADC_CONTR, ~(1 << ADC_FLAG_BIT)); \
/* Set ADC power on */ \
bit_set(ADC_CONTR, 1 << ADC_START_BIT); \
\
/* Waiting for ADC result is ready */ \
while (test_if_bit_cleared(ADC_CONTR, 1 << ADC_FLAG_BIT)); \
\
/* Return ADC result value */ \
*value = test_if_bit_set(CLK_DIV, 1 << ADRJ_BIT) ? \
(ADC_RESL << ADC_LOW_BITS_COUNT) | (ADC_RES & ADC_LOW_BITS_MSK) \
: \
(ADC_RES << ADC_LOW_BITS_COUNT) | (ADC_RESL & ADC_LOW_BITS_MSK);\
} while(0)
#define ADC_LOW_BITS_COUNT
ADC result shift offset.
Definition adc.h:38
#define ADC_LOW_BITS_MSK
ADC result low bits mask.
Definition adc.h:40

ADC read routine.

Clear result ready ADC flag and start ADC. Waiting for result is ready (flag up). After ADC flag is up by hardware store result to value reference

Parameters
valueuint16_t 10-bit ADC result

◆ is_adc_async_read_started

#define is_adc_async_read_started ( )    (test_if_bit_set(ADC_CONTR, 1 << ADC_START_BIT) && (ADC_CONTR & ADC_POWER_ON_MSK))

get ADC start and power flags

Returns
bool true if flags set otherwise false

Enumeration Type Documentation

◆ adc_speed_t

ADC speed enum.

describes possible convertion speeds

Enumerator
ADC_SPEED_540 

540 mcu cycles

ADC_SPEED_360 

360 mcu cycles

ADC_SPEED_180 

180 mcu cycles

ADC_SPEED_90 

90 mcu cycles