9557 views|1 replies

5

Posts

0

Resources
The OP
 

ADC routines for the HC32F146/HC32M140 series of HuaDa microcontrollers [Copy link]

1 Abstract This application note mainly introduces how to use the ADC module of the HC32F146 / HC32M140 series chip to perform voltage conversion. 2 ADC Introduction What is ADC? Analog to digital converter. Conversion mode description  Scan mode Scan mode includes single conversion mode and continuous conversion mode. Scan mode supports sequential scanning or unordered scanning of channels. Scan mode supports timer/software trigger. Scan mode supports DMA transfer triggered by interrupt request.  Priority mode The priority order is: L1 (external port trigger) conversion > L2 (timer/software trigger) conversion > scan sampling mode conversion. Priority mode supports external port/timer/software trigger. Comparison function description  Conversion result comparison The high 12 bits of the conversion result are compared, and the comparison value can be configured. It can be selected to be greater than or less than the comparison value.  Conversion result range comparison The high 12 bits of the conversion result are compared, and the comparison upper/lower limit threshold can be configured. The comparison range can be selected to be within/outside the range, and the range can be identified as "exceeding the upper limit" or "below the lower limit". 3 ADC of HC32F146 / HC32M140 series 3.1 Introduction The ADC module of HC32F146 / HC32M140 series MCU is integrated with 12-bit precision. It can select external reference voltage Avref or analog voltage AVCC, provide scanning and priority conversion, conversion result comparison and interval comparison functions, and provide external port, timer, and software trigger mode. 3.2 Description The ADC module of this series has two conversion modes: scanning and priority conversion. The sample column ADC_PrioritySw_ScanSw in this AN mainly introduces the use of scanning conversion and priority conversion, that is, priority conversion interrupts scanning conversion. Main features of scanning conversion: Sampling channel: sequential scanning and disordered scanning. Conversion trigger: software trigger and timer trigger. Conversion mode: single conversion and continuous conversion. FIFO operation: 16-level FIFO can be provided, byte access SFD, read the highest 8 bits (31:24), half word access SFD, read the highest 16 bits (31:16), FIFO shift when word access. The main features of priority conversion: Priority mode: Priority L1 (external port trigger) > Priority L2 (software or timer trigger) > scan conversion. Sampling channel: Priority L1 and priority L2 use different registers to configure the sampling channel. Conversion trigger: external trigger, software trigger and timing trigger. Conversion mode: single conversion. FIFO operation: 4-level FIFO can be provided, byte access SFD, read the highest 8 bits (31:24), half-word access SFD, read the highest 16 bits (31:16), FIFO shifts when word access. 3.2.1 Register Introduction 4 Sample Code 4.1 Code Introduction Users can write their own code according to the above workflow to learn and verify this module, or they can directly download the sample code of the Device Driver Library (DDL) from the website of Huada Semiconductor and use the ADC Example in it for verification. The following section briefly introduces the various configurations involved in the sample ADC_PrioritySw_ScanSw used in this AN. 1) Configure GPIO: Gpio_SetAnalog( T1_PORT, T1_PIN, TRUE); Gpio_SetAnalog( T2_PORT, T2_PIN, TRUE); 2) Configure priority conversion: stcAdcPrioCfg.bExtTriggerEn = FALSE; stcAdcPrioCfg.bTimerTriggerEn = FALSE; stcAdcPrioCfg.enFifoStages = AdcPrioFifoStages1; Adc_PrioConvChnCfg(&stcAdcPrioCfg, DEFAULT_CHN, AdcChn10); 3) Configure scan conversion: stcAdcScanCfg.bRepeat = TRUE; stcAdcScanCfg.bTimerTriggerEn = FALSE; stcAdcScanCfg.enFifoStages = AdcScanFifoStages1; Adc_ScanConvChnCfg(&stcAdcScanCfg, AdcScanChnModeOrder, CHSL(AdcChn8)); 4) Configure the sampling time of each channel: stcAdcSampTimeCfg.enFreqDiv = SampFreqSysTDiv16; stcAdcSampTimeCfg.enTimeReg0 = AdcSampTime6AdcClk; stcAdcSampTimeCfg.enTimeReg1 = AdcSampTime12AdcClk; Adc_ChnSampleTimeCfg(&stcAdcSampTimeCfg, ST1CHN(AdcChn10)); 5) General configuration: stcAdcInitCfg.enAdcRefVol = AdcRefVolInternal; stcAdcInitCfg.enAdcResultAlign = AdcResultAlignLeft; stcAdcInitCfg.pstcAdcSampTimeCfg = &stcAdcSampTimeCfg; stcAdcInitCfg.pstcAdcPrioCfg = &stcAdcPrioCfg; stcAdcInitCfg.pstcAdcScanCfg = &stcAdcScanCfg; 4.2 Code Running Users can download the ADC sample code from the website of Huada Semiconductor, and run the relevant code with the evaluation board (SK-HC32F146-64L V10) to learn how to use the ADC module. The following section mainly introduces how to run the ADC sample code on the evaluation board and observe the results: - Confirm that the correct IAR (or Keil, IAR is used here for sample description, and the operation method in Keil is similar) tool is installed (please download the corresponding installation package from Huada Semiconductor in full, and refer to the user manual for installation). - Download the ADC sample code from the website of Huada Semiconductor. - Download and run the sample code: 1) Open adc-> ADC_PrioritySw_ScanSw project and open 'main.c' as shown below: 2) Click Recompile to link the entire project. 3) Click to download the code to the evaluation board. 4) You can see a view similar to the following: 5) Set a breakpoint at line 207: 6) Click Run. 7) During the scan conversion process, when the priority conversion is successfully converted 5 times, it will run to the breakpoint at line 207: 8) After running, you can close the project file. 9) Users can also further learn the functions of the ADC module by modifying the relevant configuration parameters or initialization data of the ADC in the code. 5 Summary The above chapters briefly introduce the ADC of the HC32F146 / HC32M140 series, explain the registers and some operation processes of the ADC module, and demonstrate how to use priority conversion to interrupt scan conversion. In actual development, users can configure and use ADC according to their needs.



140-1.bmp (125.99 KB, downloads: 1)

140-1.bmp

140-2.bmp (830.87 KB, downloads: 1)

140-2.bmp

HC32F146_HC32M140系列的AD转换器Rev1.0.pdf

664.78 KB, downloads: 41

This post is from MCU

Latest reply

have a look  Details Published on 2018-3-7 09:12
 

1903

Posts

0

Resources
2
 
have a look
This post is from MCU
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list