大学生
最后登录1970-1-1
在线时间 小时
注册时间2014-1-9
|
#include "./tim/bsp_general_tim_2_3_4_5.h" //í¨óö¨ê±Æ÷
static void TIM2_Mode_Config(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
u16 TimerPeriod = (SystemCoreClock / 90000 ) - 1;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,ENABLE);
// TIM_TimeBaseInitStructure.TIM_Period = TimerPeriod - 1;
//
// TIM_TimeBaseInitStructure.TIM_Prescaler = 0; //Timer clock = sysclock /(TIM_Prescaler+1) = 168M
TIM_TimeBaseInitStructure.TIM_Prescaler = ((SystemCoreClock/2)/1000000)-1; //Timer clock = sysclock /(TIM_Prescaler+1) = 168M
TIM_TimeBaseInitStructure.TIM_Period = 1000000-1; //Period = (TIM counter clock / TIM output clock) - 1 = 20K
TIM_TimeBaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up; //?????
TIM_TimeBaseInitStructure.TIM_ClockDivision = TIM_CKD_DIV1; //??????
TIM_TimeBaseInitStructure.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(TIM2,&TIM_TimeBaseInitStructure);
// Çå3y¼ÆêyÆ÷ÖD¶Ï±ê־λ
TIM_ClearFlag(TIM2, TIM_FLAG_Update);
// ¿aÆô¼ÆêyÆ÷ÖD¶Ï
TIM_ITConfig(TIM2,TIM_IT_Update,ENABLE);
// ê1Äü¼ÆêyÆ÷
TIM_Cmd(TIM2, ENABLE);
}
/**
* @brief 3õê¼»ˉ»ù±¾¶¨ê±Æ÷¶¨ê±£¬1ms2úéúò»′ÎÖD¶Ï
* @param ÎT
* @retval ÎT
*/
void TIMx_Configuration_2_3_4_5(void)
{
TIM2_Mode_Config();
}
static void Rheostat_ADC_Mode_Config(void)
{
DMA_InitTypeDef DMA_InitStructure;
ADC_InitTypeDef ADC_InitStructure;
ADC_CommonInitTypeDef ADC_CommonInitStructure;
// ¿aÆôADCê±Öó
RCC_APB2PeriphClockCmd(RHEOSTAT_ADC_CLK , ENABLE);
// ------------------DMA Init ½á11ìå2Îêy 3õê¼»ˉ--------------------------
// ADC1ê1óÃDMA2£¬êy¾Yá÷0£¬í¨μà0£¬Õa¸öêÇêÖ2á1춨ËàμÄ
// ¿aÆôDMAê±Öó
RCC_AHB1PeriphClockCmd(RHEOSTAT_ADC_DMA_CLK, ENABLE);
// íaéè»ùÖ·Îa£oADC êy¾Y¼Ä′æÆ÷μØÖ·
DMA_InitStructure.DMA_PeripheralBaseAddr = RHEOSTAT_ADC_DR_ADDR;
// ′æ′¢Æ÷μØÖ·£¬êμ¼êéϾíêÇò»¸öÄú2¿SRAMμıäá¿
DMA_InitStructure.DMA_Memory0BaseAddr = (u32)&ADC_ConvertedValue;
// êy¾Y′«êä·½ÏòÎaíaéèμ½′æ′¢Æ÷
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
// »o3åÇø′óD¡Îa1£¬»o3åÇøμÄ′óD¡ó|¸Ãμèóú′æ′¢Æ÷μÄ′óD¡
DMA_InitStructure.DMA_BufferSize = 1;
// íaéè¼Ä′æÆ÷Ö»óDò»¸ö£¬μØÖ·2»óÃμYÔö
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
// ′æ′¢Æ÷μØÖ·1춨
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable;
// // íaéèêy¾Y′óD¡Îa°ë×Ö£¬¼′ὸö×Ö½ú
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
// ′æ′¢Æ÷êy¾Y′óD¡ò2Îa°ë×Ö£¬¸úíaéèêy¾Y′óD¡Ïàí¬
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
// Ñ-»·′«êäÄ£ê½
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
// DMA ′«êäí¨μàóÅÏ輶Îa¸ß£¬μ±ê1óÃò»¸öDMAí¨μàê±£¬óÅÏ輶éèÖÃ2»ó°Ïì
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
// ½ûÖ1DMA FIFO £¬ê1óÃÖ±á¬Ä£ê½
DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;
// FIFO ′óD¡£¬FIFOģ꽽ûÖ1ê±£¬Õa¸ö2»óÃÅäÖÃ
DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull;
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
// Ñ¡Ôñ DMA í¨μ࣬í¨μà′æÔúóúá÷ÖD
DMA_InitStructure.DMA_Channel = RHEOSTAT_ADC_DMA_CHANNEL;
//3õê¼»ˉDMAá÷£¬á÷Ïàμ±óúò»¸ö′óμÄ1üμ࣬1üμààïÃæóDoü¶àí¨μà
DMA_Init(RHEOSTAT_ADC_DMA_STREAM, &DMA_InitStructure);
// ê1ÄüDMAá÷
DMA_Cmd(RHEOSTAT_ADC_DMA_STREAM, ENABLE);
// -------------------ADC Common ½á11ìå 2Îêy 3õê¼»ˉ------------------------
// ¶àá¢ADCÄ£ê½
ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;
// ê±ÖóÎafpclk x·ÖÆμ
ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2;
// ½ûÖ1DMAÖ±½ó·ÃÎêÄ£ê½
ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;
// 2éÑùê±¼ä¼ä¸ô
ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;
ADC_CommonInit(&ADC_CommonInitStructure);
// -------------------ADC Init ½á11ìå 2Îêy 3õê¼»ˉ--------------------------
// ADC ·Ö±æÂê
ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
// ½ûÖ1é¨Ãèģ꽣¬¶àí¨μà2é¼ˉ2ÅDèòa
ADC_InitStructure.ADC_ScanConvMode = DISABLE;
/***************************************************************************************************************************/
// á¬Dø×a»»
ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; /////////////////μ¥′Î×a»»
//ê1óÃèí¼t′¥·¢£¬ía2¿′¥·¢2»óÃÅäÖã¬×¢êíμô¼′¿é
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T2_TRGO; // 1ê1óö¨Æ÷′¥·¢Ä£ê½
//½ûÖ1ía2¿±ßÑØ′¥·¢
ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_Rising; // 2ê1óö¨ê±Æ÷éÏéyÑؽøDD′¥·¢
// // á¬Dø×a»»
// ADC_InitStructure.ADC_ContinuousConvMode = ENABLE; /////////////////μ¥′Î×a»»
// //½ûÖ1ía2¿±ßÑØ′¥·¢
// ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None; /////////////////////////ía2¿éÏéyÑØ′¥·¢2éÑù
// //ê1óÃèí¼t′¥·¢£¬ía2¿′¥·¢2»óÃÅäÖã¬×¢êíμô¼′¿é
// //ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC1; /////////////////////////
/******************************************************************************************************************************/
//êy¾Yóò¶ÔÆë
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
//×a»»í¨μà 1¸ö
ADC_InitStructure.ADC_NbrOfConversion = 1;
ADC_Init(RHEOSTAT_ADC, &ADC_InitStructure);
//---------------------------------------------------------------------------
// ÅäÖà ADC í¨μà×a»»Ë3DòÎa1£¬μúò»¸ö×a»»£¬2éÑùê±¼äÎa3¸öê±ÖóÖüÆú
ADC_RegularChannelConfig(RHEOSTAT_ADC, RHEOSTAT_ADC_CHANNEL, 1, ADC_SampleTime_3Cycles);
// ê1ÄüDMAÇëÇó after last transfer (Single-ADC mode)
ADC_DMARequestAfterLastTransferCmd(RHEOSTAT_ADC, ENABLE);
// ê1ÄüADC DMA
ADC_DMACmd(RHEOSTAT_ADC, ENABLE);
// ê1ÄüADC
ADC_Cmd(RHEOSTAT_ADC, ENABLE);
//¿aê¼adc×a»»£¬èí¼t′¥·¢
ADC_SoftwareStartConv(RHEOSTAT_ADC);
}
/**
* @brief ADC13õê¼»ˉ
* @param ÎT
* @retval ÎT
*/
void Rheostat_Init(void)
{
Rheostat_ADC_GPIO_Config();
Rheostat_ADC_Mode_Config();
}
|
|