logo elektroda
logo elektroda
X
logo elektroda
REKLAMA
REKLAMA
Adblock/uBlockOrigin/AdGuard mogą powodować znikanie niektórych postów z powodu nowej reguły.

Fast PWM nie działa na ATmega328 - kod nie zapala diody LED

C-z-e-s-i-e-k 13 Sie 2017 12:57 882 3
REKLAMA
  • #1 16639733
    C-z-e-s-i-e-k
    Poziom 9  
    jak w temacie, próbuje coś prostego napisać i nic z tego nie wychodzi, dioda nie swieci.

    #include<avr/io.h>
    #include<util/delay.h>
    #include <avr/interrupt.h>
    #include <stdint.h>
    
    #define LED1 (1<<PB2)
    
    
    int main( void ){
    
    	DDRB = LED1;
    	PORTB = LED1;
    
    	TCCR1A |=(1<<WGM11);
    	TCCR1B |=(1<<WGM12); //Fast Pwm
    
    	TCCR1A |= (1<<COM1B1);
    	TCCR1B |= (1<<CS12)|(1<<CS11)|(1<<CS10);
    
    	 ICR1 = 18; //~50hz
    
    	while(1){
    
    		//PORTB ^=LED1;
    		_delay_ms(2000);
    		OCR1B=10;
    		_delay_ms(2000);
    		OCR1B=50;
    		_delay_ms(2000);
    		OCR1B=100;
    		_delay_ms(2000);
    		OCR1B=150;
    		_delay_ms(2000);
    		OCR1B=200;
    		_delay_ms(2000);
    		OCR1B=225;
    		_delay_ms(4000);
    		OCR1B=255;
    
    
    
    	}
    }
  • REKLAMA
  • REKLAMA
  • #3 16640072
    C-z-e-s-i-e-k
    Poziom 9  
    Dzięki, pomogło...
    chciałem to jeszcze zrealizować na 8 bit. timerze ale to samo zmiana CS nic nie dała.
    Czy jest możliwość osiągnięcia 50 hz na timerze 8 bit. ?? z tego co się orientuje to chyba nie.

    
    #include<avr/io.h>
    #include<util/delay.h>
    #include <avr/interrupt.h>
    #include <inttypes.h>
    
    #define LED1 (1<<PD3)
    
    
    int main( void ){
    
    	DDRD = LED1;
    	PORTD = LED1;
    
    	TCCR2A |=(1<<WGM21)|(1<<WGM20);
    	TCCR2B |= (1<<WGM22); //Fast Pwm
    	TCCR2A |= (1<<COM2B1);//|(1<<COM2B0);
    	TCCR2B |= (1<<CS22)|(1<<CS21)|(1<<CS22);
    
    
    	while(1){
    
    	//	PORTD ^=LED1;
    		_delay_ms(2000);
    		OCR2B=10;
    		_delay_ms(2000);
    		OCR2B=50;
    		_delay_ms(2000);
    		OCR2B=100;
    		_delay_ms(2000);
    		OCR2B=150;
    		_delay_ms(2000);
    		OCR2B=200;
    		_delay_ms(2000);
    		OCR2B=225;
    		_delay_ms(4000);
    		OCR2B=255;
    
    
    
    	}
    }
REKLAMA