PD6输出50K的波形,使用TIM3的ETR功能测量(PD2),将PD2于PD6连接,用示波器可以测得50K的波形,但是TIM3的计数器没有计数,一直为0!
?
//*****************************************************
//***************************************************************
//*************************************************
//将外部IO连到ETR
//打开PD2 时钟 PD2 JP6
RCC->AHB1ENR |= (RCC_AHB1ENR_GPIODEN);
//使用复用功能AF2 TIME3 ETR 复用
GPIOD->AFR[0] &= (~(0xF<<8));
GPIOD->AFR[0] |= (0x2 << 8);
GPIOD->MODER &= (~(0x3 << 4));
GPIOD->MODER |= (0x0 << 4);//0x2
//推挽输入
GPIOD->OTYPER &= (~(1 << 2));
//输出速度 高速
GPIOD->OSPEEDR &= ((~(0x3 << 4)));
GPIOD->OSPEEDR |= (0x2 << 4);
//悬浮
GPIOD->PUPDR &= ((~(0x3 << 4)));
GPIOD->PUPDR |= (0x0 << 4);
//***********************************************
//初始化时钟 40M 输入
RCC->APB1ENR |= (RCC_APB1ENR_TIM3EN);
//ETR设置
//不需要滤波器
temp = TIM3->SMCR;
temp &= ~(TIM_SMCR_ETF);
//预分频 0
temp &= ~(TIM_SMCR_ETPS);
//temp |= TIM_SMCR_ETF_1;
//上升沿检测
temp &= ~(TIM_SMCR_ETP);
//外部时钟模式2
temp |= TIM_SMCR_ECE;
//外部触发输入
// temp |= TIM_SMCR_TS;
//从模式选择
//temp &= ~TIM_SMCR_SMS;
// temp |= TIM_SMCR_SMS;
TIM3->SMCR = temp;
temp = 0;
//TIM3->EGR |= TIM_EGR_UG;
UART1_Printf("timer3 init TIM3->SMCR %x
", TIM3->SMCR);
//***********************************************************
//禁止计数器
// TIM3->CR1 &= ~(TIM_CR1_CEN);
//手动清除计数器
//TIM3->EGR |= TIM_EGR_UG;
//设置预分频器 1KHZ
TIM3->PSC = 0;// 2分频
//自动重载寄存器 100ms 上溢 ?
TIM3->ARR = 0xffff;
//计数初始为0
TIM3->CNT = 0;
//重复计数器
TIM3->RCR = (TIM3->RCR)&0xff;
//TIM3_CR1
temp = TIM3->CR1;
//自动重装载
temp |= TIM_CR1_ARPE;
//多脉冲模式
temp &= ~(TIM_CR1_OPM);
//更新源设置
temp |= TIM_CR1_URS;
//更新禁止选择
temp &= (~TIM_CR1_UDIS);
//方向 上
temp &= ~(TIM_CR1_DIR);
// 采样频率 Tdts = Tck_int 40M
temp &= ~(TIM_CR1_CKD);
//中心对齐模式选择 单向
temp &= ~ TIM_CR1_CMS;
TIM3->CR1 = temp;
//使能定时器6 100ms
TIM3->CR1 |= (TIM_CR1_CEN);
UART1_Printf("timer3 init TIM3->CR1 %x
",TIM3->CR1);
UART1_Printf("timer3 init TIM3->CNT %d
",TIM3->CNT);
此帖出自
小平头技术问答
但是我看它的寄存器不止这些,因为我也处于初学,所以我觉得你有些问题可以到正点原子的论坛去看看。http://www.openedv.com/
一周热门 更多>