Accessing Clock

Status
Not open for further replies.

jtmcknight

New member
I am attempting to interface with an ADC, specifically TI's ADS1224. I've been attempting to generate a consistent clock pulse, but have been unsuccessful. I tried using the tone() function, but when I view the clock with a logic analyzer the pulses are inconsistent. Also, I tried using analogWrite(pin,128) which gave me a clock signal, but at a frequency of only 500 Hz. Is there any way to access the clock or possibly assign it to a pin? I am using a Teensy 3.1.

This is the result of using the tone() function: clk.jpg

Edit: What I'm looking for is something similar to what you would get when using SPI on the SCK pin while the SPI.tranfer() function is executing.

Thanks!
Jake
 
Last edited:
If you're trying to generate a consistent clock, your best bet is to use the one of the libraries that wraps one of the HW timer blocks (FTM, PIT, etc).

One way you could approach this is to use analogWrite, but first to change the resolution down to 2-4 bits so that you can get higher PWM frequencies, and then change the analog write frequency to whatever you want the clock frequency to be. Check out the PWM Frequency and PWM Resolution sections of this page: http://pjrc.com/teensy/td_pulse.html

Another option would be to use the IntervalTimer library(http://pjrc.com/teensy/td_timing_IntervalTimer.html).

The easiest option to generate the clock is probably to use the analog write function with a different frequency/resolution so that the HW is doing all the clock generation without any extra software functionality (ISRs, etc). However, if you need to actually read or write data on the clock edges, it would be better to use the interval timer library, so that you can perform the additional tasks in the interval timer ISR.
 
Status
Not open for further replies.
Back
Top