Advertisement
sombruxo

FastPWM

May 16th, 2023
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. ;
  2. ; fastPWM.asm
  3. ;
  4. ; Created: 03/05/2023 16:37:42
  5. ; Author : bemposta
  6. ;
  7.  
  8. .ORG 0x0000
  9.  
  10. sbi DDRB, PINB5
  11. rcall initFastPWMTmr0
  12. clr r17
  13. ser r18
  14.  
  15. mainLoop:
  16. sbi PORTB, PINB5
  17. rcall delay100ms
  18. inc r17
  19. dec r18
  20. out OCR0A, r17
  21. out OCR0B, r18
  22. cbi PORTB, PINB5
  23. rcall delay100ms
  24. inc r17
  25. dec r18
  26. out OCR0A, r17
  27. out OCR0B, r18
  28. rjmp mainLoop
  29.  
  30. /***************************************************************************************
  31. Funciones
  32. ***************************************************************************************/
  33. initFastPWMTmr0:
  34. push r16
  35. sbi DDRD, PIND6 ; Out 0A (pin D6)
  36. sbi DDRD, PIND5 ; Out 0B (pin D5)
  37. clr r16
  38. ori r16, (3 << WGM00) ; Modo 3 -> FastPWM [falta:(0 << WGM02) en TCCR0B]
  39. ori r16, (2 << COM0A0) ; Out 0A (pin D6), non inverting Compare Output = Clear OC0A on Compare Match.
  40. ori r16, (2 << COM0B0) ; Out 0B (pin D5), non inverting Compare Output = Clear OC0B on Compare Match.
  41. out TCCR0A, r16
  42. clr r16
  43. ori r16, (0 << WGM02) ; completar Modo 3 -> FastPWM y Modo 7.
  44. ori r16, (5 << CS00) ; Preescaler 1024. 0=No Clk, 1=No prescaling, 2=clk/8, 3=clk/64, 4=clk/256, 5=clk/1024
  45. out TCCR0B, r16
  46. ldi r16, 0
  47. out OCR0A, r16 ; Init PWM 0%
  48. out OCR0B, r16 ; Init PWM 0%
  49. pop r16
  50. ret
  51.  
  52. /***************************************************************************************/
  53. delay100ms:
  54. ; 100ms at 16 MHz
  55. push r18
  56. push r19
  57. push r20
  58. ldi r18, 2
  59. ldi r19, 30
  60. ldi r20, 229
  61. delay100msL1:
  62. dec r20
  63. brne delay100msL1
  64. dec r19
  65. brne delay100msL1
  66. dec r18
  67. brne delay100msL1
  68. pop r20
  69. pop r19
  70. pop r18
  71. ret
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement