Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///////////////////////////////////////
- // Lab 5 - Microcontrollers, Triggers
- // M K Gharzai
- // Oct 08 2017
- ///////////////////////////////////////
- uint16_t captureTime, captureTimePrev, diff;
- void setup()
- {
- Serial.begin(115200);
- // consult the AVR manual and set the following registers,
- // you can use binary or hex, e.g:
- // 0b00001000 == 0x04
- // A = 0x80; // to set a value (A = 0b10000000)
- // A |= 0x2A; // to pull bits high (A = 0b10101010)
- // A &= 0x08; // to pull bits low (A = 0b00001000)
- DDRB = 0x00; // all pins on PORTB should be defined as inputs
- TCCR1A &= 0b11111100; //should only affect bits 0 and 1 to activate normal counter operation
- TCCR1B |= 0b11000010; //Bit 7 activates noise cancellation, 6 sets rising edge trigger, bit 1 is part of clock scaling
- TCCR1B &= 0b11100010; //These bits are set to only affect the WGM and other pins in the line above
- TIMSK1 |= 0b00100000; //This turns on the ICIE1 Interrupt Enable
- SREG |= 0x80; // enable global interrupts
- }
- void loop()
- {
- diff = captureTime - captureTimePrev;
- Serial.print("difference: "); Serial.print(diff);
- Serial.print("\tfrequency: "); Serial.println(2e6/diff);
- }
- ISR(TIMER1_CAPT_vect) {
- captureTimePrev = captureTime;
- unsigned short *inputCaptureRegister1;
- inputCaptureRegister1 = (unsigned short *) 0x86;
- captureTime = *inputCaptureRegister1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement