📄 pulse_8c-source.html
字号:
00142 00143 <span class="keywordtype">void</span> pulseT1BRun(u16 nPulses)00144 {00145 <span class="comment">// set the number of pulses we want and the mode</span>00146 <span class="keywordflow">if</span>(nPulses)00147 {00148 <span class="comment">// if the nPulses is non-zero, use "counted" mode</span>00149 PulseT1BMode |= PULSE_MODE_COUNTED;00150 PulseT1BCount = nPulses<<1;00151 }00152 <span class="keywordflow">else</span>00153 {00154 <span class="comment">// if nPulses is zero, run forever</span>00155 PulseT1BMode &= ~PULSE_MODE_COUNTED;00156 PulseT1BCount = 1<<1;00157 }00158 <span class="comment">// set OutputCompare action to toggle OC1B pin</span>00159 <span class="comment">// (note: with all the A's and B's flying around, TCCR1A is not a bug)</span>00160 cbi(TCCR1A,COM1B1);00161 sbi(TCCR1A,COM1B0);00162 00163 <span class="comment">// now the "enabling" stuff</span>00164 00165 <span class="comment">// set the output compare one pulse cycle ahead of current timer position </span>00166 <span class="comment">// to make sure we don't have to wait until the timer overflows and comes</span>00167 <span class="comment">// back to the current value</span>00168 <span class="comment">// set future output compare time to TCNT1 + PulseT1APeriodTics</span>00169 <span class="comment">//outw(OCR1B, inw(TCNT1) + PulseT1BPeriodTics);</span>00170 OCR1B += PulseT1BPeriodTics;00171 00172 <span class="comment">// enable OutputCompare interrupt</span>00173 sbi(TIMSK, OCIE1B);00174 }00175 00176 <span class="keywordtype">void</span> pulseT1AStop(<span class="keywordtype">void</span>)00177 {00178 <span class="comment">// stop output regardless of remaining pulses or mode</span>00179 <span class="comment">// go to "counted" mode</span>00180 PulseT1AMode |= PULSE_MODE_COUNTED;00181 <span class="comment">// set pulses to zero</span>00182 PulseT1ACount = 0;00183 }00184 00185 <span class="keywordtype">void</span> pulseT1BStop(<span class="keywordtype">void</span>)00186 {00187 <span class="comment">// stop output regardless of remaining pulses or mode</span>00188 <span class="comment">// go to "counted" mode</span>00189 PulseT1BMode |= PULSE_MODE_COUNTED;00190 <span class="comment">// set pulses to zero</span>00191 PulseT1BCount = 0;00192 }00193 00194 u16 pulseT1ARemaining(<span class="keywordtype">void</span>)00195 {00196 <span class="comment">// return the number of pulses remaining for channel A</span>00197 <span class="comment">// add 1 to make sure we round up, >>1 equivalent to /2</span>00198 <span class="keywordflow">return</span> (PulseT1ACount+1)>>1;00199 }00200 00201 u16 pulseT1BRemaining(<span class="keywordtype">void</span>)00202 {00203 <span class="comment">// return the number of pulses remaining for channel A</span>00204 <span class="comment">// add 1 to make sure we round up, >>1 equivalent to /2</span>00205 <span class="keywordflow">return</span> (PulseT1BCount+1)>>1;00206 }00207 00208 <span class="keywordtype">void</span> pulseT1AService(<span class="keywordtype">void</span>)00209 {00210 <span class="comment">// check if TimerPulseACount is non-zero</span>00211 <span class="comment">// (i.e. pulses are still requested)</span>00212 <span class="keywordflow">if</span>(PulseT1ACount)00213 {00214 <span class="comment">//u16 OCValue;</span>00215 <span class="comment">// read in current value of output compare register OCR1A</span>00216 <span class="comment">//OCValue = inp(OCR1AL); // read low byte of OCR1A</span>00217 <span class="comment">//OCValue += inp(OCR1AH)<<8; // read high byte of OCR1A</span>00218 <span class="comment">// increment OCR1A value by PulseT1APeriodTics</span>00219 <span class="comment">//OCValue += PulseT1APeriodTics;</span>00220 <span class="comment">// set future output compare time to this new value</span>00221 <span class="comment">//outp((OCValue>>8), OCR1AH); // write high byte</span>00222 <span class="comment">//outp((OCValue & 0x00FF),OCR1AL); // write low byte</span>00223 00224 <span class="comment">// the following line should be identical in operation</span>00225 <span class="comment">// to the lines above, but for the moment, I'm not convinced</span>00226 <span class="comment">// this method is bug-free. At least it's simpler!</span>00227 <span class="comment">//outw(OCR1A, inw(OCR1A) + PulseT1APeriodTics);</span>00228 <span class="comment">// change again</span>00229 OCR1A += PulseT1APeriodTics;00230 00231 <span class="comment">// decrement the number of pulses executed</span>00232 <span class="keywordflow">if</span>(PulseT1AMode & PULSE_MODE_COUNTED)00233 PulseT1ACount--;00234 }00235 <span class="keywordflow">else</span>00236 {00237 <span class="comment">// pulse count has reached zero</span>00238 <span class="comment">// disable the output compare's action on OC1A pin</span>00239 cbi(TCCR1A,COM1A1);00240 cbi(TCCR1A,COM1A0);00241 <span class="comment">// and disable the output compare's interrupt to stop pulsing</span>00242 cbi(TIMSK, OCIE1A);00243 }00244 }00245 00246 <span class="keywordtype">void</span> pulseT1BService(<span class="keywordtype">void</span>)00247 {00248 <span class="comment">// check if TimerPulseACount is non-zero</span>00249 <span class="comment">// (i.e. pulses are still requested)</span>00250 <span class="keywordflow">if</span>(PulseT1BCount)00251 {00252 <span class="comment">//u16 OCValue;</span>00253 <span class="comment">// read in current value of output compare register OCR1B</span>00254 <span class="comment">//OCValue = inp(OCR1BL); // read low byte of OCR1B</span>00255 <span class="comment">//OCValue += inp(OCR1BH)<<8; // read high byte of OCR1B</span>00256 <span class="comment">// increment OCR1B value by PulseT1BPeriodTics</span>00257 <span class="comment">//OCValue += PulseT1BPeriodTics; </span>00258 <span class="comment">// set future output compare time to this new value</span>00259 <span class="comment">//outp((OCValue>>8), OCR1BH); // write high byte</span>00260 <span class="comment">//outp((OCValue & 0x00FF),OCR1BL); // write low byte</span>00261 00262 <span class="comment">// the following line should be identical in operation</span>00263 <span class="comment">// to the lines above, but for the moment, I'm not convinced</span>00264 <span class="comment">// this method is bug-free. At least it's simpler!</span>00265 <span class="comment">//outw(OCR1B, inw(OCR1B) + PulseT1BPeriodTics);</span>00266 <span class="comment">// change again</span>00267 OCR1B += PulseT1BPeriodTics;00268 00269 00270 <span class="comment">// decrement the number of pulses executed</span>00271 <span class="keywordflow">if</span>(PulseT1BMode & PULSE_MODE_COUNTED)00272 PulseT1BCount--;00273 }00274 <span class="keywordflow">else</span>00275 {00276 <span class="comment">// pulse count has reached zero</span>00277 <span class="comment">// disable the output compare's action on OC1B pin</span>00278 cbi(TCCR1A,COM1B1);00279 cbi(TCCR1A,COM1B0);00280 <span class="comment">// and disable the output compare's interrupt to stop pulsing</span>00281 cbi(TIMSK, OCIE1B);00282 }00283 }</pre></div><hr size="1"><address style="align: right;"><small>Generated on Sun Oct 29 03:41:07 2006 for Procyon AVRlib by <a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.2 </small></address></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -