Interrupt evry 1/100s

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 6.

Moderator: Benj

Post Reply
rradojko
Posts: 40
Joined: Thu Jun 21, 2012 8:53 am
Has thanked: 10 times
Been thanked: 2 times
Contact:

Interrupt evry 1/100s

Post 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.
Attachments
konfiguracija_interrupt.jpg
(199.16 KiB) Downloaded 1235 times

User avatar
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

Post by Benj »

Hello,

This should get you pretty close to 100Hz interrupt.
ArdTimerDemo.fcfx
(4.6 KiB) Downloaded 337 times

rradojko
Posts: 40
Joined: Thu Jun 21, 2012 8:53 am
Has thanked: 10 times
Been thanked: 2 times
Contact:

Re: Interrupt evry 1/100s

Post 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?
Attachments
Logic.jpg
(138.5 KiB) Downloaded 1182 times
Interrupt_1_100s.fcfx
(5.5 KiB) Downloaded 296 times

User avatar
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

Post 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.

rradojko
Posts: 40
Joined: Thu Jun 21, 2012 8:53 am
Has thanked: 10 times
Been thanked: 2 times
Contact:

Re: Interrupt evry 1/100s

Post 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
}

rradojko
Posts: 40
Joined: Thu Jun 21, 2012 8:53 am
Has thanked: 10 times
Been thanked: 2 times
Contact:

Re: Interrupt evry 1/100s

Post by rradojko »

Here are the settings for the custom interrupt the Flowcode 6. Interrupt evry 1/100s.
Attachments
Custom_nterrupt_1_100s_Flowcode_6.jpg
Custom_nterrupt_1_100s_Flowcode_6.jpg (153.97 KiB) Viewed 6230 times

rradojko
Posts: 40
Joined: Thu Jun 21, 2012 8:53 am
Has thanked: 10 times
Been thanked: 2 times
Contact:

Re: Interrupt evry 1/100s

Post by rradojko »

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

Post Reply