Page 1 of 1
Interrupt evry 1/100s
Posted: Wed Apr 13, 2016 10:31 am
by rradojko
I have a question.
I use an Arduino UNO and 16 MHz quartz.
I want to create a interruption at every hundredth of a second - interrupt 1/100s.
Which timer should i use? 8-bit timer or 16_bit timer?
How do I configure the timer register?
Thanks for the reply.
Re: Interrupt evry 1/100s
Posted: Thu Apr 14, 2016 12:55 pm
by Benj
Hello,
This should get you pretty close to 100Hz interrupt.
Re: Interrupt evry 1/100s
Posted: Sun Apr 17, 2016 8:51 pm
by rradojko
Hello,
Thank you Benj for your answer, but interrupt (ArdTimerDemo.fcfx ) is not not accurate.
I checked interrupt with the logic analyzer. See attachment below.
I need exactly interruption. It uses the 16-bit timer and the "C" code, but I do not know how?
Re: Interrupt evry 1/100s
Posted: Wed Apr 20, 2016 12:38 pm
by Benj
Hello,
Something like this might help to get your values right.
http://eleccelerator.com/avr-timer-calculator/
Have a play and let us know how your getting on.
Re: Interrupt evry 1/100s
Posted: Thu Apr 21, 2016 6:21 am
by rradojko
Hello!
Benj Thanks for the information.
I managed to configure the 16-bit Timer1.
I use the Arduino Uno and processor Atmega328p.
Here are the settings Timer1 to interrupt each 1 / 100s for Arduino. The code works!
Code: Select all
// Arduino timer CTC interrupt example - interrupt evry 1/100s
#include <avr/io.h>
#include <avr/interrupt.h>
#define LEDPIN 13
void setup()
{
pinMode(LEDPIN, OUTPUT);
// inicializacija Timer1
cli(); // disable all interrupts
TCCR1A = 0; // TCCR1A register on 0
TCCR1B = 0; // TCCR1B on 0
// set compare match register to desired timer count
OCR1A = 624;
// turn on CTC mode
TCCR1B |= (1 << WGM12);
// prescaler - 1:256
TCCR1B |= (1 << CS12);
// enable timer compare interrupt
TIMSK1 |= (1 << OCIE1A);
// enable all interrupts
sei();
}
void loop()
{
// do some stuff while my LED keeps blinking
}
ISR(TIMER1_COMPA_vect)
{
digitalWrite(LEDPIN, !digitalRead(LEDPIN)); //Flashing LED and frequency control
}
Re: Interrupt evry 1/100s
Posted: Thu Apr 21, 2016 6:32 am
by rradojko
Here are the settings for the custom interrupt the Flowcode 6. Interrupt evry 1/100s.
Re: Interrupt evry 1/100s
Posted: Thu Apr 21, 2016 6:48 am
by rradojko
I think it is a mistake to help in Flowcode custom interrupt. Code of help did not work