標題: 快速PWM模式 [打印本頁]

作者: liuqq    時間: 2015-5-21 23:50
標題: 快速PWM模式




  1. #include <iom128v.h>

  2. void main(void)

  3. {

  4. // Port B initialization, PB.5-PB.7輸出PWM

  5. // Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out

  6. PORTB=0xFF;

  7. DDRB=0xFF;

  8. // Timer/Counter 1 initialization

  9. // Clock source: System Clock

  10. // Clock value: Timer 1 Stopped

  11. // Mode: 相位修正PWM, top=ICR1, PWM頻率50Hz,外部晶振16M

  12. // OC1A output: Non-Inv.

  13. // OC1B output: Non-Inv.

  14. // OC1C output: Non-Inv.

  15. // Noise Canceler: Off

  16. // Input Capture on Falling Edge

  17. // Timer 1 Overflow Interrupt: OFF

  18. // Input Capture Interrupt: Off

  19. // Compare A Match Interrupt: OFF

  20. // Compare B Match Interrupt: OFF

  21. // Compare C Match Interrupt: OFF

  22. TCCR1A=0xAA;    //普通PWM

  23. TCCR1B=0x10;

  24. //TOP1=FOSC/FPWM/2/64;       //64分頻

  25. //ICR1H=TOP1>>8; ICR1L=TOP1&0xFF;

  26. ICR1H=0x09; ICR1L=0xf6;     //TOP,64分頻 49Hz PWM, TOP=2550

  27. OCR1AH=0x09;OCR1AL=0xC4;    //100%

  28. OCR1BH=0x04;OCR1BL=0xE2;    //50%

  29. OCR1CH=0x00;OCR1CL=0xFA;   //10%

  30. TCCR1B|=0x03;   //啟動T1,64分頻

  31. while(1);

  32. }
復制代碼











歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1