S
S
svd712015-10-23 18:55:21
Arduino
svd71, 2015-10-23 18:55:21

How to control a timer in Arduino?

There is an Arduino UNO with an atmega328p on board. I'm trying to set a timer for 250 microseconds.
I am using the following code:

void setup() 
{ 
  DDRC = 0xFF;
  DDRB = 0xFF;

TCNT1 = 0;
  TCCR1B = /*_BV(CS11)|*/_BV(CS10);
TCNT1 = 0;
  //TIMSK1 = _BV(TOIE1);

TIMSK1 |= (1<<TOIE1);

        //-TIMER1_OVF_vect
   
    sei();
  
}//setup()
 
void loop() 
{ 
}
  
volatile uint8_t pp = 0;

ISR(TIMER1_OVF_vect)
{
    pp = ~pp;
    PORTC = pp;
    PORTB = pp;
}

Everything is fine, the timer has started. But only prescaler changes lead to nothing - the frequency is always 2 milliseconds. What's wrong with the timer?
UDP: I look at the changes with an oscilloscope, and not with something else.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2015-10-23
@svd71

The arduino environment uses timers for its tasks - the first millis timer, the second pwm.
You need to comment them out in the arduino code first and then use them.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question