05.01.2015 Views

Measuring Duty Cycles with an Intel MCS-51 ... - Smartec

Measuring Duty Cycles with an Intel MCS-51 ... - Smartec

Measuring Duty Cycles with an Intel MCS-51 ... - Smartec

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

A4. <strong>Duty</strong>-cycle measurement using a programmable counter array<br />

(PCA)<br />

The 80<strong>51</strong>FX derivatives are equipped <strong>with</strong> <strong>an</strong> additional piece of hardware: the programmable<br />

counter array. This consists of one timer <strong>an</strong>d 5 capture registers.<br />

The timer c<strong>an</strong> be programmed to run at a frequency Osc/12 or Osc/4. As compared to the<br />

ordinary 80<strong>51</strong>, the use of the FX types enables to perform the measurements <strong>with</strong> 3 times the<br />

resolution in the same measurement time.<br />

Osc.<br />

÷ 4<br />

CH<br />

CL<br />

CF bit<br />

CR bit<br />

interrupt<br />

CEX0 pin<br />

CCAP0<br />

CCF0 bit<br />

SMT160<br />

CEX1 pin<br />

CCAP1<br />

CCF1 bit<br />

Figure 6. <strong>Duty</strong>-cycle measurement using the PCA.<br />

Moreover, the capture registers c<strong>an</strong> be programmed to capture on rising or falling edges, or<br />

both, so no external XOR gates are required. Since there is a capture register available for<br />

both the rising <strong>an</strong>d the falling edge, interrupt latencies are non critical using this processor<br />

family (Fig. 6). This me<strong>an</strong>s the interrupts h<strong>an</strong>dlers c<strong>an</strong> be easily written using a high level<br />

programming l<strong>an</strong>guage like C.<br />

A example of <strong>an</strong> interrupt h<strong>an</strong>dler that measures n periods of the SMT160 signal consecutively<br />

is given below.<br />

void PCAH<strong>an</strong>dler(void) interrupt 6 using 1 {<br />

static union Word2Byte CaptureUp, CaptureDo;<br />

if (PCAOverFlow) { /* PCA Overflow */<br />

PCAOverFlow = FALSE;<br />

if (!Ready) {<br />

if (OverFlow > 3) { /* 3 overflows => error */<br />

SetCaptureOff(); /* Capture off */<br />

PCACapture0 = FALSE; /* Clear flags */<br />

PCACapture1 = FALSE;<br />

Ready = TRUE; /* measurement done */<br />

Error = TRUE;<br />

} else {<br />

OverFlow++;<br />

};<br />

};<br />

} else {<br />

if (PCACapture1) { /* rising edge */<br />

PCACapture1 = FALSE; /* Clear flag */<br />

if (!Ready) {<br />

CaptureDo.Byte.Hi = CCAP1H; /* save PCA value */<br />

CaptureDo.Byte.Lo = CCAP1L;<br />

HiTime += (CaptureDo.Word - CaptureUp.Word);<br />

}; /* determine low period */<br />

6

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!