Author Topic: interrupt RTC atmel  (Read 5926 times)

0 Members and 1 Guest are viewing this topic.

Offline losstTopic starter

  • Contributor
  • Posts: 21
  • Country: dz
interrupt RTC atmel
« on: September 14, 2016, 06:04:44 pm »
Hi !
I am beginner and I am having a lot of difficulty to implement interrupts in Atmel.
Basically, I used the RTC module to implement a time base of the ?C.
I would like to afterwards generate interrupts at regular intervals to executing a of my functions in parallel operation of the main program.
But the problem is I can not find a concrete example that allows me to put in place an interruption.

So I use the function initalisation above but afterwards how to implement an interruption

On the Internet, I understand the need establish a routine ISR service.

Code: [Select]
ISR (RTC_Handle)
{
// Here with calling my function
}

But I also find things this way:

Code: [Select]
NVIC_EnableIRQ (RTC_IRQn);
NVIC_SetPrioroty(RTC_IRQn,2);

but after with this, where do I place my code?

I'm lost   |O

Can someone explain to me how this works with an example without using the functions of atmel?
Thanks
« Last Edit: September 14, 2016, 06:46:52 pm by losst »
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11251
  • Country: us
    • Personal site
Re: interrupt RTC atmel
« Reply #1 on: September 14, 2016, 06:44:40 pm »
Do you actually have GCLK[2] configured? What frequency it is running at?

Also, "Atmel" is a manufacturer, you may want to mention a specific device that you are using.

And edit your posts so that code is properly wrapped in  [ code ]  tags.
Alex
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11251
  • Country: us
    • Personal site
Re: interrupt RTC atmel
« Reply #2 on: September 14, 2016, 08:32:34 pm »
I use SAMD10. I set this way the RTC module for the moment without worrying about clocks.
You can't not worry about clocks. You indicated that you want RTC to be clocked from GCLK[2]. You need to have an actual clock source attached to that GCLK, otherwise noting will happen.
Alex
 

Offline losstTopic starter

  • Contributor
  • Posts: 21
  • Country: dz
Re: interrupt RTC atmel
« Reply #3 on: September 14, 2016, 08:43:08 pm »
I want to use an internal clock source to the microcontroller. Then I want to generate interrupts at regular time intervals from the time base, to run in the background another function together my program runs
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11251
  • Country: us
    • Personal site
Re: interrupt RTC atmel
« Reply #4 on: September 14, 2016, 08:46:42 pm »
You still need to connect that internal clock to the GCLK[2].

I have sample projects for a number of Atmel MCUs. Here is one for D10 https://github.com/ataradov/mcu-starter-projects/tree/master/samd10 It blinks an LED in the timer (not RTC, just a regular timer,) interrupt.
Alex
 

Offline losstTopic starter

  • Contributor
  • Posts: 21
  • Country: dz
Re: interrupt RTC atmel
« Reply #5 on: September 14, 2016, 09:01:22 pm »
When I look at your project I do not understand the functions that are used for interrupts

I see :
Code: [Select]
void irq_handler_tc1(void)
{
  if (TC1->COUNT16.INTFLAG.reg & TC_INTFLAG_MC(1))
  {
    HAL_GPIO_LED_toggle();
    TC1->COUNT16.INTFLAG.reg = TC_INTFLAG_MC(1);
  }
}
So in my case it's:
Code: [Select]
void irq_handler_rtc(void)
{
   if(RTC->MODE0.INTFLAG.bit.CMP0)
{
my_function();
}

}
you flash your LED in the background due to an interruption to TC. But what is that:

TC_INTFLAG_MC (1)
In my case the function will be:

this feature only runs? there is no need to call it, it runs only?
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11251
  • Country: us
    • Personal site
Re: interrupt RTC atmel
« Reply #6 on: September 14, 2016, 09:07:25 pm »
you flash your LED in the background due to an interruption to TC.
Well, replace HAL_GPIO_LED_toggle() with my_function().  Although running big chunks of code in the interrupt is generally a bad idea.

But what is that:TC_INTFLAG_MC (1)
It is a bit corresponding to the interrupt flag.

this feature only runs? there is no need to call it, it runs only?
I don't understand the question.

Alex
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11251
  • Country: us
    • Personal site
Re: interrupt RTC atmel
« Reply #7 on: September 14, 2016, 09:12:29 pm »
Because it is an interrupt handler, it is called by the MCU when interrupt happens. That's how interrupts work.
Alex
 

Offline losstTopic starter

  • Contributor
  • Posts: 21
  • Country: dz
Re: interrupt RTC atmel
« Reply #8 on: September 14, 2016, 09:17:55 pm »
In your function your counter starts at 0 and counts up to 15 625 (= 8000000/1000/256) * 500
Then when the counter reaches this value an interrupt is generated through online NVIC_EnableIRQ (TC1_IRQn); . It is from this that the function runs: void irq_handler_tc1 (void) and flashes the led? but the LED will operate when the counter reaches the value of the TC
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11251
  • Country: us
    • Personal site
Re: interrupt RTC atmel
« Reply #9 on: September 14, 2016, 09:22:06 pm »
NVIC_EnableIRQ (TC1_IRQn);
This allows MCU to call your interrupt handler when interrupt is triggered. Basically this tells the MCU that you have defined a valid handler.

. It is from this that the function runs: void irq_handler_tc1 (void) and flashes the led? but the LED will operate when the counter reaches the value of the TC
irq_handler_tc1() will be called every time there is a flag that this interrupt is pending.

And
Code: [Select]
TC1->COUNT16.INTFLAG.reg = TC_INTFLAG_MC(1); clears that flag, so that interrupt handler is not called again right after it exits.
Alex
 

Offline losstTopic starter

  • Contributor
  • Posts: 21
  • Country: dz
Re: interrupt RTC atmel
« Reply #10 on: September 14, 2016, 09:22:40 pm »
What is then the difference between the IRQ interrupts and ISR?
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11251
  • Country: us
    • Personal site
Re: interrupt RTC atmel
« Reply #11 on: September 14, 2016, 09:24:15 pm »
ISR() is not a thing, at least not for ARM processors. It all depends on your environment and startup code. I don't know what ISR() does in your case, it it up to whoever wrote that code.
Alex
 

Offline losstTopic starter

  • Contributor
  • Posts: 21
  • Country: dz
Re: interrupt RTC atmel
« Reply #12 on: September 14, 2016, 09:27:44 pm »

How do I download your entire project and test it with all these files?
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11251
  • Country: us
    • Personal site
Re: interrupt RTC atmel
« Reply #13 on: September 14, 2016, 09:29:06 pm »
Go here https://github.com/ataradov/mcu-starter-projects and press big green button "Clone or download".
Alex
 

Offline losstTopic starter

  • Contributor
  • Posts: 21
  • Country: dz
Re: interrupt RTC atmel
« Reply #14 on: September 14, 2016, 09:52:57 pm »
But the fact of using this interruption that does not disturb the operation of the main program? It is executed well in the background, in parallel?
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11251
  • Country: us
    • Personal site
Re: interrupt RTC atmel
« Reply #15 on: September 14, 2016, 09:53:24 pm »
I don't know. That depends on the frequency of the clock source connected to the GCLK[0].

It is better to verify if you are not sure anyway. Just toggle the pin on the ISR and check how fast it toggles in real life.
Alex
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11251
  • Country: us
    • Personal site
Re: interrupt RTC atmel
« Reply #16 on: September 14, 2016, 09:58:31 pm »
But the fact of using this interruption that does not disturb the operation of the main program? It is executed well in the background, in parallel?
No, it is an interrupt. It interrupts execution of the main program, does its thing, and then continues with the main program. You can't execute two things in parallel on a single core CPU.
Alex
 

Offline losstTopic starter

  • Contributor
  • Posts: 21
  • Country: dz
Re: interrupt RTC atmel
« Reply #17 on: September 14, 2016, 10:00:30 pm »
I do not understand well, you advise me to perform the same test you by integrating my function in your program and check that the LED flashes. I'll try that.
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11251
  • Country: us
    • Personal site
Re: interrupt RTC atmel
« Reply #18 on: September 14, 2016, 10:09:10 pm »
Interrupt handler names are not predefined, they must match the ones in the startup code. If you integrated your function into my code, then "RTC_IRQHandler" should be called "irq_handler_rtc" (see startup_samd10.c).
Alex
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: interrupt RTC atmel
« Reply #19 on: September 14, 2016, 10:13:36 pm »
"But the problem is I can not find a concrete example that allows me to put in place an interruption."

Having example code helps but is not necessary. Read the device datasheet and the compiler manual about the following:
1. How to set up the rtc.
2. How to set up the interrupt.
3. How to service the interrupt.

Regardless of platforms or even the interrupts I involved, those are always the steps that you have to go through.

================================
https://dannyelectronics.wordpress.com/
 

Offline losstTopic starter

  • Contributor
  • Posts: 21
  • Country: dz
Re: interrupt RTC atmel
« Reply #20 on: September 14, 2016, 10:18:25 pm »
Now those famous clock to control my RTC and the time of interruption so I can still see my LED light off and I have to edit the registry 'RTC-> MODE0.COMP
  • reg' but for my clock how do I do? GCLK-> = CLKCTRL.reg GCLK_CLKCTRL_GEN (0)


At the moment it flashes extremely quickly we did not even perceive the LED off
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11251
  • Country: us
    • Personal site
Re: interrupt RTC atmel
« Reply #21 on: September 14, 2016, 10:23:38 pm »
At the moment it flashes extremely quickly we did not even perceive the LED off
Somewhere else in your code you configure GCLK[0] to run from some frequency. Again, if you use my code, then default RC oscillator is used, but sys_init() function disables prescaler, so resulting clock is 8 MHz. Now you need to select appropriate divider in your peripheral setting (16 at the moment). And then select compare value to get your desired interval.

My timer code selects 256 as a divider, you may want to use similar value.
Alex
 

Offline losstTopic starter

  • Contributor
  • Posts: 21
  • Country: dz
Re: interrupt RTC atmel
« Reply #22 on: September 14, 2016, 10:34:50 pm »
Now when I try to incorporate into my project it tells me that my function is redundant "multiple definition of RTC_Handler". Do not declare as protoype in the header?


The only place where it is if it is in startup_samd ...
RTC_Handler void (void) __attribute__ ((weak, alias ("Dummy_Handler")));
« Last Edit: September 14, 2016, 10:38:03 pm by losst »
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11251
  • Country: us
    • Personal site
Re: interrupt RTC atmel
« Reply #23 on: September 14, 2016, 10:37:23 pm »
What function is redundant?
Alex
 

Offline losstTopic starter

  • Contributor
  • Posts: 21
  • Country: dz
Re: interrupt RTC atmel
« Reply #24 on: September 14, 2016, 10:38:30 pm »
multiple definition of RTC_Handler
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11251
  • Country: us
    • Personal site
Re: interrupt RTC atmel
« Reply #25 on: September 14, 2016, 10:39:42 pm »
Well, find those definitions and figure out which one you really need. I have no idea what you use as your base program.
Alex
 

Offline losstTopic starter

  • Contributor
  • Posts: 21
  • Country: dz
Re: interrupt RTC atmel
« Reply #26 on: September 14, 2016, 10:42:58 pm »

This means that I use this function elsewhere in my program? But this is the first time I use an interrupt.
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11251
  • Country: us
    • Personal site
Re: interrupt RTC atmel
« Reply #27 on: September 14, 2016, 10:43:47 pm »
Well, you use some library (ASF?). This library may have defined this function already.
Alex
 
The following users thanked this post: losst

Offline losstTopic starter

  • Contributor
  • Posts: 21
  • Country: dz
Re: interrupt RTC atmel
« Reply #28 on: September 14, 2016, 10:56:13 pm »

ok it's good it works ASF was a library that was included in the project.
Thank you. Thank you for the time you gave me thank you now I know how to walk interrupts!
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf