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.
Interrupt evry 1/100s
Moderator: Benj
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Interrupt evry 1/100s
Hello,
This should get you pretty close to 100Hz interrupt.
This should get you pretty close to 100Hz interrupt.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: Interrupt evry 1/100s
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?
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?
- Attachments
-
- Logic.jpg
- (138.5 KiB) Downloaded 1182 times
-
- Interrupt_1_100s.fcfx
- (5.5 KiB) Downloaded 326 times
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Interrupt evry 1/100s
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.
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: Interrupt evry 1/100s
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!
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
I think it is a mistake to help in Flowcode custom interrupt. Code of help did not work
- Attachments
-
- Custom_nterrupt_Flovcode_6_mistake.jpg
- (198.35 KiB) Downloaded 1127 times