搜索
bottom↓
回复: 8

M48产生16路PPM信号控制16路舵机程序

[复制链接]

出0入0汤圆

发表于 2013-9-15 12:33:12 | 显示全部楼层 |阅读模式
原创M48产生16路PPM信号控制16路舵机程序
  1. //ICC-AVR application builder : 2013/9/15 7:09:24
  2. // Target : m48
  3. // Crystal: 8.0000Mhz

  4. #include <iom48v.h>
  5. #include <macros.h>

  6. void port_init(void)
  7. {
  8. PORTB = 0x00;
  9. DDRB  = 0xFF;
  10. PORTC = 0x7F; //m103 output only
  11. DDRC  = 0x00;
  12. PORTD = 0x00;
  13. DDRD  = 0xFF;
  14. }

  15. //TIMER1 initialize - prescale:1
  16. // WGM: 14) fast PWM, TOP=ICRn
  17. // desired value: 2.5mSec
  18. // actual value:  2.500mSec (0.0%)
  19. void timer1_init(void)
  20. {
  21. TCCR1B = 0x00; //stop
  22. TCNT1 = 2500*8; //setup
  23. OCR1A = 2500*8;
  24. OCR1B = 2500*8;
  25. ICR1  = 2500*8;
  26. TCCR1A = 0x02;
  27. TCCR1B = 0x19; //start Timer
  28. }

  29. unsigned char n = 7;
  30. unsigned int htla[8]={1100*8,1200*8,1300*8,1400*8,1500*8,1600*8,1700*8,1800*8};
  31. unsigned int htlb[8]={1800*8,1700*8,1600*8,1500*8,1400*8,1300*8,1200*8,1100*8};

  32. #pragma interrupt_handler timer1_compa_isr:iv_TIM1_COMPA
  33. void timer1_compa_isr(void)
  34. {
  35. //compare occured TCNT1=OCR1A
  36. PORTB = 0;
  37. }

  38. #pragma interrupt_handler timer1_compb_isr:iv_TIM1_COMPB
  39. void timer1_compb_isr(void)
  40. {
  41. //compare occured TCNT1=OCR1B
  42. PORTD = 0;
  43. }

  44. #pragma interrupt_handler timer1_ovf_isr:iv_TIM1_OVF
  45. void timer1_ovf_isr(void)
  46. {
  47. //TIMER1 has overflowed
  48. PORTB = PORTD = BIT(n);
  49. n = n ? n-1 : 7;
  50. OCR1A = htla[n];
  51. OCR1B = htlb[n];
  52. }

  53. //call this routine to initialize all peripherals
  54. void init_devices(void)
  55. {
  56. //stop errant interrupts until set up
  57. CLI(); //disable all interrupts
  58. port_init();
  59. timer1_init();

  60. MCUCR = 0x00;
  61. EICRA = 0x00; //extended ext ints
  62. EIMSK = 0x00;

  63. TIMSK0 = 0x00; //timer 0 interrupt sources
  64. TIMSK1 = 0x07; //timer 1 interrupt sources
  65. TIMSK2 = 0x00; //timer 2 interrupt sources

  66. PCMSK0 = 0x00; //pin change mask 0
  67. PCMSK1 = 0x00; //pin change mask 1
  68. PCMSK2 = 0x00; //pin change mask 2
  69. PCICR = 0x00; //pin change enable
  70. PRR = 0xE7; //power controller
  71. SEI(); //re-enable interrupts
  72. //all peripherals are now initialized
  73. }

  74. //
  75. void main(void)
  76. {
  77. init_devices();
  78. //insert your functional code here...
  79. }

复制代码

阿莫论坛20周年了!感谢大家的支持与爱护!!

知道什么是神吗?其实神本来也是人,只不过神做了人做不到的事情 所以才成了神。 (头文字D, 杜汶泽)

出0入0汤圆

 楼主| 发表于 2013-9-15 12:37:15 | 显示全部楼层
用M48的PORTB和PORTD两个端口输出16路周期为20毫秒的PPM信号,可以添加I2C接口程序,修改16路PPM输出的高电平时长,用来精确控制16路舵机或电调。

出0入0汤圆

 楼主| 发表于 2013-9-15 12:41:26 | 显示全部楼层
输出波形
attach://139265.jpg

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

出0入0汤圆

发表于 2013-9-25 09:19:10 | 显示全部楼层
这么好的帖子居然没有人顶,我顶啊 希望楼主能科普下ppm的定义越详细越好
最好有图有讲解

出0入0汤圆

发表于 2013-11-4 00:08:25 | 显示全部楼层
mark,学习学习

出0入0汤圆

发表于 2013-11-18 22:40:34 | 显示全部楼层
mark,学习.

出0入0汤圆

发表于 2014-1-5 22:39:54 | 显示全部楼层
做个记号,学习了

出0入0汤圆

发表于 2014-1-5 23:12:54 | 显示全部楼层
好贴
进来学习

出0入0汤圆

发表于 2014-1-7 18:51:55 | 显示全部楼层
mark  
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片。注意:要连续压缩2次才能满足要求!!】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-7-23 22:10

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

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