极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10949|回复: 3

求助,急

[复制链接]
发表于 2015-1-3 22:48:42 | 显示全部楼层 |阅读模式
对定时器不是太明白
下面是摘自国外的一段程序,不明白为什么是 pin 49 输入,2560的板子
高手们给解释下,万分感谢

void Init_PWM4(void)
{
  pinMode(49, INPUT);
  pinMode(7,OUTPUT);
  pinMode(8,OUTPUT);
      //Remember the registers not declared here remains zero by default...
  TCCR4A =((1<<WGM40)|(1<<WGM41)|(1<<COM4C1)|(1<<COM4B1)|(1<<COM4A1));  
  TCCR4B = ((1<<WGM43)|(1<<WGM42)|(1<<CS41)|(1<<ICES4)); //Prescaler set to 8, that give us a resolution of 2us, read page 134 of data sheet
  OCR4A = 40000; ///50hz freq...Datasheet says  (system_freq/prescaler)/target frequency. So (16000000hz/8)/50hz=40000,
  //must be 50hz because is the servo standard (every 20 ms, and 1hz = 1sec) 1000ms/20ms=50hz, elementary school stuff...   
  OCR4B = 3000; //PH4, OUT5
  OCR4C = 3000; //PH5, OUT4

  TIMSK4 |= (1<<ICIE4); //Timer interrupt mask
  sei();
  
}
/****************************************************
  Interrupt Vector
****************************************************/
ISR(TIMER4_CAPT_vect)//interrupt.
{
  if(((1<<ICES4)&TCCR4B) >= 0x01)
  {
    if(Start_Pulse>Stop_Pulse) //Checking if the Stop Pulse overflow the register, if yes i normalize it.
    {
      Stop_Pulse+=40000; //Nomarlizing the stop pulse.
    }
    Pulse_Width=Stop_Pulse-Start_Pulse; //Calculating pulse
       if(Pulse_Width>5000) //Verify if this is the sync pulse
       {
        PPM_Counter=0; //If yes restart the counter
       }
       else
       {
        PPM_Counter=Pulse_Width; //Saving pulse.
        PPM_Counter++;
       }
    Start_Pulse=ICR4;
    TCCR4B &=(~(1<<ICES4)); //Changing edge detector.
  }
  else
  {
    Stop_Pulse=ICR4; //Capturing time stop of the drop edge
    TCCR4B |=(1<<ICES4); //Changing edge detector.
   
  }
  
}
回复

使用道具 举报

 楼主| 发表于 2015-1-3 22:51:08 | 显示全部楼层
另外,timer4 和pin49有何关联
回复 支持 反对

使用道具 举报

发表于 2015-1-4 14:15:49 | 显示全部楼层
我更看不懂
回复 支持 反对

使用道具 举报

发表于 2015-1-4 16:06:11 | 显示全部楼层
楼主的代码没看出来很急啊?
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|联系我们|极客工坊

GMT+8, 2026-6-17 09:55 , Processed in 0.061863 second(s), 19 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表