智能车制作

标题: kl25脉冲计数 [打印本页]

作者: 綿婲/ka餹    时间: 2014-5-20 15:14
标题: kl25脉冲计数
有没有kl25脉冲计数写出来的,拿出来分享一下。

作者: 灬爱    时间: 2014-5-20 15:35
有!可惜不是我!
作者: chenqiang    时间: 2014-5-20 15:39
void Counter0_Init(void)
{
        /*First configure the pin of the module will be use*/
        SIM->SCGC5 |=(uint32_t)(0x1UL<<11);                        //open the clock of the PTC
        PORTC->PCR[5] &=~(uint32_t)(0x7UL<<8);
        PORTC->PCR[5] |=(uint32_t)(0x3UL<<8);        //PTC5 for ALT3(LPTMR_ALT2)

        /*Configure the module*/
        SIM->SCGC5 |=(uint32_t)(0x1UL<<0);                        //open the clock of the LPTMR0
        LPTMR0->CSR =0;
        LPTMR0->PSR        =0;
  LPTMR0->CMR        =0xFFFFUL;
        LPTMR0->PSR        |=(uint32_t)(0x1UL<<2);                //prescaler and glitch filter bypassed,if you want to use it,reference the book
       
        LPTMR0->CSR        &=~(uint32_t)(0x3UL<<4);
        LPTMR0->CSR |=(uint32_t)(0x2UL<<4);                //Select the LPTMR_ALT2 as the input clk
        LPTMR0->CSR |=(uint32_t)(0x1UL<<1);                //counter mode selected
       
        LPTMR0->CSR        |=(uint32_t)0x1UL;                        //enable the counter
}
uint32_t Counter0_Read(void)
{
        uint32_t temp=0;
        LPTMR0->CNR =0x00;
        temp=LPTMR0->CNR;
        return temp;
}
void Counter0_Clear(void)
{
        LPTMR0->CSR =0;
        LPTMR0->PSR        =0;
  LPTMR0->CMR        =0xFFFFUL;
        LPTMR0->PSR        |=(uint32_t)(0x1UL<<2);                //prescaler and glitch filter bypassed,if you want to use it,reference the book
       
        LPTMR0->CSR        &=~(uint32_t)(0x3UL<<4);
        LPTMR0->CSR |=(uint32_t)(0x2UL<<4);                //Select the LPTMR_ALT2 as the input clk
        LPTMR0->CSR |=(uint32_t)(0x1UL<<1);                //counter mode selected
       
        LPTMR0->CSR        |=(uint32_t)0x1UL;                        //enable the counter
}
作者: 綿婲/ka餹    时间: 2014-5-20 16:59
chenqiang 发表于 2014-5-20 15:39
void Counter0_Init(void)
{
        /*First configure the pin of the module will be use*/

你用了吗,能测出来吗,我大致也这样写的,但是测不出来

作者: chenqiang    时间: 2014-5-20 17:06
綿婲/ka餹 发表于 2014-5-20 16:59
你用了吗,能测出来吗,我大致也这样写的,但是测不出来

用了,挺好用的。能计数啊

作者: chenqiang    时间: 2014-5-20 17:07
綿婲/ka餹 发表于 2014-5-20 16:59
你用了吗,能测出来吗,我大致也这样写的,但是测不出来

最大计数为65535,在到达这个数之前要清零。

作者: 綿婲/ka餹    时间: 2014-5-20 17:45
chenqiang 发表于 2014-5-20 17:06
用了,挺好用的。能计数啊

哦,我试试,有什么问题再问你


作者: 吕江涛    时间: 2014-7-8 14:07
挺好的,但我想实现两路脉冲计数怎么办呢?

作者: 国际化    时间: 2014-7-9 11:31
chenqiang 发表于 2014-5-20 15:39
void Counter0_Init(void)
{
        /*First configure the pin of the module will be use*/

请问一下,我用lptmr脉冲计数,发现它在速度快的时候测不准,超过正确值很多,跳动很大。你有没有遇到这种情况啊?

作者: chenqiang    时间: 2014-7-9 21:54
国际化 发表于 2014-7-9 11:31
请问一下,我用lptmr脉冲计数,发现它在速度快的时候测不准,超过正确值很多,跳动很大。你有没有遇到这种 ...

没有遇到过这种情况呢

作者: 枫林霜叶    时间: 2015-3-20 17:52
我也想问一下,要是有两个编码器,该怎么办呢?
作者: 綿婲/ka餹    时间: 2015-3-20 23:00
枫林霜叶 发表于 2015-3-20 17:52
我也想问一下,要是有两个编码器,该怎么办呢?

引脚中断可以测,DMA也可以






欢迎光临 智能车制作 (http://dns.znczz.com/) Powered by Discuz! X3.2