Introduction to ADC driver

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Introduction to ADC driver

Introduction to ADC driver

In this section, we will cover the light weight ADC driver, which enable you to read the ADC the output and raw form, and converted to scale form , or even as average level over a number of reads. The light weight ADC driver also allows you to configure a number of attributes of the converter.  So you can customize your application.

Quick overview of ADC

ADC is a system that converts an analog signal into digital signal. Simply put, Analog signals here means any variable voltage that is being monitored. It doesn’t matter what the signal is doing, it can remain the same level continuously, it can have slight wave to it, or it can be seemingly random. The analog to digital converter requires you to provide the reference voltage. That defines the maximum level that the input can be.  To determine the voltage level of the input the circular ADC generate a local voltage, and just this level until the same level as the input.  

This can be done in different ways but the circuitry will adjust the level of the local signal until the comparator to detect the two inputs are the same or lease the same as the resolution of ADC, once the signal level is matched, the output generated.  Which can be read by your application.  To calculate the signal level the ADC defines the full range from the input into the three levels.  ADC typically have a resolution of 12 to 16 bits, so the 212  to 216 different levels. Whatever level input signals determined to be add , the reading from the ADC will be a digital representation of this value compare the  reference voltage. The digital output then represents what percentage of the allowed input range the input signal is currently add.

Being at the minimum level will result an output of zero and being the max will resut in an output of 0xffff. And for inputs some in between the result is the output that represents the level measured. So if you are using a reference voltage of 3.3V for example, the reading will represent what flection the 3.3 v  the input voltage is .  If the input voltage is zero.  The reading will be 0 of course. And if the input is 3.3 v, the reading will be all FF, meaning 100 percent.

So in between, if the input voltage is 1v, the result will be roughly 30.3%. And an input of 2v, will result the input roughly 60.6%, and 3v will be 90.9%.

pastedImage_1.png

ADC Driver in MQX architecture Diagram

The light weight ADC driver is considered a low level driver and is located alongside the LWGPIO driver. This is because we don’t trade the interfaces as a part of serial communication, they passing data back and forth in blocks or in bytes, also it doesn’t make sense to be accessing the drivers through the IO subsystem.

pastedImage_2.png

 

There is a section dedicated to ADC module in bsp files folder in project. (take twrk70f120m for example)

pastedImage_3.png

The ADC priority is defined as 3, though ADC is typically not used with interrupts, 

The default reference voltage and maximum voltage is 3300mV.

The input setting of the potentiometer is connected to ADC1_SOURCE_AD20 in Twr-k70 board.

The adc1 device is designated as the default ADC device

ADC API   

1 _lwadc_init()

This function initializes the ADC module according to the parameters given in the platform specific initialization structure. Call to this function does not start any ADC conversion. This function is normally called in the BSP initialization code.

 

2  _lwadc_init_input ()

This function initializes the application allocated LWADC_STRUCT with all data needed later for quick control of particular input. This function sets the ADC input to continuous conversion mode if not already in this mode.

3 _lwadc_set_attribute / _lwadc_get_attribute : 

both this functions receive a pointer to the LWADC_STRUCT_PRT ,  and the attributes you interested in. All the attributes are defined in an enum LWADC_ATTRIBUTE.

pastedImage_4.png

4 _lwadc_read_raw ()

Read the current value of the ADC input and return the result without applying any scaling.

pastedImage_5.png

5 _lwadc_read ()

This function reads the current value of the ADC input, applies scaling according to preset parameters.

pastedImage_6.png

6 _lwadc_read_average()
This function reads num_sample samples from the specified input and returns the scaled average reading.

pastedImage_7.png

7  _lwadc_wait_next()

This function waits for a new value to be available on the specified ADC input.

Labels (1)
Comments

Hi Daniel,

I am looking for using my ADC1_SE16 on K64 micro for measuring voltages in the range of 0-160V converted to 0-3.3V using a hardware. 

Can I use the LWADC parameters like these:
         LWADC_RESOLUTION
         LWADC_REFERENCE
         LWADC_FREQUENCY
         LWADC_DIVIDER
         LWADC_DIFFERENTIAL
         LWADC_POWER_DOWN
         LWADC_NUMERATOR
         LWADC_DENOMINATOR
         LWADC_FORMAT
         LWADC_INPUT_CONVERSION_ENABLE
and get the conversion of the ADC values(read in the range of 0-3.3V) to real values (0-160V).

How are these values related to the actual value and the value read by ADC?

Thanks in anticipation.

Best regards
Sarma

No ratings
Version history
Last update:
‎11-22-2016 10:19 PM
Updated by: