Continue to Site

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.

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

Coding a PIC

Status
Not open for further replies.
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:
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.
 
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
 
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.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top