Difference between revisions of "Custom Interrupts - PICmicro"

From Flowcode Help
Jump to navigationJump to search
Tags: Flowcode v8 Version
(fixed the screenshots and added old version links)
Line 1: Line 1:
 +
The Custom option of the [[Interrupt_Icon_Properties|Interrupt icon]] allows the creation of custom interrupt code.
 +
 +
Many of the chips available in Flowcode support hardware driven interrupts that are not provided in the standard set of Flowcode interrupts. To allow users to add their own interrupts to suit their application Flowcode has the option to add your own custom interrupt.
 +
 +
==Old Versions==
 +
This page is current for Flowcode v11 and later. Earlier versions can be found below:
 +
{| class="wikitable"
 +
|+
 +
|-
 +
| [[Special:PermanentLink/23682|Flowcode v10]]
 +
|-
 +
| [[Special:PermanentLink/23682|Flowcode v9]]
 +
|-
 +
| [[Special:PermanentLink/23682|Flowcode v8]]
 +
|}
 +
 +
<br>
 
Here are a few examples for such interrupts using PICmicro chips. To create interrupts that are not shown below you will have to refer to the device datasheet. Once the code has been placed into the custom interrupt properties dialog, the interrupt can be enabled and disabled like any of the standard Flowcode [[Interrupt Icon Properties|Interrupts]].  
 
Here are a few examples for such interrupts using PICmicro chips. To create interrupts that are not shown below you will have to refer to the device datasheet. Once the code has been placed into the custom interrupt properties dialog, the interrupt can be enabled and disabled like any of the standard Flowcode [[Interrupt Icon Properties|Interrupts]].  
  
Line 15: Line 32:
 
==USART Receive==
 
==USART Receive==
  
[[File:Gen_Custom_Interrupts_PICmicro_USART.png|right]]
+
[[File:CustomInterrupt 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).
Line 50: Line 67:
 
==Analogue Comparator==
 
==Analogue Comparator==
  
[[File:Gen_Custom_Interrupts_PICmicro_COMPARE.png|right]]
+
[[File:CustomInterrupt COMPARE.png|right]]
 
'''Enable code:'''
 
'''Enable code:'''
  
Line 90: Line 107:
  
  
[[File:Gen_Custom_Interrupts_PICmicro_TMR1.png|right]]
+
[[File:CustomInterrupt TIMER.png|right]]
 
'''Enable code:'''
 
'''Enable code:'''
  

Revision as of 14:21, 3 February 2026

The Custom option of the Interrupt icon allows the creation of custom interrupt code.

Many of the chips available in Flowcode support hardware driven interrupts that are not provided in the standard set of Flowcode interrupts. To allow users to add their own interrupts to suit their application Flowcode has the option to add your own custom interrupt.

Old Versions

This page is current for Flowcode v11 and later. Earlier versions can be found below:

Flowcode v10
Flowcode v9
Flowcode v8


Here are a few examples for such interrupts using PICmicro chips. To create interrupts that are not shown below you will have to refer to the device datasheet. Once the code has been placed into the custom interrupt properties dialog, the interrupt can be enabled and disabled like any of the standard Flowcode Interrupts.


USART receive - This can be nicely integrated with the Flowcode RS232 component.

Comparator - Example of the use of a function not supported by Flowcode.

Timer1 rollover - An example of the use of another unsupported, but potentially useful, function.

Target PIC Processor ( PIC16F877A )

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


USART Receive

CustomInterrupt 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:

INTCONbits.PEIE = 1; // Enable peripheral interrupts

INTCONbits.GIE = 1; // Enable global interrupts

PIE1bits.RCIE = 1; // Enable USART receive interrupts


Disable code:

PIE1bits.RCIE = 0; // Disable USART receive interrupts


Handler code:

if (PIR1 & (1 << RCIF)) // Check to see if the interrupt flag is set

{

FCM_%n(); // Call Flowcode Macro

PIR1bits.RCIF = 0; // Clear interrupt flag

}


Analogue Comparator

CustomInterrupt COMPARE.png

Enable code:

INTCONbits.PEIE = 1; // Enable peripheral interrupts

INTCONbits.GIE = 1; // Enable global interrupts

PIE1bits.CCP1IE = 1; // Enable Capture Compare interrupts


Disable code:

PIE1bits.CCP1IE = 0; // Disable Capture Compare Interrupts


Handler code:

if (PIR1 & (1 << CCP1IF)) // Check to see if the interrupt flag is set

{

FCM_%n(); // Call Flowcode Macro

PIR1bits.CCP1IF = 0; // Clear interrupt flag

}


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


FCV_COMPSTATE = ccpr1l | ( ccpr1h << 8 );

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

Timer1 Rollover

CustomInterrupt TIMER.png

Enable code:

T1CON = 0x79; // Start timer with Internal clock source, prescaler = 1:8

INTCONbits.PEIE = 1; // Enable peripheral interrupts

INTCONbits.GIE = 1; // Enable global interrupts

PIE1bits.TMR1IE = 1; // Enable Timer 1 interrupts


Disable code:

PIE1bits.TMR1IE = 0; // Disable Timer 1 interrupts


Handler code:

if (PIR1 & (1 << TMR1IF)) // Check to see if the interrupt flag is set

{

FCM_%n(); // Call Flowcode Macro

PIR1bits.TMR1IF= 0; // Clear interrupt flag

}


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


FCV_CAPTVAL = TMR1L | ( TMR1H << 8 );

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