Aha! The for loop doen't have any increment of the loop variable! Yes, that was a bit unusual. Even if it is by-the-book when it comes to C standards, I'd also use some other construct, such as a (more normal) while loop. Jan-Erik. Allen Mulvey wrote 2014-07-20 19:16: > Richard, > > I think you are getting there but there are a few details you missed. > > I've never seen a for loop used like this but it looks like it should wor= k. > I would reset count and use a while loop to wait for the incrementing. > > What you missed is that resetting count is only part of the reset. This i= s > the 10ths of a second. Meanwhile you don't know where the clock is and wi= ll > probably miss part of the first cycle. To get accurate timing you need to > stop the clock with the enable bit, reset the clock high and low register= s, > and reset count. Then use the Clock Enable Bit to accurately restart the > clock, wait for count to increment, etc. > > Putting some of this inside the ISR can be more efficient and even more > accurate as you may eliminate various call and return functions. > > Allen > >> -----Original Message----- >> From: piclist-bounces@mit.edu [mailto:piclist-bounces@mit.edu] On Behalf > Of >> Richard R. Pope >> Sent: Sunday, July 20, 2014 5:23 AM >> To: Microcontroller discussion list - Public. >> Subject: Re: [Pic] Making a special timer! >> >> Jan=3DErik, >> I think I finally understand. I did this. >> Reset display; >> Turn the Gate on; >> call delay(numberseconds); //This will be for one second >> Turn the Gate off; >> >> call delay(numberseconds); again /This will be for 15 seconds= .. >> do forever >> >> delay(numberseconds) >> { >> for(count =3D 0; count <=3D numberseconds*10;); >> return; >> } >> >> interruptcode goes here. >> >> void Interrupt() >> { >> if (TMR1IF_bit) >> { >> TMR1IF_bit =3D 0; >> TMR1H =3D 0x0B; >> TMR1L =3D 0xDC; >> count++; //This increments the count variable >> which was declared as global. >> } >> } >> >> It compiles. Now I have to test it and see what the output is. If this > works I'll >> then add the pot and the ADC so that the display time can be varied. I'm > getting >> there. >> Thanks, >> rich! >> P.S. Allen this also uses your suggestion. >> Thanks, >> rich! >> >> On 7/19/2014 4:39 PM, Jan-Erik Soderholm wrote: >>> > Jan-Erik, >>> > The interrupt happens every 100mS. So for a one second delay I nee= d >>> > to execute ten interrupts. >>> >>> No, that is done automaticly. You doesn't have to >>> do anything, the 10 interrupts will happen each >>> 1 second by the hardware. >>> >>> > But I just don't understand how to do this. >>> >>> You don't have to do anything. Just let your interrupts >>> >> >> -- >> http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive >> View/change your membership options at >> http://mailman.mit.edu/mailman/listinfo/piclist > > --=20 http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .