[问答] 用M16的TC1产生PWM信号并同时不断改变频率,出现PWM信号不时有断开的现象,这是为什么?如何解决?

mvuwerw ( 楼主 ) 2018-6-26 04:08:09  显示全部楼层
本帖最后由 一只耳朵怪 于 2018-6-26 10:39 编辑

发现M16的TC1的重大缺陷!!!!! 本人用M16的TC1产生PWM信号,并且在产生信号的同时不断改变频率,但变频幅度很小,这时就出现一个很令人费解的现象,PWM信号会不时有断开的现象 PWM频率:28KHz OC1A、OC1B双路输出:想得到的信号是:如图正常的波形 但是一旦改变频率,两路的信号会随即的中断6.5ms左右,如图断开的波形,不知其解,各位高手请指教 程序: // Target : M16 // Crystal: 10.000Mhz #include  #include  void port_init(void) { PORTA = 0x00; DDRA = 0x00; PORTB = 0x00; DDRB = 0x00; PORTC = 0x00; //m103 output only DDRC = 0x00; PORTD = 0x00; DDRD = 0b00110000; } //TIMER1 initialize - prescale:1 // WGM: 8) PWM phz freq correct, TOP=ICRn // desired value: 28KHz // actual value: 28.090KHz (0.3%) void timer1_init(void) { TCCR1B = 0x00; //stop TCNT1H = 0xFF; //setup TCNT1L = 0x4E; OCR1AH = 0x00; OCR1AL = 0xB2-0x50; OCR1BH = 0x00; OCR1BL = 0x50; ICR1H = 0x00; ICR1L = 0xB2; TCCR1A = 0xB0; TCCR1B = 0x11; //start Timer } //call this routine to initialize all peripherals void init_devices(void) { //stop errant interrupts until set up CLI(); //disable all interrupts port_init(); timer1_init(); MCUCR = 0x00; GICR = 0x00; TIMSK = 0x00; //timer interrupt sources SEI(); //re-enable interrupts //all peripherals are now initialized } void Delay(unsigned int t) { unsigned int i,j; for(i=0;i9)i=0; Delay(100); //延时 ICR1L=ICR1L_+i; //改变频率 } }  

  

0个回复

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

本版积分规则


关闭

站长推荐上一条 /9 下一条

小黑屋|手机版|Archiver|电子发烧友 ( 粤ICP备14022951号-2 )

GMT+8, 2018-7-17 10:11 , Processed in 0.554302 second(s), 24 queries , Memcache On.

Powered by 电子发烧友网

© 2015 bbs.elecfans.com

微信扫描
快速回复 返回顶部 返回列表