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.
/** \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
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:
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.
k7michal:
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...