Pausing PWM, Pin goes High.

Discussion in 'Embedded Systems and Microcontrollers' started by AgentSmithers, Sep 16, 2016.

  1. AgentSmithers

    Thread Starter Active Member

    Jan 14, 2011
    52
    0
    Hi everyone!
    When I use this code the PWM seems to hover around 2.25 volts. I wanted to use this code to Pulse an IR LED but there is an issue. During the Time the PWM is turned off with the CS00 Prescaler, It seems to work sometimes then other times spike the voltage to the full load of around 5V.
    Anyone experience this before?

    Code (Text):
    1.  
    2.  
    3. int main(void)
    4. {
    5.     DDRB |= (1<<PB0); //Set pin PB0 as output
    6.     TCNT0 = 0;
    7.     TCCR0A=0;
    8.     TCCR0B=0;
    9.     TCCR0A |=(1<<COM0A0); //Timer0 in toggle mode Table 11-2
    10.     TCCR0A |=(1<<WGM01); //Start timer 1 in CTC mode Table 11.5
    11.     TCCR0B |= (1 << CS00);// Prescaler table 11.6
    12.     OCR0A=104; //CTC Compare value  
    13.  
    14.     while(1)
    15.     {      
    16.         TCCR0B |= (1 << CS00);// Prescaler table 11.6
    17.         _delay_ms(5000);
    18.         TCCR0B &= ~(1 << CS00);// Prescaler table 11.6
    19.         _delay_ms(5000);
    20.     }
    21. }
    22.  
    23.  
    24.  
    This below works, Why is adjusting the prescaler keeping the Pin on High, Is it a timing isssue as PWM is being generated?
    UPDATE:
    Code (Text):
    1.  
    2. while(1)
    3.     {      
    4.         DDRB |= (1<<PB0); //Set pin PB0 as output
    5.         //TCCR0B |= (1 << CS00);// Prescaler table 11.6
    6.         _delay_ms(2000);
    7.         //TCCR0B &= ~(1 << CS00);// Prescaler table 11.6
    8.         DDRB &= ~(1<<PB0); //Set pin PB0 as output
    9.         _delay_ms(3000);
    10.     }
    11.  
     
    Last edited: Sep 16, 2016
  2. shteii01

    AAC Fanatic!

    Feb 19, 2010
    3,393
    497
    Is the pin designed for pwm or are you using generic i/o pin for pwm signal?
     
  3. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,392
    1,605
    What does the data sheet for this mysterious device say about that?
     
Loading...