14.5.1 Application Use of IOIM
The setup in code example is used to showcase the general application of IOIM. The reference pin will be in output configuration and feedback will be input. The delay between the signal leaving the reference pin and being received in the feedback pin is taken into consideration using the blanking timer.
#include "xc.h"
int main(void)
{
IOIM1CONbits.ON = 0; // module is turned off.
IOIM1STAT = 0; // clearing all status flags
// both of the above steps clears the module status bits.
IOIM1CONbits.TESTEN = 0x00; // set 00/01 to disable artificial test.
IOIM1BCONbits.BLANK = 100; // set to make sure the required delay is given between reference and feedback.
IOIM1CONbits.REFSEL = 8; // this is according to datasheet (pin rc8)
IOIM1CONbits.FBKSEL = 7; // this is according to datasheet (pin rc7)
IOIM1CONbits.EOVFVAL = 10; // set err count overflow value
_IOM1IF = 0; // clear interrupt flag
_IOM1IE = 1; // enable interrupt
_TRISC8 = 0; // set the reference pin to output
_LATC8 = 0; // set the reference pin value
IOIM1CONbits.ON = 1; // module is turned on
while(1);
return 0;
}
void __attribute__((interrupt, no_auto_psv)) _IOIM1Interrupt(void)
{
_IOM1IF = 0; // clear interrupt flag
IOIM1STATbits.ERR = 0;
if(IOIM1STATbits.OVF)
{
IOIM1STATbits.OVF = 0;
// your overflow application code goes here
}
}