hsk-libs-dev  270
High Speed Karlsruhe XC878 library collection
Macros | Typedefs | Functions
hsk_adc.h File Reference

HSK Analog Digital Conversion headers. More...

#include "../hsk_isr/hsk_isr.isr"
Include dependency graph for hsk_adc.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define ADC_RESOLUTION_10   0
 10 bit ADC resolution. More...
 
#define ADC_RESOLUTION_8   1
 8 bit ADC resultion. More...
 
#define hsk_adc_open   hsk_adc_open10
 Backwards compatibility hack. More...
 
#define hsk_adc_warmup   hsk_adc_warmup10
 Backwards compatibility hack. More...
 

Typedefs

typedef ubyte hsk_adc_channel
 Typedef for ADC channel ids. More...
 

Functions

void hsk_adc_init (ubyte resolution, uword convTime)
 Initialize the AD conversion. More...
 
void hsk_adc_enable (void)
 Turns on ADC conversion, if previously deactivated. More...
 
void hsk_adc_disable (void)
 Turns off ADC conversion unit to converse power. More...
 
void hsk_adc_open10 (const hsk_adc_channel channel, uword *const target)
 Open the given ADC channel in 10 bit mode. More...
 
void hsk_adc_open8 (const hsk_adc_channel channel, ubyte *const target)
 Open the given ADC channel in 8 bit mode. More...
 
void hsk_adc_close (const hsk_adc_channel channel)
 Close the given ADC channel. More...
 
bool hsk_adc_service (void)
 A maintenance function that takes care of keeping AD conversions going. More...
 
bool hsk_adc_request (const hsk_adc_channel channel)
 Requests an ADC for a specific channel. More...
 
void hsk_adc_warmup10 (void)
 Warm up 10 bit AD conversion. More...
 

Detailed Description

HSK Analog Digital Conversion headers.

This library provides access to all 8 ADC channels. Each channel can be provided with a pointer. Every completed conversion is written to the address provided by the pointer. The target memory can be protected for read access by msking the interrupts with EADC.

The conversion time can be freely configured in a wide range. Even short conversion times like 5µs yield good precission.

In order to keep the conversion going a service function hsk_adc_service() has to be called on a regular basis. This prevents locking up of the CPU due to an overload of interrupts, the ADC module can provide a new conversion result every 30 clock cycles.

Making the hsk_adc_service() call only as often as needed reduces the drain on the analogue input and reduces flickering.

Alternatively hsk_adc_request() can be used to request single just in time conversions.

Author
kami

Macro Definition Documentation

§ ADC_RESOLUTION_10

#define ADC_RESOLUTION_10   0

10 bit ADC resolution.

§ ADC_RESOLUTION_8

#define ADC_RESOLUTION_8   1

8 bit ADC resultion.

§ hsk_adc_open

#define hsk_adc_open   hsk_adc_open10

Backwards compatibility hack.

Deprecated:
Use hsk_adc_open10() or hsk_adc_open8() as appropriate

§ hsk_adc_warmup

#define hsk_adc_warmup   hsk_adc_warmup10

Backwards compatibility hack.

Deprecated:
Use hsk_adc_warmup10()

Typedef Documentation

§ hsk_adc_channel

typedef ubyte hsk_adc_channel

Typedef for ADC channel ids.

Function Documentation

§ hsk_adc_close()

void hsk_adc_close ( const hsk_adc_channel  channel)

Close the given ADC channel.

Stopp ADC if no more channels were left.

Parameters
channelThe channel id

§ hsk_adc_disable()

void hsk_adc_disable ( void  )

Turns off ADC conversion unit to converse power.

§ hsk_adc_enable()

void hsk_adc_enable ( void  )

Turns on ADC conversion, if previously deactivated.

§ hsk_adc_init()

void hsk_adc_init ( ubyte  resolution,
uword  convTime 
)

Initialize the AD conversion.

The shortest possible conversion time is 1.25µs, the longest is 714.75µs. The given value will be rounded down.

Note if hsk_adc_service() is not called in intervals shorter than convTime, there will be a waiting period between conversions. This prevents locking up of the controler with erratic interrupts.

There is a 4 entry queue, for starting conversions, so it suffices to average the interval below convTime.

All already open channels will be closed upon calling this function.

Parameters
resolutionThe conversion resolution, any of ADC_RESOLUTION_*
convTimeThe desired conversion time in µs
Here is the call graph for this function:

§ hsk_adc_open10()

void hsk_adc_open10 ( const hsk_adc_channel  channel,
uword *const  target 
)

Open the given ADC channel in 10 bit mode.

Parameters
channelThe channel id
targetA pointer where to store conversion results

§ hsk_adc_open8()

void hsk_adc_open8 ( const hsk_adc_channel  channel,
ubyte *const  target 
)

Open the given ADC channel in 8 bit mode.

Parameters
channelThe channel id
targetA pointer where to store conversion results

§ hsk_adc_request()

bool hsk_adc_request ( const hsk_adc_channel  channel)

Requests an ADC for a specific channel.

This function is an alternative to hsk_adc_service(). Make requests in time before the updated value is required.

This function uses the same queue as hsk_adc_service(), if the queue is full it fails silently.

Parameters
channelThe channel id
Return values
0The queue is full
1A conversion request has been added to the queue

§ hsk_adc_service()

bool hsk_adc_service ( void  )

A maintenance function that takes care of keeping AD conversions going.

This has to be called repeatedly.

There is a queue of up to 4 conversion jobs. One call of this function only adds one job to the queue.

Return values
0No conversion request had been queued, either the queue is full or no channels have been configured
1A conversion request has been added to the queue
Here is the call graph for this function:

§ hsk_adc_warmup10()

void hsk_adc_warmup10 ( void  )

Warm up 10 bit AD conversion.

I.e. make sure all conversion targets have been initialized with a conversion result. This is a blocking function only intended for single use during the boot procedure.

This function will not terminate unless interrupts are enabled.

Note
This function only works in 10 bit mode, because in 8 bit mode it is impossible to initialize targets with an invalid value.
Here is the call graph for this function: