下面的程序只更新了198个字节,按设置:TIM_DMAConfig(TIM1, TIM_DMABase_CCR1, TIM_DMABurstLength_2Bytes ); 它应该更新396个字节,如果把PERIOD改成721,HALF_NUM改成249,ALL_NUM改成498,DMA就更新498个字节,符合设置,此问题有点难度,请香主帮忙看看,还有那些寄存器还没设置好,
#define TIM1_CCR1_Address 0x40012C34
#define Max_Samples 1000 //定义最大数组值
#define PERIOD 726
#define HALF_NUM 198
#define ALL_NUM 396
uint16_t Sin_Table[Max_Samples*2];
void DMA_Configuration(void)
{
DMA_InitTypeDef DMA_InitStructure;
/* DMA1 Channel5 Config */
DMA_DeInit(DMA1_Channel5);
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)TIM1_DMAR_Address;
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&Sin_Table[0];// SRC1_Buffer;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
DMA_InitStructure.DMA_BufferSize =198;
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_M2M = DMA_M2M_Disable;
DMA_Init(DMA1_Channel5, &DMA_InitStructure);
DMA_Cmd(DMA1_Channel5, ENABLE);
}
int main(void)
{
int i;
unsigned int dwVal;
i=0;
while( i<HALF_NUM )
{
Sin_Table[i]= 339;
Sin_Table[i+1]= 387;
i+=2;
}
while( i<ALL_NUM )
{
Sin_Table[i]= 387;
Sin_Table[i+1]= 339;
i+=2;
}
RCC_Configuration();
GPIO_Configuration();
DMA_Configuration();
TIM_TimeBaseStructure.TIM_Prescaler =0;
TIM_TimeBaseStructure.TIM_CounterMode =TIM_CounterMode_CenterAligned2;
TIM_TimeBaseStructure.TIM_Period = PERIOD;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_RepetitionCounter =1;// 0;
TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OutputNState =TIM_OutputNState_Enable;
TIM_OCInitStructure.TIM_Pulse = (unsigned short)(Sin_Table[0]);
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High;
TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Reset;
TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCNIdleState_Reset;
TIM_OC1Init(TIM1, &TIM_OCInitStructure);
TIM_OCInitStructure.TIM_Pulse = (unsigned short)(Sin_Table[0]>>16);
TIM_OC2Init(TIM1, &TIM_OCInitStructure);
//设置 Burst 模式,分别传输一个HalfWord给TIM1_CCR1和TIM1_CCR2
TIM_DMAConfig(TIM1, TIM_DMABase_CCR1, TIM_DMABurstLength_2Bytes );
TIM_DMACmd(TIM1, TIM_DMA_Update, ENABLE);
TIM_OC1FastConfig(TIM1, TIM_OCFast_Enable );
TIM_OC1PreloadConfig(TIM1, TIM_OCPreload_Enable);
TIM_OC2FastConfig(TIM1, TIM_OCFast_Enable );
TIM_OC2PreloadConfig(TIM1, TIM_OCPreload_Enable);
TIM_ARRPreloadConfig(TIM1, ENABLE);//ARR预装载缓冲器
TIM_Cmd(TIM1, ENABLE);
TIM_CtrlPWMOutputs(TIM1, ENABLE);
while (1) ;
} |