在线时间0 小时
UID392480
ST金币0
蝴蝶豆0
注册时间2012-9-28
新手上路
- 最后登录
- 1970-1-1
|
a0a.1 0b0c
加220时两路电流采样数据完全不对 但母线电压很准
单15v电源供电时加电位器采样很准 不知道是怎么回事
求各位大神帮帮忙!!
#include
#include "stm32f4_discovery.h"
/* ADC_DMA2 Macro */
#define ADC1_DR_ADDRESS ((uint32_t)0x4001204C)
#define ADC2_DR_ADDRESS ((uint32_t)0x4001214C)
/*** Private Structures define ***/
#include
ADC_InitTypeDef ADC_InitStructure;
ADC_CommonInitTypeDef ADC_CommonInitStructure;
DMA_InitTypeDef DMA_InitStructure;
/* Private variables */
extern uint16_t ADC1ConvertedValue[4];
extern uint16_t ADC2ConvertedValue[4];
/* ADCs configuration: triple interleaved with 5cycles delay to reach 6Msps */
void ADC_Common_Configuration(void)
{
/************************ ADC Common configuration **************************/
ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;
ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;
ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_2;
ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2;
ADC_CommonInit(&ADC_CommonInitStructure);
}
/*****************ADC1 Configuration****************/
/* Use The Channel 0,3,6,8,9,10,12,13 To Convert */
void ADC1_Configuration(void)
{
/* ENABLE The ADC Clock */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE); //
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
ADC_InitStructure.ADC_ScanConvMode = ENABLE;
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC1;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfConversion = 3;//
ADC_Init(ADC1, &ADC_InitStructure);
/**************以上是ADC_Init函数,还要指定通道转换顺序,采样时间等************/
/* ADC1 规则通道12(Channel 12)配置 */
ADC_RegularChannelConfig(ADC1, ADC_Channel_12, 1, ADC_SampleTime_3Cycles);//
ADC_RegularChannelConfig(ADC1, ADC_Channel_13, 2, ADC_SampleTime_3Cycles);//
ADC_RegularChannelConfig(ADC1, ADC_Channel_10, 3, ADC_SampleTime_3Cycles);//
// ADC_RegularChannelConfig(ADC1, ADC_Channel_8, 4, ADC_SampleTime_3Cycles);//
ADC_DMARequestAfterLastTransferCmd(ADC1, ENABLE);
/* Enable ADC1 DMA */
ADC_DMACmd(ADC1, ENABLE);
/* Enable ADC1 */
ADC_Cmd(ADC1, ENABLE);
/* Start ADC1 Software Conversion */
ADC_SoftwareStartConv(ADC1);
//ADC_ITConfig(ADC1, ADC_IT_AWD, ENABLE);
//ADC_ClearFlag(ADC1, ADC_FLAG_JEOC);
//ADC_SoftwareStartInjectedConv(ADC1);
}
/* DMA2_Stream0 Configuration */
void DMA2_Configuration(void)
{
/* ENABLE The DMA Clock */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE); //打开DMA2时钟
DMA_DeInit(DMA2_Stream0);
/* DMA2 Stream 0 channel 0 configuration */
DMA_InitStructure.DMA_Channel = DMA_Channel_0;
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)ADC1_DR_ADDRESS;
DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)&ADC1ConvertedValue;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
DMA_InitStructure.DMA_BufferSize = 3;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;
DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull;
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
DMA_Init(DMA2_Stream0, &DMA_InitStructure);
/* DMA2_Stream0 enable */
DMA_Cmd(DMA2_Stream0, ENABLE);
} |
|