hsk-libs-dev
270
High Speed Karlsruhe XC878 library collection
|
HSK Analog Digital Conversion implementation. More...
#include <Infineon/XC878.h>
#include "hsk_adc.h"
#include <string.h>
#include "../hsk_isr/hsk_isr.h"
Macros | |
#define | ADC_CLK_12MHz 0 |
Conversion clock prescaler setting for 12MHz. More... | |
#define | ADC_CLK_8MHz 1 |
Conversion clock prescaler setting for 8MHz. More... | |
#define | ADC_CLK_6MHz 2 |
Conversion clock prescaler setting for 6MHz. More... | |
#define | ADC_CLK_750kHz 3 |
Conversion clock prescaler setting for 750kHz. More... | |
#define | ADC_CHANNELS 8 |
Number of availbale ADC channels. More... | |
#define | ADC_QUEUE 4 |
Number of queue slots. More... | |
#define | BIT_CHNR 0 |
ADC_RESRxL Channel Number bits. More... | |
#define | CNT_CHNR 3 |
CHNR bit count. More... | |
#define | BIT_RESULT 6 |
ADC_RESRxLH Conversion Result bits. More... | |
#define | CNT_RESULT 10 |
RESULT bit count. More... | |
#define | BIT_DW 6 |
ADC_GLOBCTR Data Width bit. More... | |
#define | BIT_CTC 4 |
ADC_GLOBCTR Conversion Time Control bits. More... | |
#define | CNT_CTC 2 |
CTC bit count. More... | |
#define | BIT_ASEN_SEQUENTIAL 6 |
ADC_PRAR Arbitration Slot Sequential Enable bit. More... | |
#define | BIT_ASEN_PARALLEL 7 |
ADC_PRAR Arbitration Slot Parallel Enable bit. More... | |
#define | BIT_IEN 4 |
RCRx Interrupt Enable bit. More... | |
#define | BIT_WFR 6 |
RCRx Wait-for-Read Mode. More... | |
#define | BIT_VFCTR 7 |
RCRx Valid Flag Control bit. More... | |
#define | BIT_ENGT 0 |
QMR0 Enable Gate bit. More... | |
#define | BIT_ANON 7 |
ADC_GLOBCTR Analog Part Switched On bit. More... | |
#define | BIT_IMODE 4 |
SYSCON0 Interrupt Structure 2 Mode Select bit. More... | |
#define | BIT_ADC_DIS 0 |
PMCON1 ADC Disable Request bit. More... | |
#define | BIT_FILL 0 |
QSR0 bits Filling Level. More... | |
#define | CNT_FILL 2 |
Filling Level bit count. More... | |
#define | BIT_EMPTY 5 |
QSR0 bit Queue Empty. More... | |
#define | BIT_REQCHNR 0 |
ADC_QINR0 Request Channel Number bits. More... | |
#define | CNT_REQCHNR 3 |
REQCHNR bit count. More... | |
Functions | |
void | hsk_adc_isr10 (void) |
Write the 10bit conversion result to the targeted memory address. More... | |
void | hsk_adc_isr8 (void) |
Write the 8bit conversion result to the targeted memory address. More... | |
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_isr_warmup10 (void) |
Special ISR for warming up 10 bit conversions. More... | |
void | hsk_adc_warmup10 (void) |
Warm up 10 bit AD conversion. More... | |
Variables | |
static hsk_adc_channel | nextChannel = 8 |
Holds the channel of the next conversion that will be requested. More... | |
union { | |
uword * ptr10 | |
Pointer type used for 10 bit conversions. More... | |
ubyte * ptr8 | |
Pointer type used for 8 bit conversions. More... | |
} | targets [8] |
An array of target addresses to write conversion results into. More... | |
HSK Analog Digital Conversion implementation.
This file implements the functions defined in hsk_adc.h.
To be able to use all 8 channels the ADC is kept in sequential mode.
In order to reduce processing time this library uses the convention that all functions terminate with ADC register page 6. Page 6 contains the ADC queue request and status registers.
#define ADC_CHANNELS 8 |
Number of availbale ADC channels.
#define ADC_CLK_12MHz 0 |
Conversion clock prescaler setting for 12MHz.
#define ADC_CLK_6MHz 2 |
Conversion clock prescaler setting for 6MHz.
#define ADC_CLK_750kHz 3 |
Conversion clock prescaler setting for 750kHz.
#define ADC_CLK_8MHz 1 |
Conversion clock prescaler setting for 8MHz.
#define ADC_QUEUE 4 |
Number of queue slots.
#define BIT_ADC_DIS 0 |
PMCON1 ADC Disable Request bit.
#define BIT_ANON 7 |
ADC_GLOBCTR Analog Part Switched On bit.
#define BIT_ASEN_PARALLEL 7 |
ADC_PRAR Arbitration Slot Parallel Enable bit.
#define BIT_ASEN_SEQUENTIAL 6 |
ADC_PRAR Arbitration Slot Sequential Enable bit.
#define BIT_CHNR 0 |
ADC_RESRxL Channel Number bits.
#define BIT_CTC 4 |
ADC_GLOBCTR Conversion Time Control bits.
#define BIT_DW 6 |
ADC_GLOBCTR Data Width bit.
#define BIT_EMPTY 5 |
QSR0 bit Queue Empty.
#define BIT_ENGT 0 |
QMR0 Enable Gate bit.
#define BIT_FILL 0 |
QSR0 bits Filling Level.
#define BIT_IEN 4 |
RCRx Interrupt Enable bit.
#define BIT_IMODE 4 |
SYSCON0 Interrupt Structure 2 Mode Select bit.
#define BIT_REQCHNR 0 |
ADC_QINR0 Request Channel Number bits.
#define BIT_RESULT 6 |
ADC_RESRxLH Conversion Result bits.
#define BIT_VFCTR 7 |
RCRx Valid Flag Control bit.
#define BIT_WFR 6 |
RCRx Wait-for-Read Mode.
#define CNT_CHNR 3 |
CHNR bit count.
#define CNT_CTC 2 |
CTC bit count.
#define CNT_FILL 2 |
Filling Level bit count.
#define CNT_REQCHNR 3 |
REQCHNR bit count.
#define CNT_RESULT 10 |
RESULT bit count.
void hsk_adc_close | ( | const hsk_adc_channel | channel | ) |
Close the given ADC channel.
Stopp ADC if no more channels were left.
channel | The channel id |
void hsk_adc_disable | ( | void | ) |
Turns off ADC conversion unit to converse power.
void hsk_adc_enable | ( | void | ) |
Turns on ADC conversion, if previously deactivated.
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.
resolution | The conversion resolution, any of ADC_RESOLUTION_* |
convTime | The desired conversion time in µs |
|
private |
Write the 10bit conversion result to the targeted memory address.
|
private |
Write the 8bit conversion result to the targeted memory address.
|
private |
Special ISR for warming up 10 bit conversions.
This is used as the ISR by hsk_adc_warmup() after the warmup countdowns have been initialized. After all warmup countdowns have returned to zero The original ISR will be put back in control.
void hsk_adc_open10 | ( | const hsk_adc_channel | channel, |
uword *const | target | ||
) |
Open the given ADC channel in 10 bit mode.
channel | The channel id |
target | A pointer where to store conversion results |
void hsk_adc_open8 | ( | const hsk_adc_channel | channel, |
ubyte *const | target | ||
) |
Open the given ADC channel in 8 bit mode.
channel | The channel id |
target | A pointer where to store conversion results |
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.
channel | The channel id |
0 | The queue is full |
1 | A conversion request has been added to the queue |
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.
0 | No conversion request had been queued, either the queue is full or no channels have been configured |
1 | A conversion request has been added to the queue |
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.
|
static |
Holds the channel of the next conversion that will be requested.
uword* ptr10 |
Pointer type used for 10 bit conversions.
ubyte* ptr8 |
Pointer type used for 8 bit conversions.
|
static |
An array of target addresses to write conversion results into.