Re: Problem with volatile modifier

From: Marcin Kalicinski (kalita_at_poczta.onet.pl)
Date: 10/01/04


Date: Fri, 1 Oct 2004 11:02:07 +0200


> int clock, rolls;
> do
> {
> clock = read_clock();
> rolls = read_rolls();
> } while (clock != read_clock());

This approach will create an infinite loop because clock is updated by
hardware very often (roughly at the speed of CPU clock) and will certainly
change between two read_clock() calls in the above loop. So, the condition
in while will always be met.

> > atomically_, and your approach is flawed, as you have two threads of
> > execution trying to update flag. What you have to do is read both in a
> > loop, exiting when two consective reads are the same for both, then

No, I don't have threads. The situation is different because interrupts are
synchronous unlike threads. If interrupt handler is executing, the main
program is stopped until the handler finishes. Handler cannot be interrupted
in the middle (at least not to return control back to main program).

What I think now is that my approach to use this little hardware clock as a
long-term timer is doomed, because from time to time other interrupts with
greater priority happen, and prevent calling of handler() on clock overflow.
Thus, the clock misses some overflows.

Best regards,
Marcin



Relevant Pages

  • Re: Breadboarded 74HCT7046 PLL very unstable
    ... I'm trying to recover the bit clock from a 6.9375MHz NRZ bit stream. ... lock within 16 bits or less (or at least lock well enough to shift in and ... How did you design your loop, ...
    (sci.electronics.design)
  • Re: Antenna for receiving WWV/10MHz: am I asking too much?
    ... a clean WWV signal. ... Clock II from my father. ... better antenna, one which would let the clock lock onto WWV at ... My attempt at a 30m indoor loop antenna: ...
    (rec.radio.amateur.antenna)
  • Re: All Digital PLL Design
    ... and the leading edge of the feedback clock makes it count down. ... and the loop bandwidth will usually be ... the input clock leads the feedback by pi radians. ... I simulated this with gain settings of A=64 for the proportional path ...
    (comp.dsp)
  • Re: Breadboarded 74HCT7046 PLL very unstable
    ... I'm trying to recover the bit clock from a 6.9375MHz NRZ bit stream. ... lock within 16 bits or less (or at least lock well enough to shift in and ... How did you design your loop, ...
    (sci.electronics.design)
  • Re: Event Driven State Machine
    ... Place the case statement in an infinite loop, ... of it's own (aside from the occasional serial clock) it has to operate ... -- Defined as I2C Master Start Sequence ... -- Transmit the acknowledge ...
    (comp.lang.vhdl)