Arduino Input Capture - Page 1
Forum section: electronics / general

author: metrologist
author_rank: Super Contributor
timestamp: August 09, 2017, 08:07:56 pm
content: I'm hoping someone can help me understand this code and later apply it to a project using Arduino clocked with a 10MHz reference (would need serial comm).https://gist.github.com/billroy/4032657When I insert a 1pps signal to the input, I get this data on the serial monitor:timing...0:4096437 01:15583074 02:409407 03:15583071 04:409408 05:15583070 06:409407 07:15583070 08:409407 09:15583072 010:409407 0...I suspect that the first line is not valid, but 15583074 might be the number of CPU cycles since the previous input edge. Not sure about the trailing 0?I do not know what the even lines are?Then I insert a 15kHz signal and see:timing...0:237 600431:799 600922:800 601413:799 601904:801 602395:798 602886:801 603377:799 603878:800 604359:799 6048510:801 60535...If my above wag is correct, I would expect to see 1600 cycles, but I see half. There is a note in the code about rising/falling edge, so maybe I am seeing the cycles between these edges? Then the trailing number, it increments a somewhat consistent 50 counts for each line.I'm going to try to make a GPSDO and use long averaging techniques to slowly steer a highly stable OCXO. I wanted serial so I could communicate with the PC. I have not worked it all out yet. I might also want to parse NMEA from the GPS and pass that to the PC as well. Serial won't work with the 10MHz reference, and I probably will not be able to use the Arduino IDE as is either, but I think it can be done. (I've already written some code to parse NMEA and may need to do something for TSIP as well, if I do not find all the hard work's already been done)Thanks for any help.

author: westfw
author_rank: Super Contributor
timestamp: August 10, 2017, 09:33:44 am
content: I suspect you have separate lines for HIGH and LOW.In your 1pps example, it looks like your don't have anything even close to a square wave, but the SUM of two consecutive lines is very close to the expected 16,000,000 count.The 15kHz signal looks closer to a square wave, but the sum is about the 1600 you were expecting.The second number is the "lost event count"; that probably means that printing isn't keeping up with the events.

author: MatthewEveritt
author_rank: Unknown
timestamp: August 10, 2017, 09:49:43 am
content: TIMER1_CAPT_vect is switching between rising and falling edges (lines 94 and 95), so you are indeed seeing two events per cycle. Pretty much all PPS signals are exactly that, one shortpulseper second, not a 1Hz square wave, which is why you're seeing a large and a small value. If you just want the period comment out lines 94 and 95.

author: metrologist
author_rank: Super Contributor
timestamp: August 10, 2017, 03:47:43 pm
content: Thanks for that. I was reading the code again and now see some more commenting that I missed the first pass.To connect an external 10Mhz clock, do I just connect to clk1 pin and leave clk2 floating?Then to upload from the Arduino IDE, could I just create my own board:##############################################################atmega328.name=Arduino Duemilanove w/ ATmega32810Matmega328.upload.protocol=arduinoatmega328.upload.maximum_size=30720atmega328.upload.speed=36000atmega328.bootloader.low_fuses=0xFFatmega328.bootloader.high_fuses=0xDAatmega328.bootloader.extended_fuses=0x05atmega328.bootloader.path=atmegaatmega328.bootloader.file=ATmegaBOOT_168_atmega328.hexatmega328.bootloader.unlock_bits=0x3Fatmega328.bootloader.lock_bits=0x0Fatmega328.build.mcu=atmega328patmega328.build.f_cpu=10000000Latmega328.build.core=arduinoatmega328.build.variant=standard##############################################################Would the code still run and communicate if I used something like putty to set the off baud rate?This might get more complicated as I either want to use PWM out or i2c to control a dac.

author: techloveguy
author_rank: Newbie
timestamp: August 12, 2017, 02:50:56 pm
content: Hi, Pin 2 is connected to the pps output of a gps. I am trying to get input capture working but fails. I have followed the "Timer interrupts on Due" thread and read the data sheet and some but not all relevant source code in the arduino 1.5 package. I have verified that I can read the pulse using digitalRead() so I know the pulse is there and the Due can measure it - am using thisAdruino box. I just cant get the input capture to work.