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