📄 iar-
字号:
/****************************************Copyright (c)****************************************************
** Guangzhou ZHIYUAN electronics Co.,LTD.
**
** http:// www.embedtools.com
**
**--------------File Info---------------------------------------------------------------------------------
** File Name: ADC.c
** Last modified Date: 2007.08.24
** Last Version: V1.0
** Description: A/D转换触发方式和转换程序
**
**--------------------------------------------------------------------------------------------------------
** Created By: Kang qinhua
** Created date: 2007.10.10
** Version: V1.0
** Descriptions: The original version 初始版本
**
**--------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
** Version:
** Description:
**
*********************************************************************************************************/
#include "includes.h"
#include "PLLSet.h"
unsigned long ulData; /* 采样数据缓冲器 */
static uint8 flag_Charge; /* 采样次数 */
uint32 flag_ADC_finish = 0; /* 采样完成标志 */
uint16 Charge_Val[3] = {0, 0, 0}; /* 存放采样数据 */
/*********************************************************************************************************
** Function name: ADC_Trigger
** Descriptions: 配置A/D的触发源,用户根据实际需要在这个函数里配置对应的触发源
** input parameters: 无
** output parameters: 无
** Returned value: 无
*********************************************************************************************************/
void ADC_Trigger(void)
{
ADCSequenceConfigure(ADC_BASE, 0, ADC_TRIGGER_TIMER, 0); /* 配置为定时器触发A/D */
SysCtlPeripheralEnable( SYSCTL_PERIPH_TIMER0 ); /* 使能定时器0外设 */
TimerConfigure(TIMER0_BASE, TIMER_CFG_32_BIT_PER); /* 配置为32位周期定时器 */
TimerLoadSet(TIMER0_BASE, TIMER_A, 0xfff0); /* 设置定时器装载值为0xfff0 */
TimerControlTrigger(TIMER0_BASE, TIMER_A, TRUE); /* 使能触发输出 */
TimerEnable(TIMER0_BASE, TIMER_A); /* 使能定时器并开始等待边沿事件*/
}
/*********************************************************************************************************
** Function name: ADC_Init
** Descriptions: A/D初始化
** input parameters: 无
** output parameters: 无
** Returned value: 无
*********************************************************************************************************/
void ADC_Init(void)
{
PLLSet(); /* 设置PLL */
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC); /* 使能ADC模块时钟 */
SysCtlADCSpeedSet(SYSCTL_ADCSPEED_125KSPS); /* 125KSps采样率 */
ADCSequenceDisable(ADC_BASE, 0); /* 禁能0 */
IntMasterEnable(); /* 使能处理器中断 */
IntEnable(INT_ADC0); /* 使能AD中断 */
ADCIntEnable(ADC_BASE, 0); /* 使能AD中断模块 */
ADC_Trigger();
/*
* 确定ADC的采样步数,确定每一步的采样通道,并在每一通道采样后产生中断
*/
ADCSequenceStepConfigure(ADC_BASE, 0, 0, ADC_CTL_CH0 | ADC_CTL_IE);
ADCSequenceStepConfigure(ADC_BASE, 0, 1, ADC_CTL_CH1 | ADC_CTL_IE);
ADCSequenceStepConfigure(ADC_BASE, 0, 2, ADC_CTL_TS | ADC_CTL_IE | ADC_CTL_END);
ADCHardwareOversampleConfigure(ADC_BASE,16); /* 为对16个采样进行平均计算 */
ADCSequenceEnable(ADC_BASE, 0); /* 使能采样序列0 */
/* ADCSequenceEnable(ADC_BASE, 1); */ /* 使能采样序列1 */
}
/*********************************************************************************************************
** Function name: ADC_Sequence_0_ISR
** Descriptions: A/D中断服务程序
** input parameters: 无
** output parameters: 无
** Returned value: 无
*********************************************************************************************************/
void ADC_Sequence_0_ISR(void)
{
ADCIntClear(ADC_BASE,0); /* 清除中断标志位 */
while (!(HWREG(ADC_BASE + 0X04C) & 0X100)) {
ADCSequenceDataGet(ADC_BASE, 0, &ulData); /* 读出10位转换结果 */
ulData = ((ulData & 0x3ff) * 1000 * 3) / 1023;
Charge_Val[flag_Charge] = ulData;
flag_Charge++;
if ( flag_Charge >= 3) {
flag_Charge = 0;
flag_ADC_finish = 1; /* A/D转换完成标志位 */
}
}
}
/*********************************************************************************************************
END FILE
*********************************************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -