Go Down

### Topic: how to create original interrupts [ ISR() ] (Read 1 time)previous topic - next topic

#### k7michal

##### Nov 28, 2012, 05:25 am
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: [Select]
/** \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

#### WizenedEE

#1
##### Nov 28, 2012, 05:32 am
Here's some more documentation:
http://www.nongnu.org/avr-libc/user-manual/modules.html

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

#### Cybernetician

#2
##### Nov 28, 2012, 05:34 am
what i understand first you need to understand about interrupts may it will solve your problem without changes in interrupt.h

From Idea To Invention

#### k7michal

#3
##### Nov 28, 2012, 06:59 am
Thank you! that helps!!

#### Nick Gammon

#4
##### Nov 28, 2012, 07:08 am

http://www.gammon.com.au/interrupts
Please post technical questions on the forum, not by personal message. Thanks!

http://www.gammon.com.au/electronics

#### k7michal

#5
##### Nov 28, 2012, 08:19 am
The more the merrier

#### DigitalJohnson

#6
##### Nov 28, 2012, 11:18 am
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
DigitalJohnson

#### MarkT

#7
##### Nov 28, 2012, 11:44 am

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...
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Go Up

Please enter a valid email to subscribe