1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

Coding a PIC

Discussion in 'Homework Help' started by Logjkos, Jun 24, 2017.

  1. jpanhalt

    jpanhalt Well-Known Member Most Helpful Member

    Joined:
    Jun 21, 2006
    Messages:
    5,983
    Likes:
    511
    Location:
    Cleveland, OH, USA
    ONLINE
    Hi Les,
    Yes, I realized Preset was an equate in your program. That was clear. It was not in Logjkos's code to which my comment applied.

    Edit:
    PS: I believe GIE is cleared automatically upon entry to an interrupt and reset with RETFIE. Without knowing the rest of the code, it might be a good idea to save context, or at least w on entering the interrupt.

    John
     
    Last edited: Jun 27, 2017
  2. Les Jones

    Les Jones Well-Known Member

    Joined:
    May 15, 2015
    Messages:
    1,451
    Likes:
    189
    Location:
    Lancashire UK
    Hi John,
    In my tachometer program everything is done in the interrupt routine (Not normally good practice.) The main program just loops doing nothing so no context saving is needed. The timer interrupt first steps through the multiplexing of the 4 digit display. For each full cycle of the multiplexing it increments an 8 bit count (Just a register.) which divides it by 256. This then gives the gate time for counting the input pulses. I don't think Logjkos has even considered how he plans to display the result of his timing. I did not realise until yesterday how small a change would be required to make my tachometer program do the timing that Logjkos needs. I think I will leave explaining context saving until I see some of the code he writes.

    Les.
     
  3. jpanhalt

    jpanhalt Well-Known Member Most Helpful Member

    Joined:
    Jun 21, 2006
    Messages:
    5,983
    Likes:
    511
    Location:
    Cleveland, OH, USA
    ONLINE
    Hi Les,
    I agree, we need to see something he writes. I did not go through your code very carefully but did notice absence of context saving. Of course, your display routine did not check on STATUS (as far as I could tell), but your routine did use w. Since display routines are usually quite slow relative to other parts of the code, it seemed to me that an interrupt would occasionally hit that routine. That is why I suggested at least saving w and restoring it upon exit from the interrupt.

    John
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. Les Jones

    Les Jones Well-Known Member

    Joined:
    May 15, 2015
    Messages:
    1,451
    Likes:
    189
    Location:
    Lancashire UK

    Hi John,
    The display routine is called from the timer inerrupt. All the display routine has to do is to decide which of the four digits is to be displayed in that multiplexing time slot, clear the bit for that digit drive (Active low.) and copy that digit value to an I/O port. So it only takes a few microseconds. The maximum frequency of the input pulses is about 2.5 Khz which is 400 uS beween them. This is 2000 instruction cycles.

    Les.
     

Share This Page