Menu

Delayed interrupt

Help
2016-05-30
2016-06-02
  • David Stephenson

    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

    #chip 16F1705,.25
    #config OSC=INTOSC, MCLRE=Off, WDT=off, boren=off
    'I2C settings
    #define I2C_MODE Master
    #define I2C_DATA PORTc.4
    #define I2C_CLOCK PORTc.5
    wait 200 ms
    
    dir portc.3 out
    dir portc.2 out
    dir portc.1 out
    dir portc.0 out
    dir porta.2 in
    dir porta.1 in
    dir porta.0 in
    
    set portc.3 off
    set portc.2 off
    set portc.1 off
    set portc.0 off
    
    ht=0
    kint=0:jint=1
    option_reg.7=0
    
    wpuc=b'00110000' 'i2c pins
    wpua=b'00000111' 'front buttons
    wait 200 ms
    
    on interrupt extint0 call wakeup
    id=0
    dim pressure as word
    dim zht as word
    
    dim xx1 as word
    
    dim alt as word
    dim alt1 as word
    dim d11 as word
    
    wait 500 ms
    
    SL=0x7C 'DISPLAY ID
    COMSEND=0x00 'display COMMAND send
    DS=0X40      'display DATA send
    
    'Main loop
        'Send start
    'INITIALIZATION
    I2CStart
    I2CSEND(Sl)
    I2CSEND(Comsend)
    I2CSEND(0x34) 'initialize 16x1
    'i2csend(0x38) '16x2
    I2CSEND(COMSEND)
    I2CSEND(0x35) '16x1
    'i2csend(0x39) '16x2
    I2CSEND(0x10) 'osc set to slowest
    I2CSEND(0x77) 'contrast low byte=3 now 5 now 7
    I2CSEND(0x54) 'pwr booster on
    I2CSEND(0x6F) 'follower
    I2CSEND(0x0C) 'on/off
    I2CSEND(0x01) 'clear
    I2Cstop
    iicwrite(0x2b,b'00000100') 'press correction +16 Pa
    'iicwrite(0x2b,b'00010101') '+84
    iicwrite(0x2c,b'00010000') 'temp correction add 1.0°C
    '3.6Pa for every foot
    '12 Pa per m
    'ht=44 'height above sea level in meters
    'ht=22
    zht=ht*12
    zht=100
    'iicwrite(0x12,b'10000000') 
    start: 
    do
    q1=q1+1
    if q1=2 then q1=0
    'iicwrite(0x26,b'00111010') 'bar and sample 128
    iicwrite(0x26,b'10111010') 'bar and sample 128 alt
    'iicwrite(0x26,b'00100010') 'bar and sample 16
    WAIT 500 ms 'sampling time
    'sleep
    'nop
    wait 1 sec
    iicread(0x01,p1)
    iicread(0x02,p2)
    iicread(0x03,p3)
    iicread(0x04,b1)
    iicread(0x05,b2)
    b2=b2/16
    b2=((b2*10)+8)/16
    
    'this is the output to the lcd
    if b2=10 then b2=0:b1=b1+1      
    A1=b1/100
    A2=b1%100
    A3=A2/10
    A4=A2%10
    
    alt1=p3/16
    alt=[word]p1*256+[word]p2
    n1=0
    if alt>32768 then alt=65535-alt:n1=1
    xx1=2*alt+(8*alt)/10+5
    xx1=xx1+alt1*328/160
    xx1=xx1/10+3*alt
    
    pressure=xx1
    
    z1=pressure/10000 
    d11=pressure%10000
    z2=d11/100 
    z3=d11%100 
    
    
    I2CStart
    I2CSEND(Sl)
    I2CSEND(Comsend)
    i2csend(0x01) 'clr
    i2cstop
    I2CStart
        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)
    i2cstop
    
    
    
    
    
    Loop
    sub iicread(adr,vlr)
    i2cstart
    i2csend(0xc0) 'send to
    i2csend(adr) 'read id
    i2crestart
    i2csend(0xc1) 'read from
    i2creceive vlr ,nack
    i2cstop
    end sub
    sub iicwrite(adw,vlw)
    i2cstart
    i2csend(0xc0)
    i2csend(adw)
    i2csend(vlw)
    i2cstop
    end sub
    
    
    
    
    
    sub wakeup
    kint=kint+1
    'if kint>1 then kint=0
    wait 5 sec
    
    end sub
    
     
  • kent_twt4

    kent_twt4 - 2016-05-30

    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"

     
  • Anobium

    Anobium - 2016-05-31

    Please post your ASM file as an attachment. I would like to review the oscillator settings.

    Thank you.

     
  • Anobium

    Anobium - 2016-05-31

    Please post your ASM file as an attachment. I would like to review the oscillator settings.

    Thank you.

     
  • David Stephenson

    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

     
  • Anobium

    Anobium - 2016-05-31

    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.

     
  • David Stephenson

    It does much the same thing.

     
  • David Stephenson

    Ah I see I can only attach one file.

     
  • Anobium

    Anobium - 2016-05-31

    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?

     
  • Anobium

    Anobium - 2016-05-31

    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.

     
  • William Roth

    William Roth - 2016-06-01

    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
  • David Stephenson

    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).

     
  • William Roth

    William Roth - 2016-06-02

    Quote:

    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 ?

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.