Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- uint16_t get_period(void)
- {
- uint8_t go;
- uint8_t timeout;
- uint16_t retval;
- // Note: with 32 Mhz clock and /8 prescaler, the frequency
- // of the measured signal can be computed as such:
- // Freq (in MHz) = 16384 / value returned by get_period.
- //
- // For other clock freqs, add proper setup code
- timer1_stop();
- timer1_clear();
- timer1_start();
- PIR1bits.TMR1IF = 0;
- PIE1 = 0x00;
- PIE2 = 0x00;
- // Fix: DON'T just set INTCON=0; this prematurely clears TMR0IF, which is needed
- // for correct blinkage timing. n3wdz 11-17-09
- INTCONbits.PEIE = 0;
- INTCONbits.GIE = 0; // No ints required!
- go = 1;
- timeout = 0;
- // Re-wrote all comparisons to be == or != 0, to generate faster code
- // Resulted in accuracy now of +/- 1 clock tick.
- while (go != 0)
- {
- if (FREQ_PIN != 0)
- { // Wait for high on freq pin
- go = 0;
- }
- if (PIR1bits.TMR1IF != 0)
- { // Check for timer OVFL
- return (0xffff); // Return FAIL
- }
- }
- timer1_stop();
- timer1_clear();
- go = 1;
- timer1_start();
- while (go != 0)
- {
- if (FREQ_PIN == 0)
- { // Wait for low on freq pin
- go = 0;
- }
- if (PIR1bits.TMR1IF != 0)
- {
- return (0xffff); // Return FAIL
- }
- }
- timer1_stop();
- timer1_clear();
- go = 1;
- timer1_start();
- while (go != 0)
- {
- if (FREQ_PIN != 0)
- { // Wait for high on freq pin
- timer1_stop();
- go = 0;
- }
- if (PIR1bits.TMR1IF != 0)
- {
- return (0xffff); // Return FAIL
- }
- }
- timer1_stop();
- retval = (TMR1H << 8) | TMR1L; // Get final timer val
- RFPeriod = retval; // NOTE: If you call get_stable_period, set RFPeriod equal to its result when done
- return (retval);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement