I have a push button attached to the interrupt pin. When it is pushed the interrupt takes about 2 minutes to take effect.
Any ideas what is going on. I'm using a 16LF1705 and I've sucessfully managed to get a similar arranged interrupt to work with a different circuit.
Here's the code
#chip16F1705,.25#configOSC=INTOSC,MCLRE=Off,WDT=off,boren=off'I2C settings#define I2C_MODE Master#define I2C_DATA PORTc.4#define I2C_CLOCK PORTc.5wait 200 msdir portc.3 outdir portc.2 outdir portc.1 outdir portc.0 outdir porta.2 indir porta.1 indir porta.0 inset portc.3 offset portc.2 offset portc.1 offset portc.0 offht=0kint=0:jint=1option_reg.7=0wpuc=b'00110000' 'i2cpinswpua=b'00000111''front buttonswait 200 mson interrupt extint0 call wakeupid=0dim pressure as worddim zht as worddim xx1 as worddim alt as worddim alt1 as worddim d11 as wordwait 500 msSL=0x7C 'DISPLAYIDCOMSEND=0x00'display COMMAND sendDS=0X40 'displayDATAsend'Main loop 'Sendstart'INITIALIZATIONI2CStartI2CSEND(Sl)I2CSEND(Comsend)I2CSEND(0x34) 'initialize16x1'i2csend(0x38) '16x2I2CSEND(COMSEND)I2CSEND(0x35)'16x1'i2csend(0x39)'16x2I2CSEND(0x10) 'oscsettoslowestI2CSEND(0x77)'contrast low byte=3 now 5 now 7I2CSEND(0x54) 'pwrboosteronI2CSEND(0x6F)'followerI2CSEND(0x0C) 'on/offI2CSEND(0x01)'clearI2Cstopiicwrite(0x2b,b'00000100') 'presscorrection+16Pa'iicwrite(0x2b,b'00010101') '+84iicwrite(0x2c,b'00010000')'temp correction add 1.0°C'3.6Paforeveryfoot'12 Pa per m'ht=44'height above sea level in meters'ht=22zht=ht*12zht=100'iicwrite(0x12,b'10000000') start: doq1=q1+1if q1=2 then q1=0'iicwrite(0x26,b'00111010')'bar and sample 128iicwrite(0x26,b'10111010') 'barandsample128alt'iicwrite(0x26,b'00100010') 'barandsample16WAIT500ms'sampling time'sleep'nopwait 1 seciicread(0x01,p1)iicread(0x02,p2)iicread(0x03,p3)iicread(0x04,b1)iicread(0x05,b2)b2=b2/16b2=((b2*10)+8)/16'thisistheoutputtothelcdifb2=10thenb2=0:b1=b1+1A1=b1/100A2=b1%100A3=A2/10A4=A2%10alt1=p3/16alt=[word]p1*256+[word]p2n1=0ifalt>32768thenalt=65535-alt:n1=1xx1=2*alt+(8*alt)/10+5xx1=xx1+alt1*328/160xx1=xx1/10+3*altpressure=xx1z1=pressure/10000d11=pressure%10000z2=d11/100z3=d11%100I2CStartI2CSEND(Sl)I2CSEND(Comsend)i2csend(0x01)'clri2cstopI2CStart I2Csend(Sl) I2Csend(DS)i2csend(32)if n1=1 then i2csend(45)if n1=0 then i2csend(43) 'I2CSend((z1/10)+48)I2CSend((z1%10)+48)'data long I2CSend ((z2/10)+48) I2CSend ((z2%10)+48) I2CSend ((z3/10)+48) I2CSend ((z3%10)+48)i2csend(32)i2csend(32)i2csend(102)i2csend(116)i2csend(32)i2csend(kint/10+48)i2csend(kint%10+48)i2cstopLoopsub iicread(adr,vlr)i2cstarti2csend(0xc0) 'sendtoi2csend(adr)'read idi2crestarti2csend(0xc1) 'readfromi2creceivevlr,nacki2cstopendsubsubiicwrite(adw,vlw)i2cstarti2csend(0xc0)i2csend(adw)i2csend(vlw)i2cstopendsubsubwakeupkint=kint+1'ifkint>1thenkint=0wait5secendsub
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Yes it's a curious error. It would seem the interrupt is being captured, but it is not going to the sub WAKEUP and then the interrupt flag is not being reset. I've found that the following line overcome the problems
I am going offline for the day. I had alread reformated so I could review the code. I would check ALL the if-then-endif statements. I am not sure how to handle single line if-then statements - I do not use them.
I have added a new #define as this will prevent interrupt from being turned on/off in the i2c handler but this may introduce an issue with I2C timing.
Divide and Conquor. Instead of debugging the program as a whole why not try simple code first to test basic wake from sleep functionality on this specific chip at such a low clock speed. If the code below does not work as expected then the Chip Data file may need to be looked at for Registers & bits. ( This same code works ok on an 18F25K22) .
However...
I also tested wake from sleep on ext int in a large program that uses an I2C LCD and SPI . It seem ok at first but.... If I repeatedly trigger the interrupt pin. The LCD eventually stops working and the
program appears to hang somewhere in the LCD or I2C code. Montoring the FOSC/4 on the clock out pin show that the interrupt still works (system clock still stops & starts with button press)
Wrapping all I2C/LCD functions with INTOFF and INTON seemed to stop the hangs.
You can test if the interrupt is working by enabling clock out in the config and looking at the system clock with a scope. on the 16F1705 PortA.4 will need to be freed up to do this.
My question sbout the 16F1705 and related code is ... Is the interrupt really delayed or is IC2 failing?
If the code below works and then if checking the clock using normal code shows the clock starting & stopping then the interrupt functionality is ok. If the code below fails then it may be registers and bits related to interrupts, PPS, or even OSC problems.
It might could even be that the LCD needs to run at a faster speed. I would try 500K and then 1Mhz and see if the same problem occurs.
#chip 16F1705,.25
#config OSC=INTOSC, MCLRE=Off
#Config WDT=off, boren=off
'//Connect an LED to Pin 2
'// Via 1K resistor
#Define LED PORTA.5 Pin 2
DIR LED OUT
'//INT0 is on PORTA.2 PIN 11
'// Pull Pin Low with 10K resistor
'//Default INT on rising edge
On interrupt extint0 call Test_Interrupt
Set LED OFF
Wait 5 Sec
'------------------------
Do
Repeat 2
Set LED ON
wait 200 ms
Set LED OFF
Wait 200 ms
End Repeat
SLEEP '// Waiting for INT
NOP
Loop
'-------------------------
Sub Test_Interrupt
NOP
Repeat 5
Set LED ON
wait 200 ms
Set LEd OFF
Wait 200 ms
End repeat
Wait 2 Sec
End Sub
Last edit: William Roth 2016-06-01
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Yes the interrupt is working as the INTCON.1 bit is set.
What is happening is the program is not branching to the interrupt subroutine (wakeup) and the INTCON.1 flag bit is not being reset.
If I use the interrupt to wake from sleep it happens immediately, but it continues to break out of sleep several more times (maybe around 5-10) before the sleep works properly once more.
I've got another circuit working with the same I2C display(MCCOG21605) and the interrupt works fine so it must be the rather more involved I2C two-way communication with the pressure sensor (MPL3115A2).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
If I use the interrupt to wake from sleep it happens immediately, but it continues to break out of sleep several more times (maybe around 5-10) before the sleep works properly once more.
This is rather odd behavior. Have you sustematically removed/disabled sections of code to try to positively determine determine the root cause ?
A simple question but I have to ask. Is there a resistor from the interrupt pin to ground to prevent it from, floating ?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have a push button attached to the interrupt pin. When it is pushed the interrupt takes about 2 minutes to take effect.
Any ideas what is going on. I'm using a 16LF1705 and I've sucessfully managed to get a similar arranged interrupt to work with a different circuit.
Here's the code
The interrupt and INT pin look to be set correctly; same goes for the OSC.
There is a typo in the iicread sub, could that be hanging the code?
"i2creceive vlr ,nack"
Please post your ASM file as an attachment. I would like to review the oscillator settings.
Thank you.
Please post your ASM file as an attachment. I would like to review the oscillator settings.
Thank you.
Yes it's a curious error. It would seem the interrupt is being captured, but it is not going to the sub WAKEUP and then the interrupt flag is not being reset. I've found that the following line overcome the problems
if intcon.1 = 1 then wakeup
set intcon.1 off
Anyway I have attached the ASM
Thank you.
I recommend you upgrade your Great Cow BASIC installation. The later releases address specific issues with the 16f1705 chipset range.
Whilst an upgrade may not fix the issue - it will enable us to provide the best resolution.
Backup you existing install (a complete set of folders as the backup), and, install the latest release.
Retest. Post the new GCB source file and the asm as a zip please.
It does much the same thing.
Ah I see I can only attach one file.
I have reviewed the code.
I would expect a some delay as you describe.
Before I advise. Are you using the IDE to write this code? or GCGB?
I am going offline for the day. I had alread reformated so I could review the code. I would check ALL the if-then-endif statements. I am not sure how to handle single line if-then statements - I do not use them.
I have added a new #define as this will prevent interrupt from being turned on/off in the i2c handler but this may introduce an issue with I2C timing.
Do try - the define may resolve the issue.
Divide and Conquor. Instead of debugging the program as a whole why not try simple code first to test basic wake from sleep functionality on this specific chip at such a low clock speed. If the code below does not work as expected then the Chip Data file may need to be looked at for Registers & bits. ( This same code works ok on an 18F25K22) .
However...
I also tested wake from sleep on ext int in a large program that uses an I2C LCD and SPI . It seem ok at first but.... If I repeatedly trigger the interrupt pin. The LCD eventually stops working and the
program appears to hang somewhere in the LCD or I2C code. Montoring the FOSC/4 on the clock out pin show that the interrupt still works (system clock still stops & starts with button press)
Wrapping all I2C/LCD functions with INTOFF and INTON seemed to stop the hangs.
You can test if the interrupt is working by enabling clock out in the config and looking at the system clock with a scope. on the 16F1705 PortA.4 will need to be freed up to do this.
My question sbout the 16F1705 and related code is ... Is the interrupt really delayed or is IC2 failing?
If the code below works and then if checking the clock using normal code shows the clock starting & stopping then the interrupt functionality is ok. If the code below fails then it may be registers and bits related to interrupts, PPS, or even OSC problems.
It might could even be that the LCD needs to run at a faster speed. I would try 500K and then 1Mhz and see if the same problem occurs.
Last edit: William Roth 2016-06-01
Yes the interrupt is working as the INTCON.1 bit is set.
What is happening is the program is not branching to the interrupt subroutine (wakeup) and the INTCON.1 flag bit is not being reset.
If I use the interrupt to wake from sleep it happens immediately, but it continues to break out of sleep several more times (maybe around 5-10) before the sleep works properly once more.
I've got another circuit working with the same I2C display(MCCOG21605) and the interrupt works fine so it must be the rather more involved I2C two-way communication with the pressure sensor (MPL3115A2).
Quote:
This is rather odd behavior. Have you sustematically removed/disabled sections of code to try to positively determine determine the root cause ?
A simple question but I have to ask. Is there a resistor from the interrupt pin to ground to prevent it from, floating ?