Difference between revisions of "Custom Interrupts - AVR"

From Flowcode Help
Jump to navigationJump to search
(Created page with " <font style="color:#FF0000"> '''Target AVR Processor''' ( ATMEGA8, 16, 32 ) '''(Note: For other AVR devices you may have to refer to the device datasheet to obtain the cor...")
 
 
(13 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
+
<sidebar>Sidebar: What Is an Interrupt?</sidebar>
 
 
 
 
 
<font style="color:#FF0000"> '''Target AVR Processor''' ( ATMEGA8, 16, 32 )
 
<font style="color:#FF0000"> '''Target AVR Processor''' ( ATMEGA8, 16, 32 )
  
Line 7: Line 5:
  
  
'''USART receive'''
+
==USART Receive==
  
 +
[[File:Gen_Customer_Interrupts_AVR_USART.png|right]]
  
 
The Flowcode RS232 component can be used to set the Baud rate and configure the mode of operation, and the ReceiveRS232Char function can be used in the handler macro to read the data (clearing the interrupt).
 
The Flowcode RS232 component can be used to set the Baud rate and configure the mode of operation, and the ReceiveRS232Char function can be used in the handler macro to read the data (clearing the interrupt).
  
  
Enable code:
+
'''Enable code:'''
  
 
<span style="color:#000080"> UCSRB |= ((1 << RXCIE) | (1 << RXEN)); // enable USART receiver and receive interrupts </span>
 
<span style="color:#000080"> UCSRB |= ((1 << RXCIE) | (1 << RXEN)); // enable USART receiver and receive interrupts </span>
  
  
Disable code:
+
'''Disable code:'''
  
 
<span style="color:#000080"> UCSRB &= ~(1 << RXCIE); // disable USART receive interrupts </span>
 
<span style="color:#000080"> UCSRB &= ~(1 << RXCIE); // disable USART receive interrupts </span>
  
  
Handler code:
+
'''Handler code:'''
  
 
<font style="color:#000080"> ISR(USART_RXC_vect) // USART receive vector
 
<font style="color:#000080"> ISR(USART_RXC_vect) // USART receive vector
Line 29: Line 28:
 
{
 
{
  
FCM_%n(); // call selected macro
+
FCM_%n(); // Call Flowcode Macro
  
} </font>
+
}</font>
  
  
'''<img>'''
 
  
  
'''Analogue comparator'''
 
  
 +
==Analogue Comparator==
  
Enable code:
+
[[File:Gen_Custom_Interrupts_AVR_COMPARITOR.png|right]]
 +
 
 +
 
 +
'''Enable code:'''
  
 
<font style="color:#000080"> SFIOR &= ~(1 << ACME); // disable multiplexer input
 
<font style="color:#000080"> SFIOR &= ~(1 << ACME); // disable multiplexer input
Line 47: Line 48:
  
  
Disable code:
+
'''Disable code:'''
  
 
<span style="color:#000080"> ACSR &= ~(1 << ACIE); // disable comparator interrupts </span>
 
<span style="color:#000080"> ACSR &= ~(1 << ACIE); // disable comparator interrupts </span>
  
  
Handler code:
+
'''Handler code:'''
  
 
<font style="color:#000080"> ISR(ANA_COMP_vect) // analogue comparator interrupt vector
 
<font style="color:#000080"> ISR(ANA_COMP_vect) // analogue comparator interrupt vector
Line 58: Line 59:
 
{
 
{
  
FCM_%n(); // call selected macro
+
FCM_%n(); // Call Flowcode Macro
  
} </font>
+
}</font>
  
  
Line 69: Line 70:
  
  
'''<img>'''
 
  
  
'''Timer1 rollover'''
+
==Timer1 Rollover==
 +
 
 +
[[File:Gen_Custom_Interrupts_AVR_TIMER1.png|right]]
  
  
Enable code:
+
'''Enable code:'''
  
 
<font style="color:#000080"> TCCR1B = 0x45; // positive edge trigger with no noise canceler, prescaler = /1024
 
<font style="color:#000080"> TCCR1B = 0x45; // positive edge trigger with no noise canceler, prescaler = /1024
Line 82: Line 84:
  
  
Disable code:
+
'''Disable code:'''
  
 
<span style="color:#000080"> TIMSK &= ~(1 << TICIE1); // disable input capture interrupts </span>
 
<span style="color:#000080"> TIMSK &= ~(1 << TICIE1); // disable input capture interrupts </span>
  
  
Handler code:
+
'''Handler code:'''
  
 
<font style="color:#000080"> ISR(TIMER1_CAPT_vect) // input capture vector
 
<font style="color:#000080"> ISR(TIMER1_CAPT_vect) // input capture vector
Line 93: Line 95:
 
{
 
{
  
FCM_%n(); // call selected macro
+
FCM_%n(); // Call Flowcode Macro
  
 
}</font>
 
}</font>
Line 103: Line 105:
 
<span style="color:#000080"> FCV_CAPTVAL = ICR1; </span>
 
<span style="color:#000080"> FCV_CAPTVAL = ICR1; </span>
  
** captval must be declared as an integer variable **
+
{| width="auto"
 
+
|<pre>** captval must be declared as an integer variable **</pre>
'''<img>'''
+
|}

Latest revision as of 15:25, 21 January 2015

<sidebar>Sidebar: What Is an Interrupt?</sidebar> Target AVR Processor ( ATMEGA8, 16, 32 )

(Note: For other AVR devices you may have to refer to the device datasheet to obtain the correct code)


USART Receive

Gen Customer Interrupts AVR USART.png

The Flowcode RS232 component can be used to set the Baud rate and configure the mode of operation, and the ReceiveRS232Char function can be used in the handler macro to read the data (clearing the interrupt).


Enable code:

UCSRB |= ((1 << RXCIE) | (1 << RXEN)); // enable USART receiver and receive interrupts


Disable code:

UCSRB &= ~(1 << RXCIE); // disable USART receive interrupts


Handler code:

ISR(USART_RXC_vect) // USART receive vector

{

FCM_%n(); // Call Flowcode Macro

}



Analogue Comparator

Gen Custom Interrupts AVR COMPARITOR.png


Enable code:

SFIOR &= ~(1 << ACME); // disable multiplexer input

ACSR |= (1 << ACIE); // enable comparator interrupts - interrupt when comparator output toggles


Disable code:

ACSR &= ~(1 << ACIE); // disable comparator interrupts


Handler code:

ISR(ANA_COMP_vect) // analogue comparator interrupt vector

{

FCM_%n(); // Call Flowcode Macro

}


The state of the comparator input can be read into a Flowcode variable 'compstate' with the following C code line:


FCV_COMPSTATE = ACSR & (1 << ACO);



Timer1 Rollover

Gen Custom Interrupts AVR TIMER1.png


Enable code:

TCCR1B = 0x45; // positive edge trigger with no noise canceler, prescaler = /1024

TIMSK |= (1 << TICIE1); // enable input capture interrupts


Disable code:

TIMSK &= ~(1 << TICIE1); // disable input capture interrupts


Handler code:

ISR(TIMER1_CAPT_vect) // input capture vector

{

FCM_%n(); // Call Flowcode Macro

}


The captured 16-bit count value can be read into a Flowcode variable 'captval' with the following C code line:


FCV_CAPTVAL = ICR1;

** captval must be declared as an integer variable **