I am very uncertain how Timer1 functions. I have some sample code here that controls LPD6803 led chipset. According to the datasheet, the clock expects a 20Mhz square wave. I'm not sure how that relate to this code, can someone please help me understand?
void LPD6803::setCPUmax(uint8_t m) {
cpumax = m;
// each clock out takes 20 microseconds max
long time = 100;
time *= 20; // 20 microseconds per
time /= m; // how long between timers
Timer1.initialize(time);
}
The documentation says to set cpumax to between 50 - 100.
I realize that. That's why I'm confused. I didn't write this code, I found it. When comparing it with the data sheet, I don't understand what it's achieving, although it does seem to work.
And that datasheet says 24MHz and 25MHz max clock frequency anyway, not 20MHz. Its poorly
translated and not even consistent about the value, so I would treat everything in it with a pinch
of salt. Go get a library to drive it - it can probably be driven best with the SPI hardware which
can push out bytes at 8Mhz - failing that bit-banging, but I wouldn't use a timer to drive it, it will
just clock continously, the point is the serial data has to be ready too.
So I think I am understanding this better. I'm still a little hazy on the relationship between µs and Mhz, but from what I can glean, a single µs is the cycle time for 1Mhz. Therefore interrupting the timer every one µs gives us a 1 Mhz waveform. Is that correct? If so, then the 20µs used in the example above gives us a 20Mhz waveform. That's the intended purpose. Is that correct?
Lazy is what I would be if I used any of the search results from that search. The first 5 pages are all calculators, and while its nice to have a tool to do the work for me, it's nicer if I can figure out what the actual relationship is and calculate it myself.
But thanks to some helpful people on this forum who did set me on the right track with helpful information. I have deduced that period and frequency have an inverse relationship.
richbai90:
But thanks to some helpful people on this forum who did set me on the right track with helpful information. I have deduced that period and frequency have an inverse relationship.
That's right. So a 16 MHz clock frequency is a 62.5 ns period.
"I have deduced that period and frequency have an inverse relationship."
Yup, basic science in action there. Period = 1/Frequency.
electronics, light, water waves, sound.
Something interesting I've noticed that I'm investigating, that perhaps one of you might know the answer to. In every number, I plug into that calculation since it gives me the period in seconds for a given frequency, ends up being (1/x * 100)e-y
I understand (1/x * 100), what my fascination is with, is the occurrence of Euler's constant, a number I am only vaguely familiar with from my math 1050 class in problems dealing with exponential growth and decay. What is the relationship between e and your waveform?
I'm sure I can figure it out eventually though enough google searches but if you know, I'm just intrigued by it.
I plug into that calculation since it gives me the period in seconds for a given frequency
What? Which calculation?
ends up being (1/x * 100)e-y
What is x? What is y? Can you provide an example? Are you sure you're not just playing with exponential identities of some kind?
There is a bunch of math connecting periodic waveforms with exponential functions, but you have to throw complex numbers into the game: Phasor - Wikipedia