I have another problem always on the PIC16F18857.
I have to use interrupt-on-change on PORTC.6.
I execute all the settings of the case and I can not get this interrupt.
Where am I wrong?
You need to setup the interrupt. Section 15.2 and 15.3 of the datasheet.
I have made the code simply. Great Cow BASIC should set up everything else. And, you should not do much in an interrupt - keep an interrupt small (as the general case).
Untested but should be ok code.
:-)
' $formattagcb' -' Configuration
#Chip16F18857, 32' -OnInterruptPORTChangeCallInterrompo' -' -
#OptionExplicitdimeventhappenedasbit'Call setup...Registri' -' -Doifeventhappened=truethen'CLS'Print "It happened"eventhappened=FalseendifLoop' -' -' -SubRegistriDirPORTC.6InIOCCP6=1' Imposta l'InterruptsurisingEdgeEndSubSubInterrompo'has the event happended and we need to check we have completed handlign the previous eventIFIOCCF6=1ANDeventhappened=falseTHENeventhappened=trueENDIFEndSub
Last edit: Anobium 2019-09-07
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Your approach in using a sub may fail you. Why? You enable all the interrupt handlers in the command On Interrupt PORTChange Call Interrompo, then, you in the sub you setup the interrupt bit - the event could then fire and your main code is never reached... the interrupt is firing all the time (I can that here on the scope).
So, an approach that should work for you is shown below. Note. If you do not clear the event bit in the interrupt handler you will also get stuck in the interrupt handler... as the switch causing the event may bounce.
Interrupts like this look simple. They are not.
:-)
' $formattagcb' -' Configuration
#Chip16F18857, 32' -' -' -
#OptionExplicitdimeventhappenedasbyte'led outdirporta.2out'You need to consider very carefully about using a sub....DirPORTC.6InIOCCN6=1' Imposta l'InterruptsurisingEdgeeventhappened=falseOnInterruptPORTChangeCallInterrompoDo'There is debounce here. You may get multiple events event with this approachifeventhappened=truethenporta.2=!porta.2wait10mseventhappened=FalseendifLoopSubInterrompo'has the event happended and we need to check we have completed handling the previous eventIFeventhappened=falseTHENeventhappened=trueENDIF'clear the event here!IfIOCCF6=1thenIOCCF6=0EndSub
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thank you for your help.
Now the program runs perfectly.
Studying the assembler listing I noticed that the compiler zeroed the IOCIF bit of PIR0
( banksel PIR0
bcf PIR0,IOCIF
).
The datasheet indicates it as a read-only bit
(The IOCIF bits are the logical OR of all the IOCAF-IOCEF flags.
Therefore, to clear the IOCIF flag, application firmware should clear all of the lower level IOCAF-IOCEF register bits.)
This obviously has no effect on the operation of the program.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
i am trying to clear PTR0bits.IOCF = 0 in this interrupt handler but they given
(The IOCIF bits are the logical OR of all the IOCAF-IOCEF flags.
Therefore, to clear the IOCIF flag, application firmware should clear all of the lower level IOCAF-IOCEF register bits.)
inside pin manager ioc i saw:
IOCAFbits.IOCAF0 = 0;
so where i am missing.... consider the steps and suggest me
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have another problem always on the PIC16F18857.
I have to use interrupt-on-change on PORTC.6.
I execute all the settings of the case and I can not get this interrupt.
Where am I wrong?
You need to setup the interrupt. Section 15.2 and 15.3 of the datasheet.
I have made the code simply. Great Cow BASIC should set up everything else. And, you should not do much in an interrupt - keep an interrupt small (as the general case).
Untested but should be ok code.
:-)
Last edit: Anobium 2019-09-07
Code that works.
Your approach in using a sub may fail you. Why? You enable all the interrupt handlers in the command
On Interrupt PORTChange Call Interrompo
, then, you in the sub you setup the interrupt bit - the event could then fire and your main code is never reached... the interrupt is firing all the time (I can that here on the scope).So, an approach that should work for you is shown below. Note. If you do not clear the event bit in the interrupt handler you will also get stuck in the interrupt handler... as the switch causing the event may bounce.
Interrupts like this look simple. They are not.
:-)
Thank you for your help.
Now the program runs perfectly.
Studying the assembler listing I noticed that the compiler zeroed the IOCIF bit of PIR0
( banksel PIR0
bcf PIR0,IOCIF
).
The datasheet indicates it as a read-only bit
(The IOCIF bits are the logical OR of all the IOCAF-IOCEF flags.
Therefore, to clear the IOCIF flag, application firmware should clear all of the lower level IOCAF-IOCEF register bits.)
This obviously has no effect on the operation of the program.
Yes, I spotted the read-only bit. This is deep in the compiler so I would not worry about this.
Enjoy.
Hi guys,
i am also facing problem to make work IOC (interrupt on change) for PIC16F18857..
i am using MPLAB X IDE and XC8 compiler and code configurator (MCC)..
i configured 1 pin as input (IOC negative edge detection) and one pin as output ( LED)....
generated code...
interrupt manager file has code :
pin manager file , where i added the LED toggle macro:
*/
main code :
these are the coding files....
when i press the switch LED is not toggling ...
not getting where is the problem in IOC(interrupt on change)..
please help me to sort out... this is much needed to me..
Last edit: Anobium 2020-11-10
Megha - we are the forum for Great Cow BASIC not MPLAB-IDE.
But, you just need to use MMC (part of MPLAB-IDE) and this should work.
Hi thanks for reply..
what is MMC in MPLAB...
I used MCC - MPLAB CODE configurator ....
i not hard about MMC can u please explain it
My apologies. I meant MCC not MMC. :-)
Thanks for your reply...
I used MCC only for configuration but IOC not working...
struggling to fix it but not getting where is the problem..
tried to post in microchip but not able to post...
please help me if you have any idea
The issue is we do Great Cow BASIC here and Great Cow BASIC generates ASM that you could use within your MPLAB-X project. Is this any use?
just tell me the steps to configure the IOC ...
i took one pin RA0/pin2 as input and RA1/pin3 as switch...
for input i selected IOC negative edge..
wpu week pullup...
output LED , digital..
after generating the MCC project...
ISR routine it generated ...
void __interrupt() INTERRUPT_InterruptManager (void)
{
// interrupt handler
if(PIE0bits.IOCIE == 1 && PIR0bits.IOCIF == 1)
{
PIN_MANAGER_IOC();
}
else
{
//Unhandled Interrupt
}
}
/**
i am trying to clear PTR0bits.IOCF = 0 in this interrupt handler but they given
(The IOCIF bits are the logical OR of all the IOCAF-IOCEF flags.
Therefore, to clear the IOCIF flag, application firmware should clear all of the lower level IOCAF-IOCEF register bits.)
inside pin manager ioc i saw:
IOCAFbits.IOCAF0 = 0;
so where i am missing.... consider the steps and suggest me
I can look later, I need to install MPLAB etc.
Here is a Great Cow BASIC project. This is tested and works on a real chip.
PB7 - switch
PB6- LED
This is truly simple and took about 5 minutes.
Evan
Last edit: Anobium 2020-11-10
can you try with Port A pins ..and try once....
if possible try for MCC....
needed for me
Great Cow BASIO with Porta.0 rather than Portb.6 as the swtich.
This is very easy to do in Great Cow BASIC and you should be able to use the approach in MPLABX -IDE as ALL the registers are the same.
hi..
i am checking by debugging mode after pressing the switch
IOCAF0 bit is not setting....PIRbits.IOCF is not setting....
what is the reason
I would be guessing. Not set as an input? not enabled the interrupts?
but IOCAN0 = 0x01 i can check while debugging..
which is negative edge detection i setted...
Have you checked?
i setted
IOCAF0 = 1 at initialization...
IOCAN0 = 1
IOCAP0 = 0...
that first bit setting what will happen
i checked with
IOCF0 = 0
IOCANO = 1
IOCAP0 = 0
pin is input only and it is not analog
still also IOCAF0 bit is not setting
means negative edge is not detecting..
how to fix...
Sounds like you have no enabled the interrupts.
Attach main.c please.
hi...
i attached enabled global interrupt enable.
peripheral interrupt enable..
i shared main code previous post can you check once.
please