打印

请香主帮忙解答DMA同时更新寄存器时,DMA传输数目的问题

[复制链接]
2391|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
jw_andy|  楼主 | 2011-1-12 17:17 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
下面的程序只更新了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) ;
}
沙发
jw_andy|  楼主 | 2011-1-19 12:05 | 只看该作者
香主,这个问题能解决吗?

使用特权

评论回复
板凳
jw_andy|  楼主 | 2011-1-19 14:05 | 只看该作者
已经找到原因,谢谢大家的关注

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

0

主题

47

帖子

1

粉丝