Hi.
I need the Arduino to do a math operation every tenth of a second exactly.
I've thought about interfacing with RTCs, but none of the MAXIM models seems to meet my needs (100Hz output attached on an Arduino interrupt input).
Any help?
Thanks.
Hi.
I need the Arduino to do a math operation every tenth of a second exactly.
I've thought about interfacing with RTCs, but none of the MAXIM models seems to meet my needs (100Hz output attached on an Arduino interrupt input).
Any help?
Thanks.
Caracola:
I need the Arduino to do a math operation every tenth of a second exactly.
What exactly do you mean by "exactly" in this context? In other words, what is the acceptable tolerance on the interval of one tenth of a second?
You can use a rtc (to count the 32khz output for example) but that only makes your life unnecessarily difficult.
dc42:
What exactly do you mean by "exactly" in this context? In other words, what is the acceptable tolerance on the interval of one tenth of a second?
It'll be long to explain in detail. I just want to make a clock with a precision of tenths, not seconds. And every tenth (or so, at least a couple every second) do a math operation.
And after the math operation is done, change outputs acording to the result.
You haven't answered my question. You can easily make a clock with a precision of tenths of a second; but how accurate do you need it to be? If you set it to the correct time and then come back a day later, how many seconds out from the correct time is it allowed to be? If you want to change the output every ten0.1 second, does it matter of the interval is actually 0.101 second, or 0.999 second? How about 0.11 second or 0.99 second?
Caracola:
dc42:
What exactly do you mean by "exactly" in this context? In other words, what is the acceptable tolerance on the interval of one tenth of a second?It'll be long to explain in detail. I just want to make a clock with a precision of tenths, not seconds. And every tenth (or so, at least a couple every second) do a math operation.
And after the math operation is done, change outputs acording to the result.
Well if you just want to perform a task at a fast but periodic rate use the MSTimer2 library and set it to interrupt every 100msec, and perform your task in the ISR. You may have to adjust the 100 variable to some value +/- to account for your specific processor crystal accuracy but I'm sure you can work that out.
http://playground.arduino.cc//Main/MsTimer2
Lefty
You can simply count the main oscillator to (F_CPU / 1000ul / 100) -> that will produce an interval of 100ms.
The Maxim RTCs have a 1 KHz square wave output. Use that as an interrupt, and every 10 interrupts do you 1/10th of a second action.
dc42:
You haven't answered my question. You can easily make a clock with a precision of tenths of a second; but how accurate do you need it to be? If you set it to the correct time and then come back a day later, how many seconds out from the correct time is it allowed to be? If you want to change the output every ten0.1 second, does it matter of the interval is actually 0.101 second, or 0.999 second? How about 0.11 second or 0.99 second?
It must be as accurate as possible. In 8 hours it shouldn't loose a tenth.
The result of the math operation, must match with the same operation made by a "master" device with it's own clock (and this is a proven highly accurate one). I'm given the time of the master clock in tenths, that's why I need that sort of precision.
retrolefty:
Well if you just want to perform a task at a fast but periodic rate use the MSTimer2 library and set it to interrupt every 100msec, and perform your task in the ISR. You may have to adjust the 100 variable to some value +/- to account for your specific processor crystal accuracy but I'm sure you can work that out.Lefty
dhenry:
You can simply count the main oscillator to (F_CPU / 1000ul / 100) -> that will produce an interval of 100ms.
CrossRoads:
The Maxim RTCs have a 1 KHz square wave output. Use that as an interrupt, and every 10 interrupts do you 1/10th of a second action.
Thanks a lot for your answers, but the Arduino will also have an encoder with interrupt and a led driver (ICM7218, to display the time) plus the I2C LCD display (20x4 characters, to display the encoder reading and other options), so it could be too much job to do in very little time. That's why I wanted to have a full external 100Hz signal.
So take the Maxim 1 KHz output, add a /10 chip, and there you go, a 100 Hz signal.
If you have a RTC with a 1Hz output, you can generate an interrupt from that, then count microseconds from that interrupt. So the long-term accuracy will determined by the RTC, and you will only be relying on the less accurate Arduino clock to count for up to one second.
so it could be too much job to do in very little time.
Hardly.
Can you able explain your project, What u wanna achieve
CrossRoads:
So take the Maxim 1 KHz output, add a /10 chip, and there you go, a 100 Hz signal.
dc42:
If you have a RTC with a 1Hz output, you can generate an interrupt from that, then count microseconds from that interrupt. So the long-term accuracy will determined by the RTC, and you will only be relying on the less accurate Arduino clock to count for up to one second.
That's a solution to have a interrupt every selected time.
Furthermore, if I use a DS1388 (the only I2C chip with more precision than seconds), where I can find a 6.0pF crystal? Sparkfun only offers 12.5pF model.
AMPS-N:
Can you able explain your project, What u wanna achieve
I'm in regularity rallying. The organisation tells me where I'm supposed to be at any time (giving me the average speed of each section). With the encoder I know where I am, and with the RTC I know when I am. So with a simple math operation I know if I'm in my ideal point.
The organisation provides me the time in tenths, and to be accurate that's the unit to work with. But I only need to know if I'm in the ideal point once or twice a second.
Thanks for your patience.
Caracola:
dc42:
If you have a RTC with a 1Hz output, you can generate an interrupt from that, then count microseconds from that interrupt. So the long-term accuracy will determined by the RTC, and you will only be relying on the less accurate Arduino clock to count for up to one second.That's a solution to have a interrupt every selected time.
Don't try to do too much in interrupts. If you do really want an interrupt every 0.1 seconds, you can use timer 1 to generate a regular 10Hz tick interrupt, and use the RTC to adjust the TOP value in timer 1 to keep the Arduino clock in step with the RTC.
Caracola:
Furthermore, if I use a DS1388 (the only I2C chip with more precision than seconds), where I can find a 6.0pF crystal? Sparkfun only offers 12.5pF model.
Try the major component distributors, or use two pieces of insulated solid core wire about 20mm long twisted together. But that chip already provides 6pF load capacitance for the crystal internally.
And if you really want 6pF, two 12 pFs in series = 6 pF.
where I can find a 6.0pF crystal?
That's the most popular crystal for production now, as the loading capacitance is very close to a pin's input capacitance.
Caracola:
It must be as accurate as possible.
Still not an answer, unless the intent is to use cesium fountain clocks or whatever the current state of the art is.
In 8 hours it shouldn't lose a tenth.
A better answer. If I did the maths right this is about 3.5ppm, which will be beyond the ability of typical 20-30ppm crystals used to control MCUs and RTCs. A lot of folks use TXCO-based RTCs like the DS3231/DS3234, but the specs on these only just match the requirement, and I'd probably want to exceed that by at least an order of magnitude. I'm not sure what the next step in accuracy would be, maybe an OXCO or one of those surplus rubidium frequency standards.