MLC interface driver
Configuration settings and helper functions for ADC

Macros

#define AD_CH1   0x1
 
#define AD_CH2   0x2
 
#define AD_CH3   0x4
 
#define AD_SOCA   0x1
 
#define AD_SOCB   0x2
 
#define AD_SOCC   0x4
 
#define AD_OS0   0x0000
 
#define AD_OS1   0x0001
 
#define AD_OS2   0x0002
 
#define AD_OS3   0x0003
 
#define AD_OS4   0x0004
 
#define AD_OS5   0x0005
 
#define AD_OS6   0x0006
 
#define AD_RNG_5V   0x0000
 
#define AD_RNG_10V   0x0001
 
#define AD_SOC_ALL_DEFAULT   0x0000
 
#define AD_SOC_CH3_SOCA   0x1000
 
#define AD_SOC_CH3_SOCB   0x2000
 
#define AD_SOC_CH3_SOCAB   0x3000
 
#define AD_SOC_ALL_SOCA   0x4000
 
#define AD_SOC_ALL_SOCB   0x5000
 
#define AD_IN0   0
 
#define AD_IN1   2
 
#define AD_IN2   4
 
#define AD_IN3   6
 
#define AD_IN4   8
 
#define AD_IN5   10
 
#define AD_IN6   12
 
#define AD_IN7   14
 
#define DMA_ADCH1   AD_CH1
 
#define DMA_ADCH2   AD_CH2
 
#define DMA_ADCH3   AD_CH3
 

Functions

void MLC_ADC_reset (void)
 
void MLC_ADC_setup (unsigned int os_1, unsigned int os_2, unsigned int os_3, unsigned int rng_1, unsigned int rng_2, unsigned int rng_3)
 
void MLC_ADC_setup_SOC (uint16_t adsoc)
 
void MLC_ADC_start_conv (void)
 
void MLC_ADC_start_one_conv (uint16_t channel)
 
volatile int16_t * MLC_ADC1_read (void)
 
volatile int16_t * MLC_ADC2_read (void)
 
volatile int16_t * MLC_ADC3_read (void)
 
volatile int16_t * MLC_ADC1_get_res_ptr (void)
 
volatile int16_t * MLC_ADC2_get_res_ptr (void)
 
volatile int16_t * MLC_ADC3_get_res_ptr (void)
 
volatile mlc_adc_resultMLC_ADC1_get_res_strptr (void)
 
volatile mlc_adc_resultMLC_ADC2_get_res_strptr (void)
 
volatile mlc_adc_resultMLC_ADC3_get_res_strptr (void)
 
volatile int16_t * MLC_ADC_read (volatile int16_t *ad_res, uint16_t ad_addr)
 
unsigned int MLC_ADC_wait (void)
 
float MLC_ADC_calc_volt (int16_t value, uint16_t range)
 
void MLC_ADC_enable_isr (interrupt void *handler)
 
void MLC_ADC_disable_isr (void)
 
void MLC_DMA_enable_isr (uint16_t channel, interrupt void *handler)
 
void MLC_DMA_disable_isr (uint16_t channel)
 
uint16_t MLC_DMA_active (void)
 
void MLC_DMA_activate (void)
 
void MLC_DMA_deactivate (void)
 

Detailed Description

Macro Definition Documentation

#define AD_CH1   0x1

Constant for selecting ADC CH1.

Definition at line 318 of file MLC_drv.h.

Referenced by MLC_ADC_start_one_conv(), and MLC_DMA_enable_isr().

#define AD_CH2   0x2

Constant for selecting ADC CH2.

Definition at line 319 of file MLC_drv.h.

Referenced by MLC_ADC_start_one_conv(), and MLC_DMA_enable_isr().

#define AD_CH3   0x4

Constant for selecting ADC CH3.

Definition at line 320 of file MLC_drv.h.

Referenced by MLC_ADC_start_one_conv(), and MLC_DMA_enable_isr().

#define AD_IN0   0

Index of MSB data from ADC input 0

Definition at line 365 of file MLC_drv.h.

#define AD_IN1   2

Index of MSB data from ADC input 1

Definition at line 366 of file MLC_drv.h.

#define AD_IN2   4

Index of MSB data from ADC input 2

Definition at line 367 of file MLC_drv.h.

#define AD_IN3   6

Index of MSB data from ADC input 3

Definition at line 368 of file MLC_drv.h.

#define AD_IN4   8

Index of MSB data from ADC input 4

Definition at line 369 of file MLC_drv.h.

#define AD_IN5   10

Index of MSB data from ADC input 5

Definition at line 370 of file MLC_drv.h.

#define AD_IN6   12

Index of MSB data from ADC input 6

Definition at line 371 of file MLC_drv.h.

#define AD_IN7   14

Index of MSB data from ADC input 7

Definition at line 372 of file MLC_drv.h.

#define AD_OS0   0x0000

Constant defining no oversampling for ADC.

Definition at line 330 of file MLC_drv.h.

Referenced by MLC_init().

#define AD_OS1   0x0001

Constant defining 2x oversampling for ADC.

Definition at line 332 of file MLC_drv.h.

#define AD_OS2   0x0002

Constant defining 4x oversampling for ADC.

Definition at line 334 of file MLC_drv.h.

#define AD_OS3   0x0003

Constant defining 8x oversampling for ADC.

Definition at line 336 of file MLC_drv.h.

#define AD_OS4   0x0004

Constant defining 16x oversampling for ADC.

Definition at line 338 of file MLC_drv.h.

#define AD_OS5   0x0005

Constant defining 32x oversampling for ADC.

Definition at line 340 of file MLC_drv.h.

#define AD_OS6   0x0006

Constant defining 64x oversampling for ADC.

Definition at line 342 of file MLC_drv.h.

#define AD_RNG_10V   0x0001

Constant defining +/- 10V input range of ADC.

Definition at line 345 of file MLC_drv.h.

#define AD_RNG_5V   0x0000

Constant defining +/- 5V input range of ADC.

Definition at line 344 of file MLC_drv.h.

Referenced by MLC_init().

#define AD_SOC_ALL_DEFAULT   0x0000

CH3 will start with toggling of ADSOC pin - no HW SOC support

Definition at line 354 of file MLC_drv.h.

Referenced by MLC_init().

#define AD_SOC_ALL_SOCA   0x4000

CH1 + CH2 + CH3 will start with ADSOCA

Definition at line 358 of file MLC_drv.h.

#define AD_SOC_ALL_SOCB   0x5000

CH1 + CH2 + CH3 will start with ADSOCB

Definition at line 359 of file MLC_drv.h.

#define AD_SOC_CH3_SOCA   0x1000

CH1 + CH3 share ADSOCA, CH2 uses default ADSOCB

Definition at line 355 of file MLC_drv.h.

#define AD_SOC_CH3_SOCAB   0x3000

CH3 will start with CH1 or CH2 and uses ADSOCA or ADSOCB in the same time

Definition at line 357 of file MLC_drv.h.

#define AD_SOC_CH3_SOCB   0x2000

CH1 uses ADSOCA, CH2 + CH3 share default ADSOCB

Definition at line 356 of file MLC_drv.h.

#define AD_SOCA   0x1

Constant for selecting ADC CONVST A.

Definition at line 322 of file MLC_drv.h.

#define AD_SOCB   0x2

Constant for selecting ADC CONVST B.

Definition at line 323 of file MLC_drv.h.

#define AD_SOCC   0x4

Constant for selecting ADC CONVST C.

Definition at line 324 of file MLC_drv.h.

#define DMA_ADCH1   AD_CH1

Constant defining DMA CH1

Definition at line 374 of file MLC_drv.h.

Referenced by MLC_DMA_disable_isr().

#define DMA_ADCH2   AD_CH2

Constant defining DMA CH2

Definition at line 375 of file MLC_drv.h.

Referenced by MLC_DMA_disable_isr().

#define DMA_ADCH3   AD_CH3

Constant defining DMA CH3

Definition at line 376 of file MLC_drv.h.

Referenced by MLC_DMA_disable_isr().

Function Documentation

volatile int16_t* MLC_ADC1_get_res_ptr ( void  )

Returns pointer to array where measured values are stored, this function will NOT actually read a new data from AD1 !

Returns
address of array with results

Definition at line 1354 of file MLC_drv.c.

volatile mlc_adc_result* MLC_ADC1_get_res_strptr ( void  )

Returns pointer to structure where measured values are stored, this function will NOT actually read a new data from AD1 !

Returns
address of structure mlc_adc_result with results

Definition at line 1366 of file MLC_drv.c.

volatile int16_t* MLC_ADC1_read ( void  )

Reads measured values from ADC No.1 this function triggers full read sequence and update values of array of AD results

Returns
address of array with results

Definition at line 1379 of file MLC_drv.c.

References MLC_ADC_read(), and READ_AD1.

Here is the call graph for this function:

volatile int16_t* MLC_ADC2_get_res_ptr ( void  )

Returns pointer to array where measured values are stored, this function will NOT actually read a new data from AD2 !

Returns
address of array with results

Definition at line 1358 of file MLC_drv.c.

volatile mlc_adc_result* MLC_ADC2_get_res_strptr ( void  )

Returns pointer to structure where measured values are stored, this function will NOT actually read a new data from AD2 !

Returns
address of structure mlc_adc_result with results

Definition at line 1370 of file MLC_drv.c.

volatile int16_t* MLC_ADC2_read ( void  )

Reads measured values from ADC No.2 this function triggers full read sequence and update values of array of AD results

Returns
address of array with results

Definition at line 1384 of file MLC_drv.c.

References MLC_ADC_read(), and READ_AD2.

Here is the call graph for this function:

volatile int16_t* MLC_ADC3_get_res_ptr ( void  )

Returns pointer to array where measured values are stored, this function will NOT actually read a new data from AD3 !

Returns
address of array with results

Definition at line 1362 of file MLC_drv.c.

volatile mlc_adc_result* MLC_ADC3_get_res_strptr ( void  )

Returns pointer to structure where measured values are stored, this function will NOT actually read a new data from AD3 !

Returns
address of structure mlc_adc_result with results

Definition at line 1374 of file MLC_drv.c.

volatile int16_t* MLC_ADC3_read ( void  )

Reads measured values from ADC No.3 this function triggers full read sequence and update values of array of AD results

Returns
address of array with results

Definition at line 1389 of file MLC_drv.c.

References MLC_ADC_read(), and READ_AD3.

Here is the call graph for this function:

float MLC_ADC_calc_volt ( int16_t  value,
uint16_t  range 
)

Helper function, it calculate voltage from measured value.

Parameters
valuemeasured value from ADC, 16 bits
rangeuse AD_RNG_5V or AD_RNG_10V
Returns
real value measured by ADC

Definition at line 1393 of file MLC_drv.c.

void MLC_ADC_disable_isr ( void  )

Function for disabling AD end of conversion interrupt.

Definition at line 1043 of file MLC_drv.c.

void MLC_ADC_enable_isr ( interrupt void *  handler)

Function for setup of handler function called after conversion of AD ends. The handler has to acknowledge interrupt by command PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;

TMS320F28335 - it uses XINT1 - i.e. int1.4. This interrupt should not be used in user code.

Parameters
handlerpointer to function to call when conversion end. It MUST be defined with flag interrupt.

Definition at line 1008 of file MLC_drv.c.

Referenced by MLC_ADC_setup().

Here is the caller graph for this function:

volatile int16_t* MLC_ADC_read ( volatile int16_t *  ad_res,
uint16_t  ad_addr 
)

This function can be used to save some computing time. Use as MLC_read_AD(AD_res_1,READ_AD1);

Parameters
ad_respointer to array where to store results. The array must have size of 16 words
ad_addraddress of ADC in memory, use READ_ADx constant.
Returns
pointer to array passed as ad_res

Definition at line 1259 of file MLC_drv.c.

References MLC_READ, READ_AD1, READ_AD2, and READ_AD3.

Referenced by MLC_ADC1_read(), MLC_ADC2_read(), and MLC_ADC3_read().

Here is the caller graph for this function:

void MLC_ADC_reset ( void  )

This function encapsulate reset process of ADCs.

Definition at line 1061 of file MLC_drv.c.

References DELAY_US(), MLC_WRITE, WRITE_CLRRES_AD, and WRITE_SETRES_AD.

Referenced by MLC_init().

Here is the call graph for this function:

Here is the caller graph for this function:

void MLC_ADC_setup ( unsigned int  os_1,
unsigned int  os_2,
unsigned int  os_3,
unsigned int  rng_1,
unsigned int  rng_2,
unsigned int  rng_3 
)

Function for setting oversampling and input range of all three ADCs.

Parameters
os_1,os_2,os_3oversampling setup for each channel, use AD_OS0 - AD_OS6. Oversampling will prolong conversion time. I.e. if AD_OS6 is set, then conversion time will be 2^6*4us = 256us ! All ADC shares one BUSY signal, therefore conversion end is detected after slowest conversion finished.
rng_1,rng_2,rng_3set input range, use AD_RNG_5V or AD_RNG_10V

Definition at line 1191 of file MLC_drv.c.

References DELAY_US(), MLC_ADC_enable_isr(), MLC_WRITE, and WRITE_AD_CONF.

Referenced by MLC_init().

Here is the call graph for this function:

Here is the caller graph for this function:

void MLC_ADC_setup_SOC ( uint16_t  adsoc)

Function for setting CONVST source pin. Parameter defines which HW pin starts which ADC channel, valid combinations are defined by AD_SOC_* constants.

Parameters
adsocis one of AD_SOC_* constants.

Definition at line 1422 of file MLC_drv.c.

References MLC_WRITE, and WRITE_AD_CONF.

Referenced by MLC_init().

Here is the caller graph for this function:

void MLC_ADC_start_conv ( void  )

Function for manually start conversion of all three channels. In this case settings setted by calling MLC_ADC_setup_SOC() has no meaning. All three channels will be always started.

Definition at line 1084 of file MLC_drv.c.

References DELAY_US(), mlc_info_t::pcb_hw_ver, and PCB_REV_1.

Here is the call graph for this function:

void MLC_ADC_start_one_conv ( uint16_t  channel)

Function for manually start conversion of channel. Which ADC(s) will start measure is defined by MLC_ADC_setup_SOC() function.

Parameters
channelis one of AD_CHx constants.

Definition at line 1122 of file MLC_drv.c.

References AD_CH1, AD_CH2, AD_CH3, DELAY_US(), mlc_info_t::pcb_hw_ver, and PCB_REV_1.

Here is the call graph for this function:

unsigned int MLC_ADC_wait ( void  )

Waits for all AD converters finished conversion and while waiting it blocks.

Returns
number of while cycles spent in blocked state.

Definition at line 1239 of file MLC_drv.c.

void MLC_DMA_activate ( void  )

Activate start of DMA transfer after ADC conversion end.

Definition at line 901 of file MLC_drv.c.

uint16_t MLC_DMA_active ( void  )

Function for checking DMA transfer activity.

Returns
if > 0 then DMA transfer is active

Definition at line 891 of file MLC_drv.c.

void MLC_DMA_deactivate ( void  )

Disable start of DMA transfer after ADC conversion end.

Definition at line 916 of file MLC_drv.c.

void MLC_DMA_disable_isr ( uint16_t  channel)

Disables DMA interrupt for specified channel.

Parameters
channelDMA channel to disable, use one of constant of DMA_ADCHx

Definition at line 972 of file MLC_drv.c.

References DMA_ADCH1, DMA_ADCH2, and DMA_ADCH3.

void MLC_DMA_enable_isr ( uint16_t  channel,
interrupt void *  handler 
)

Enables DMA interrupt and specify user handler. Interrupt handler must acknowledge interrupt at least by command PieCtrlRegs.PIEACK.all = PIEACK_GROUP7;

If DMA transfer is enabled, then it is automatically started after ADC conversion ends.

Parameters
channelDMA channel to enable, use one of constant of DMA_ADCHx
handlerpointer to function to call when data transfer end. It MUST be defined with flag interrupt.

Definition at line 932 of file MLC_drv.c.

References AD_CH1, AD_CH2, AD_CH3, BASE_ADDRESS, dmaConfigCtrlPacket(), and READ_AD1.

Here is the call graph for this function: