Pages: [1]   Go Down
Author Topic: how to create original interrupts [ ISR() ]  (Read 874 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm studying the "interrupt.h" file and noticed that there's a few commands that allow you to create your own interrupts, however I could use a tip or some guidance here. I have the datasheet for the ATmega328p and I can set specific registers and such but I need some basics on how to establish and use personalized interrupts.

In perticular I'm trying to update the values of OCR1A and ICR1 registers to define the PWM duty cycle and frequency respectively for Timer1.. I want to do this as an interrupt so that the registers do not get messed with while the Timer is counting.

Here's some reference code from Interrupt.h

Many Thanks.

Code:
/** \name Macros for writing interrupt handler functions */


#if defined(__DOXYGEN__)
/** \def ISR(vector [, attributes])
    \ingroup avr_interrupts

    \code #include <avr/interrupt.h> \endcode

    Introduces an interrupt handler function (interrupt service
    routine) that runs with global interrupts initially disabled
    by default with no attributes specified.

    The attributes are optional and alter the behaviour and resultant
    generated code of the interrupt routine. Multiple attributes may
    be used for a single function, with a space seperating each
    attribute.

    Valid attributes are ISR_BLOCK, ISR_NOBLOCK, ISR_NAKED and
    ISR_ALIASOF(vect).

    \c vector must be one of the interrupt vector names that are
    valid for the particular MCU type.
*/
#  define ISR(vector, [attributes])
#else  /* real code */

#if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
#  define __INTR_ATTRS used, externally_visible
#else /* GCC < 4.1 */
#  define __INTR_ATTRS used
#endif

Logged

Offline Offline
Edison Member
*
Karma: 19
Posts: 1041
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here's some more documentation:
http://www.nongnu.org/avr-libc/user-manual/modules.html

Essentially it's:
Code:
ISR(<thinginthedatasheet>_vect) {
  // function
}
Logged

Offline Offline
Full Member
***
Karma: 4
Posts: 187
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

what i understand first you need to understand about interrupts may it will solve your problem without changes in interrupt.h

this will help you http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=89843&start=all&postdays=0&postorder=asc
Logged

From Idea To Invention

Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you! that helps!!
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

My blathering-on about interrupts:

http://www.gammon.com.au/interrupts
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The more the merrier
Logged

San Pedro, CA.
Offline Offline
Full Member
***
Karma: 3
Posts: 155
My head HURTS!!!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The avrFreaks tutorial above states:
Quote
There are two main sources of interrupts:

Hardware Interrupts, which occur in response to a changing external event such as a pin going low, or a timer reaching a preset value
 Software Interrupts, which occur in response to a command issued in software

The 8-bit AVRs lack software interrupts, which are usually used for special operating system tasks like switching between user and kernel space, or for handling exceptions.

From the ATmega1280/2560 datasheet:
Quote
The External Interrupts are triggered by the INT7:0 pin or any of the PCINT23..0 pins.
Observe that, if enabled, the interrupts will trigger even if the INT7:0 or PCINT23..0 pins
are configured as outputs. This feature provides a way of generating a software
interrupt.

On the arduino (mega1280/2560, I'm not sure of others), there are pins on the MCU that aren't brought out to headers. Some of those pins also serve as interrupt sources. So, if you set one of those pins to output, you can use software to set the state of the pin and trigger an interrupt to occur (hardware interrupt triggered by software). This can also be done with (external interrupt) pins that are brought out to headers. If anyone else has anything to add/corrections, please do.

DigitalJohnson
Logged

DigitalJohnson

0
Offline Offline
Shannon Member
****
Karma: 200
Posts: 11672
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset



In perticular I'm trying to update the values of OCR1A and ICR1 registers to define the PWM duty cycle and frequency respectively for Timer1.. I want to do this as an interrupt so that the registers do not get messed with while the Timer is counting.

Many Thanks.

Well the timers are quite carefully designed to allow registers like OCR1A and ICR1 to be updated on the fly - if you look at the descriptions
for the various modes it tells you when various updates happen (often delayed to the end of the current cycle), so you may not need an ISR
just to achieve what you want...
Logged

[ I won't respond to messages, use the forum please ]

Pages: [1]   Go Up
Jump to: