Menu

ISR code problem

Help
2009-12-01
2013-05-30
  • Alistair George

    Alistair George - 2009-12-01

    Hi if I uncomment the lines below, the ISR does not work any ideas? tks vm
    <pre><code>
    dim T1val as word
    dim tadjust as byte
    sub clockevent
    T1val=64835
    ' tadjust+=30
    ' if tadjust>=222 then
    ' tadjust-=222
    ' if tadjust>2 then leda
    ' T1val+=tadjust
    TMR1ON = 0
    TMR1=0x0
    TMR1H = T1val_h
    TMR1L = T1val
    TMR1ON =1
    'end if
    end sub
    </code></pre>

     
  • Alistair George

    Alistair George - 2009-12-01

    Sorry; drop the ' if tadjust>2 then leda
    line.

     
  • Hugh Considine

    Hugh Considine - 2009-12-01

    Can you post the whole program? It makes troubleshooting easier and much more reliable if I can just copy and paste from the forum into a new text file, and see what GCBASIC does. Also, what is the date on the version of GCBASIC that you're using?

     
  • Alistair George

    Alistair George - 2009-12-01

    Sure, it would be good to be able to PM you, but. Also, I have been having a major problem with oscillator accuracy which is claimed in the book to be 32khz, elsewhere 31 khz then I'm finding it to be more like 25khz!
    Hope I've commented the code enough to help:
    <pre><code>
    #chip 16F690,.031
    #config wdt_on, mclre_off,cpd=1,boren=0,cp_off,OSC=LP
    'Oscillator control register LFINTOSC/31khz
    osccon=b'00001110'
    'PU=off,Intedg=Rise,TOCS=internal,TOSE=low-high,PSA 0=int 1=wdt,xxx=PSArateSelect
    asm MOVLW b'01001111'
    asm option
    'Timer1 register
    t1con=b'10001101' 'Xtal/32768/4=8192cps (1:1 prescale)'
    'Set the pin directions
    dir PORTC.0 out
    dir PORTC.1 out
    dir PORTC.2 out
    dir PORTC.3 out
    #define ledR PulseOut portc.0, 25 ms 'Pulse LED on/off
    #define ledY pulseout portc.1, 25 ms
    #define ledA pulseout portc.2, 25 ms
    #define ledG pulseout portc.3, 25 ms
    dim freqhi,freqlo as word 'var Current sensor data
    dim averagehi,averagelo as word 'var Running Average
    #define triphi 100
    #define triplo 100 'const Trip point

    On Interrupt Timer1Overflow call clockevent 'On Interrupt Timer0Overflow call clockevent
    On Interrupt Comp1Change call touchroutine
    On interrupt ADCReady call ThermoEvent
    dim hour,T1val as word
    dim T1,mins,secs,count,tadjust as byte
    count=0
    secs=0
    mins=0
    hours=0
    oscdiv=0
    tadjust=0
    sw=0
    T1=0 '_T1 event
    TMR1=0
    T1val =65500
    TMR1H = T1val_h
    TMR1L = T1val
    TMR1=1
    dir porta.2 out
    IntOn 'Go interrupts
    main:
    clrwdt 'Make sure this is in the loop
    'Timer event
    'IntOff
    if hours<1 & secs<>count then ledg:count=secs 'indicate up to 1 hour secs display
    if secs>59 then 'seconds beep
    secs=0
    mins+=1
    repeat 10
    PulseOut porta.2,200 us
    Wait 200 us
    end repeat
    end if
    if mins>59 then
    mins=0
    hours+=1
    'binary hours clock indicator
    if hours.0 then ledr 'set PortC.0 on
    if hours.1 then ledy 'set PortC.1 on
    if hours.2 then leda 'set PortC.2 on
    if hours.3 then ledg 'set PortC.3 on
    PortC=0
    if hours>15 then hours=0
    end if
    'IntOn
    goto main

    sub ShowLeds(in whichleds)
    select case whichleds
    end sub

    sub clockevent
    T1val=65160+23 'allow for ISR/clockevent delay
    '*******faulty upper code follows
    ' tadjust+=30
    ' if tadjust>=222 then
    ' tadjust-=222
    ' if tadjust>2 then leda
    ' T1val+=tadjust
    TMR1ON = 0
    TMR1=0x0
    TMR1H = T1val_h '0xe1 '0xDF
    TMR1L = T1val 'T1val '0xb7 '0xFF
    Tadjust+=1 'temporary use of tadjust until upper code is fixed
    if tadjust>19 then tadjust=0:secs+=1 'inc seconds
    TMR1ON =1
    'end if
    end sub

    sub touchroutine
    end sub

    sub ThermoEvent
    end sub
    </code></pre>

     
  • Alistair George

    Alistair George - 2009-12-01

    Hmmm dont know why the markup came in different fonts; oh well.
    Version of my GCB is 0.9 15/11

     
  • Nobody/Anonymous

    I think the internal 32KHz oscillator is primarily for clocking the watchdog timer, and keeping the processor alive during low power modes. I believe they tell you it can be all over the map, varying from chip-to-chip, with voltage, and with temperature. If you need better accuracy, clock the processor and timer from the internal 4 or 8MHz clock, but even this can only be counted on for about 1% accuracy. If you need better accuracy, you'll have to use an external crystal.

     
  • Alistair George

    Alistair George - 2009-12-02

    Yep, I have figured that - 1% is quite a timing error and thats the best you can get out of the OSCHi. But this still does not figure why the commented code above does not work?

     
  • kent_twt4

    kent_twt4 - 2009-12-02

    Just guessing here, but suspect there may be a problem when writing to TMR1 register.  Look at:

        T1val =65500
        TMR1H = T1valh
        TMR1L = T1val

    T1valh should be T1val_H.  Another way to do this, as explained to me before by Hugh, is to use an alias.  I think this is more flexible way.

        Dim BigVar As Word Alias HighByte, LowByte

     

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.