Advertisement
Guest User

Untitled

a guest
Apr 27th, 2015
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. * PWM.c
  2. *
  3. * Created: 3/20/2013 9:29:11 PM
  4. * Author: SAM
  5. */
  6.  
  7. #define F_CPU 20000000
  8. #include <stdint.h>
  9. #include <avr/io.h>
  10. #include <avr/interrupt.h>
  11. #include <util/delay.h>
  12.  
  13. double dutyCycle = 0;
  14.  
  15. int main(void)
  16. {
  17. DDRD = (1 << PORTD6);
  18.  
  19. TCCR0A = (1 << COM0A1) | (1 << WGM00) | (1 << WGM01);
  20. TIMSK0 = (1 << TOIE0);
  21.  
  22. OCR0A = (dutyCycle/100.0)*255.0;
  23.  
  24. sei();
  25.  
  26. TCCR0B = (1 << CS00) | (1 << CS02);
  27.  
  28. while(1)
  29. {
  30. //TODO:: Please write your application code
  31. _delay_ms(100);
  32.  
  33. dutyCycle += 10;
  34.  
  35. if(dutyCycle > 100)
  36. {
  37. dutyCycle = 0;
  38. }
  39. }
  40. }
  41.  
  42. ISR(TIMER0_OVF_vect)
  43. {
  44. OCR0A = (dutyCycle/100.0)*255;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement