Low Cost PCB's Low Cost Components

Author Topic: Arduino Input Capture  (Read 440 times)

0 Members and 1 Guest are viewing this topic.

Offline metrologist

  • Frequent Contributor
  • **
  • Posts: 760
  • Country: us
Arduino Input Capture
« on: August 10, 2017, 06:07:56 AM »
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/4032657

When I insert a 1pps signal to the input, I get this data on the serial monitor:

timing...
0:4096437 0
1:15583074 0
2:409407 0
3:15583071 0
4:409408 0
5:15583070 0
6:409407 0
7:15583070 0
8:409407 0
9:15583072 0
10: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 60043
1:799 60092
2:800 60141
3:799 60190
4:801 60239
5:798 60288
6:801 60337
7:799 60387
8:800 60435
9:799 60485
10: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 :D)

Thanks for any help.
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 2301
  • Country: us
Re: Arduino Input Capture
« Reply #1 on: August 10, 2017, 07:33:44 PM »
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.
 

Online MatthewEveritt

  • Supporter
  • ****
  • Posts: 127
  • Country: gb
Re: Arduino Input Capture
« Reply #2 on: August 10, 2017, 07:49:43 PM »
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 short pulse per 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.
 

Offline metrologist

  • Frequent Contributor
  • **
  • Posts: 760
  • Country: us
Re: Arduino Input Capture
« Reply #3 on: August 11, 2017, 01:47:43 AM »
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/ ATmega328 10M

atmega328.upload.protocol=arduino
atmega328.upload.maximum_size=30720
atmega328.upload.speed=36000

atmega328.bootloader.low_fuses=0xFF
atmega328.bootloader.high_fuses=0xDA
atmega328.bootloader.extended_fuses=0x05
atmega328.bootloader.path=atmega
atmega328.bootloader.file=ATmegaBOOT_168_atmega328.hex
atmega328.bootloader.unlock_bits=0x3F
atmega328.bootloader.lock_bits=0x0F

atmega328.build.mcu=atmega328p
atmega328.build.f_cpu=10000000L
atmega328.build.core=arduino
atmega328.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.
« Last Edit: August 11, 2017, 01:52:36 AM by metrologist »
 

Offline techloveguy

  • Newbie
  • Posts: 1
  • Country: hk
Re: Arduino Input Capture
« Reply #4 on: August 13, 2017, 12:50:56 AM »
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 this Adruino box. I just cant get the input capture to work.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf