tmr2 interrupt problem


Closed Thread
Results 1 to 28 of 28

Hybrid View

  1. #1
    Join Date
    Dec 2007
    Location
    The Netherlands, Groningen
    Posts
    16


    Did you find this post helpful? Yes | No

    Default

    Thanks, I didn't know how long the ISR really was.
    Now we know this, there are a couple of possible solutions..
    make the timer longer to 6 or 8 mSec, restart and reload the timer after the ISR or make the ISR less long.

    I tried to restart the timer after the ISR(above post) but that didn't work.. Suprisingly did it work somehow when the end of the ISR was 'resume loop'. Then was the program able to make a I2C-read from the RTC and update the var's.

    So, the first possible solution is to make longer the timer to let's say 8mSec and afther that reduce the length of the ISR and posible to set the timer back to 2mS.

    The ISR is doing a lot of work every time and that is not necessary do execute every time. The lookup for segments is not deeded everytime but can be executed in the program somewhere else and 1 in the 10 times of shiftout is also very acurate(I'm not placing it in a nucear powerplant... ) So the only thing left for the ISR to do is shiftout the segmentsdata.

    I had problems with var's I did change at the mainloop. He didn't update them by the shiftout.

    So, when I place this T2CON = %00000010 is the presale to 1:16 and is the timer about 8mSec, right? Then it have to work anyway?

    about the schematic: a ds1307 is connected to A0 & A1. the two 74HC595 are placed at B0 & B1. The pushbuttons for the menu are at port A2, A3 & A7. All including external pullups. For the 7segmentsdisplays are resistors added. The 7segmentsdisplays are Common Cathode and connected with a BC557C to the GND. The PIC16f628 is working at it's internal oscillator. And a smal capacitor of 0,1uF added from V+ to GND near the IC's. So, it's all very basic and there isn't more to tell about the schematic.

    Can you also measure how long it takes for a I2C-read and write? Because, when I delete it from the mainloop the ISR can use other var's from the loop...
    Last edited by ADCON; - 30th December 2007 at 12:00.

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    To measure how long a single code line or chunk of code need toexecute, you have several method
    1: Scope method
    you Set/Clear an I/O before and after a code chunk, then you measure it with a scope

    2: MPLAB StopWatch
    You set a breakpoint at the end of the code chunk you want to measure, You set the PC at the start of the code chunk, then you click on Run at PC (refer to MPLAB help file)

    3: use a PIC timer
    Same concept as StopWatch but you need to send the results to a LCD or via serial communication. The following link explain it better

    instruction execution time
    http://www.picbasic.co.uk/forum/showthread.php?t=365

    i'll try to figure out what the heck happen here... would be nice if i had those shift register
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Dec 2007
    Location
    The Netherlands, Groningen
    Posts
    16


    Did you find this post helpful? Yes | No

    Default

    thanks, I use microcodestudio but this is a reason to look for MPlab.
    Microcodestudio sadly don't have a timerfunction. A time ago did I look for MPlab but it looked a lot harder to work with to me.

    The shiftregisters works simple. It is data+clock and when all data is loaded a puls so the latches reset to the new value.
    Maby you do have Proteus VSM? I mean that they have also this registers(haven't a lisence myself). The datasheet is here: http://www.alldatasheet.com/datashee...S/74HC595.html

    The RTC I used is a DS1307 from Maxim-ic.com but that works fine..

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Proteus VSM any sim E+457810214

    sorry not for me.

    Yeah i know those shift register and i know what a shift register is, what i meant is that it would be great if i had them in stock to build the circuit and test it in a real environment.

    I'm not a Sim fan... i know a few people using it for all their design and they seems to be more than happy with it.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    Join Date
    Dec 2007
    Location
    The Netherlands, Groningen
    Posts
    16


    Did you find this post helpful? Yes | No

    Default

    Yes, sim programs are expensive. I had a free beta-testversion once, it had still to much bugs to work with, after that came the pay-version.. I also like to life-test also my bankaccount.. it only takes sometimes some more time. But the good side is that when it workt it really works and with sim-programs is that always a question..

    Well, Possibli can you tell me the length of a I2Cread/write procedure because I think that it is also to long. When I start the timer after the ISR it will only read the RTC, it never finishes the coldstart.

    I did try to set the prescale to 1:16 but it hadn't any good progress. How do I become a timerinterrupt every 8mSec? of 16msec? Maby I can thy that so it works..

  6. #6
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Well the prescaler was already 1:16 at the first post.. hence why you didn't had any better results
    Now what you need to do is to use the POSTscaller. if you set the postscaller to 1:2 you'll have a 2mSec*Prescaller int. 8mSec, postscaller 1:4 and so on
    Code:
            T2CON = %00011010
                    'X------- Unimplemented
                    '-0011--- postscale 1:4
                    '-----0-- Timer2 off
                    '------10 prescaler 1:16
    seems to work with the second suggestion
    Code:
    // Snip
            ON INTERRUPT GOTO ISR
            PR2 = 124   ' load period register for 2mSec 
            PEIE = 1    ' Enable peripheral interupt
            GIE = 1     ' enable Global interrupt
            TMR2ON = 1  ' TMR2 ON
            GOTO LOOP                
    
            disable
    ISR:
            TOGGLE PORTB.0
            TMR2IF = 0  ' Clear interrupt flag
            resume
            enable
    // end snip
    Last edited by mister_e; - 30th December 2007 at 21:26.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  7. #7
    Join Date
    Dec 2007
    Location
    The Netherlands, Groningen
    Posts
    16


    Did you find this post helpful? Yes | No

    Default

    thanks, i just found it myself.

    4000000/4/256/16/2=122
    osc/4/8bit/precaler/postprescaler=period
    1/122=0,008S

    4000000/4/256/16/4=61
    1/61=0,016S

    now try at the code..

Similar Threads

  1. Problem with Interrupt on PIC18F4620 PORTB
    By rookie in forum Off Topic
    Replies: 1
    Last Post: - 22nd March 2007, 01:34
  2. Problem with PBP interrupt and Serin, please help
    By rgregor in forum mel PIC BASIC
    Replies: 0
    Last Post: - 22nd August 2006, 19:02
  3. Interrupt Problem
    By Kamikaze47 in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 16th November 2005, 20:58
  4. Interrupt stack overflow problem with Resume {label}
    By Yuantu Huang in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 3rd May 2005, 01:17
  5. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 01:07

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts