piclist 2001\04\05\104208a >
Thread: 16C73 vs 16F873: stability and timing
face BY : David Cary email (remove spam text)

Dear ``embedded engineer'' David,

embedded engineer <KILLspamembeddedspam_OUTspamELUCIT.COM> on 2001-04-04 05:25:20 PM (David) wrote:

>#BYTE T1_HIGH = 0x0f
>         // sync with transition of timer 1
>         timer = T1_HIGH;        // changes at 128 Hz
>         while (timer = T1_HIGH);
> It blocks until a change only, indicating overflow from T1_LOW.

This may not solve your problem, but have you considered saying
        while (timer == T1_HIGH);
(Using single equals inside a if() or while() expression, when I meant to use a
double equals, is the number 1 mistake I make when writing C code. I set my C
compiler to give me a error when I do that.)

{Quote hidden}

I doubt this is your problem, but some people would write code more like
         BYTE end_time = timer+poll_count;
         while( 0 < (BYTE)(end_time - T1_HIGH) ) {
>                 if (clk_bit != INBIT) {
>                         clk_bit = INBIT;
>                         result++;
>                 }
>         }
so they don't lose time if T1_HIGH counts 3 or 4 times during a long interrupt.
The comparison above has the amazing property of Doing the Right Thing even when
T1 overflows,
         while( T1_HIGH < end_time ) { doesn't work when end_time = 0xFF and T1
skips a count to reach 0x00.}

Since you have disabled interrupts, this doesn't matter.
Also, this only works up to poll_count == 0x7F (um... I think ...), while your
method works even for poll_count == 0xFF.

David Cary

http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email TakeThisOuTlistservKILLspamspamspammitvma.mit.edu with SET picList DIGEST in the body

seeking: microchip devices pic

See also: www.piclist.com/techref/microchip/devices.htm?key=16F
Reply You must be a member of the piclist mailing list (not only a www.piclist.com member) to post to the piclist. This form requires JavaScript and a browser/email client that can handle form mailto: posts.
Subject (change) 16C73 vs 16F873: stability and timing

month overview.

new search...