Richard R. Pope wrote 2014-07-20 11:31: > Allen, > Would you take a look at my reply to Jan-Erik? I think I finally > understand it. The timer just keeps running forever and it generates an > interrupt every time it rolls over. In this case that is every 100ms. Yes, that part is correct. > So all I have to do is have a variable that keeps track of those > interrupts. Ten counts =3D a second. I'm just staying in a loop for that > one second. Yes, and there are different ways to handle that. Either you put a test on count=3D10 in the ISR itself (faster). Or you can put something like: delay_tens =3D 10; count =3D 0; while (count < delay_tens) {}; // Do whatever has to be done after delay_tens * 0.1 sec. The main() code will stay in the while loop until the ISR has incrimineted the "count" value above 9. The value of delay_tens can be manage through an ADC value if you like to change it. You can also add a reset of the timer so that you do not start with a half timer period and end up with 9.5 seconds. The timer is freerunning and you can get anything between 9 and 10 seconds if you do not init the timer (reset TMR1H and TMR1L) right before each delay. I do not remeber if you specified what error you can accept in the 1 sec timing period. Hm, there are two delays, not? One that should be as close to 1 sec as possible (the measurment itself) and one variable (the display delay between measurments). Is that correct? The last one is not that critical but I guess that the first 1 second measurement timing is (?). Jan-Erik. > When I get back I turn the gate off. I then reenter the loop > for 15 seconds. When that time is up I go back and reset the display. > Since I am using a variable to change the number of seconds I can now > use the ADC to supply a number for the delay loop to adjust how long > between display updates. That is it isn't it?? > Thanks, > rich! > > On 7/19/2014 3:29 PM, Allen Mulvey wrote: >> Richard, >> >> I would do something like this (again in MikroC): >> >> // declare a couple of global variables >> // the scope must make them persist in both Interrupt and main >> Char counter, second_flg =3D0; >> >> //Timer1 >> > --=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 .