Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- manualni PWM
- */
- #include <avr\io.h>
- #include <avr/iom128.h>
- int main(void) {
- // PORTD pins as input
- DDRD = 0x00;
- // enable internal pull ups
- PORTD = 0xFF;
- // set PORTB1 pin as output
- DDRB = 0xFF; // output pro PWM port PB5, PB6, PB7
- // vyuzivaji se PB5(OC1A), PB6(OC1B)
- // TOP = ICR1;
- // output compare OC1A 8 bit non inverted PWM
- // clear OC1A on Compare Match, set OC1A at TOP
- // fast PWM
- // ICR1 = 20000 definuje 50Hz PWM DDRB 6 23 DDRB 5 23
- ICR1 = 20000;
- TCCR1A|=(1<<COM1A1)|(1<<COM1B1)|(1<<WGM11);
- TCCR1B|=(1<<WGM13)|(1<<WGM12)|(1<<CS10);//(1<<WGM13)|(1<<WGM12)|(1<<CS10)
- // start timeru s divisor de freq 8
- while (1) {
- if(bit_is_clear(PIND, 0)){
- // increase duty cycle
- OCR1A += 10;
- loop_until_bit_is_set(PIND, 0);
- }
- if (bit_is_clear(PIND, 1)) {
- // decease duty cycle
- OCR1A -= 10;
- loop_until_bit_is_set(PIND, 1);
- }
- if (bit_is_clear(PIND, 2)) {
- // increase duty cycle
- OCR1B += 10;
- loop_until_bit_is_set(PIND, 2);
- }
- if (bit_is_clear(PIND, 3)) {
- // decease duty cycle
- OCR1B -= 10;
- loop_until_bit_is_set(PIND, 3);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement