Time Delay question
Moderator: Benj
-
- Posts: 159
- Joined: Thu Jul 01, 2010 1:57 am
- Has thanked: 23 times
- Been thanked: 16 times
- Contact:
Time Delay question
I have noticed that when I use a time delay in a program, that I need to double the seconds to get the correct time delay. On the attached example, when I check pin D2 with a voltmeter, it is 5 volts for appx 5 seconds instead of 10. This is a good learning opportunity for me. What's up?
- Attachments
-
- TimeDelayQuestion.fcfx
- (3.35 KiB) Downloaded 244 times
-
- Valued Contributor
- Posts: 2045
- Joined: Wed Aug 27, 2008 10:31 pm
- Location: Netherlands
- Has thanked: 553 times
- Been thanked: 1081 times
- Contact:
Re: Time Delay question
What is the frequency of the crystal connected to the controller?
“Integrity is doing the right thing, even when no one is watching.”
― C.S. Lewis
― C.S. Lewis
-
- Posts: 159
- Joined: Thu Jul 01, 2010 1:57 am
- Has thanked: 23 times
- Been thanked: 16 times
- Contact:
Re: Time Delay question
Good question. I am using an Arduino Uno Clone. I only know that it has a 16 mega Hz crystal.
-
- Valued Contributor
- Posts: 2045
- Joined: Wed Aug 27, 2008 10:31 pm
- Location: Netherlands
- Has thanked: 553 times
- Been thanked: 1081 times
- Contact:
Re: Time Delay question
The project properties are set for an 8 MHz crystal. You need to open 'Build'->'Project Options' and change the clock speed to 16000000.
“Integrity is doing the right thing, even when no one is watching.”
― C.S. Lewis
― C.S. Lewis
-
- Posts: 159
- Joined: Thu Jul 01, 2010 1:57 am
- Has thanked: 23 times
- Been thanked: 16 times
- Contact:
Re: Time Delay question
dang. Thanks, I learned something. I have much larger programs that have this setting at 8 Mega Hz. I wonder if changing to 16,000,000 Hz will effect anything else other than the time delay's.
-
- Posts: 159
- Joined: Thu Jul 01, 2010 1:57 am
- Has thanked: 23 times
- Been thanked: 16 times
- Contact:
Re: Time Delay question
I note that when I start a new project, that for the Atmega 328p, the default is 8 Mega Hz. Is it set at this HZ for a reason?
-
- Valued Contributor
- Posts: 2045
- Joined: Wed Aug 27, 2008 10:31 pm
- Location: Netherlands
- Has thanked: 553 times
- Been thanked: 1081 times
- Contact:
Re: Time Delay question
This setting is used to calculate all kinds of timing related parameters like serial port baud rate settings. It is fairly important to set it to the right value. (General advice: check clock settings with the 1 second flasher when starting with new hardware)
If you are using a Uno clone, why not choose one of the Uno variants from the available targets? I just checked one of them (at random) and the clock is set to 16MHz.
As to why the default is 8MHz? Why not 16MHz or 4MHz? Matrix has no way of knowing the target hardware so a 'random' default has been chosen with the responsibility for the user to set it to the correct value. Just like the configuration options need to be set correctly when using a controller. For the Arduino boards among the targets these settings are known and are set to the correct values.
If you are using a Uno clone, why not choose one of the Uno variants from the available targets? I just checked one of them (at random) and the clock is set to 16MHz.
As to why the default is 8MHz? Why not 16MHz or 4MHz? Matrix has no way of knowing the target hardware so a 'random' default has been chosen with the responsibility for the user to set it to the correct value. Just like the configuration options need to be set correctly when using a controller. For the Arduino boards among the targets these settings are known and are set to the correct values.
“Integrity is doing the right thing, even when no one is watching.”
― C.S. Lewis
― C.S. Lewis