| Author |
Message |
|
|
Posted: Jan 25, 2012 - 03:47 PM |
|

Joined: Dec 15, 2011
Posts: 93
|
|
i just also wrote the code exactly as you suggest in your last post:
Code:
#include <avr/io.h>
#define F_CPU 3681000ul
#include <util/delay.h>
and the result was to have no errors and no warnings and the T= round to 1sec (a little bit more than a sec i think)
.
so ? |
|
|
| |
|
|
|
|
|
Posted: Jan 25, 2012 - 04:25 PM |
|


Joined: Mar 27, 2002
Posts: 18760
Location: Lund, Sweden
|
|
Notice that my #define is different than your. Your STK-500 is generating a 3.681 MHz clock signal (You've read that out from the STK-500 settings yourself), and your STK-500 is set up to route this clock signal to the AVRs clock pin(can be seen in the photo). Your AVR is configured to use the clock on the clock pin rather than the internal clock (you read that out yourself when reading the AVR fuses).
The meaning of the #define is not to set the clock that the AVR is running at, but to inform avrlibc at what the actual CPU clock frequency is. If you lie to avrlibc it will generate wrong delays.
Make your define so:
Code:
#define F_CPU 3681000ul
Rebuild, reflash and rerun this. Your LEDs should be one second on, one second off. Report back here if this is the result or not.
Keep the focus! Don't do anything but what I told you now, OK? You might not think so, but we are making progress. |
|
|
| |
|
|
|
|
|
Posted: Jan 25, 2012 - 04:31 PM |
|


Joined: Jul 18, 2005
Posts: 62944
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
I'm not sure if I should derail things by mentioning this but that 3.681 is surely a rounding error? The clock is more accurately 3.6864 and the define should be:
Code:
#define F_CPU 3686400ul
|
_________________
|
| |
|
|
|
|
|
Posted: Jan 25, 2012 - 04:34 PM |
|

Joined: Dec 15, 2011
Posts: 93
|
|
my avr generates 3686400hz or 3,686Mhz i saw it in the HW settings page.
in the main page i saw also that the ISP clock is 5,927 KHZ
i did what you say but the difference between those 2 different values are so little that there is no difference in the eye of a human.
both values seem to me that is about 1sec=T. |
|
|
| |
|
|
|
|
|
Posted: Jan 25, 2012 - 07:20 PM |
|


Joined: Mar 27, 2002
Posts: 18760
Location: Lund, Sweden
|
|
|
Quote:
in the main page i saw also that the ISP clock is 5,927 KHZ
That governs the speed with which flash programming occurs. As long as you are able to program the flash of the AVR that is of no concern to us. Drop it.
Quote:
i did what you say but the difference between those 2 different values are so little that there is no difference in the eye of a human.
Re the F_CPU you wrote above
[quote]so i will right down the code ,as i wrote it to the program.
Quote:
i just also wrote the code exactly as you suggest in your last post:
Code:
#include <avr/io.h>
#define F_CPU 3681000ul
#include <util/delay.h>
and the result was to have no errors and no warnings and the T= round to 1sec (a little bit more than a sec i think)
Can we be absolutely clear about this: Do you by "T= round to 1sec" mean "one second on, one second off" or do you mean "a complete on-off cycle takes one second"?
If it is "one second on, one second off" then we now have control over the CPU frequency. It is the one generated by the STK-500, and since you've stated that when you've read it out of the STK-500 it was set to 3681000hz then your define should be
Code:
#define F_CPU 3681000ul
and you can return to your original project (the solar tracker) and do the same define there.
(If it actually reads out as something else then we need to know exactly what it reads out as.)
If the blinking is actually "a complete on-off cycle takes one second" then we need to continue working with the small blinky program until we get control of this. Nothing else makes any sense until we get that right. |
|
|
| |
|
|
|
|
|
Posted: Jan 25, 2012 - 09:21 PM |
|

Joined: Dec 15, 2011
Posts: 93
|
|
i just measure it with a the clock of my mobile phone and i discover that is exactly one second lights on and one second lights off which means that the T(period)=2sec
so as you say we have under control the cpu frequency of the stk500.
but can you please let the solar tracker aside for a little time and continue with the game program?
i want to know why doesnt work in my stk what is the problem please tell me.
now that i started with avr i am going to do a lot of projects so as to get knowledge on that.
i want and am going to do the solar tracker and other projects but please tell me for the game too because its a very cheap project and easy to create. |
|
|
| |
|
|
|
|
|
Posted: Jan 25, 2012 - 09:36 PM |
|


Joined: May 04, 2007
Posts: 3529
Location: Geelong Australia, Home of the "Cats"
|
|
|
Quote:
now that i started with avr i am going to do a lot of projects so as to get knowledge on that.
Excellent! But start with smaller do-able exercises/steps and do things right.
As Johan has said, you must get 0.5 Sec ON & 0.5 sec OFF. At present you are not fully in control yet!
As I suggested before "always have a flashing LED in your main loop as a heart beat. You should probably not do it with
delays as you have just done with Blinky, but with say a 10ms. tick timer system and then you toggle the LED every 500 ticks.
That should be your next project! We can show you how!
After that, you can integrate the heartbeat into your "game".
If you are serious, you should get a simple logic probe to help you, it will do 99% of your hardware debugging. Oscilloscopes & logic analyzers are only required when the problem is really tough and the boss wants it fixed in the shortest time. The boss can also pay for those tools then!  |
_________________ Charles Darwin, Lord Kelvin & Murphy are always lurking about!
Lee -.-
(If you haven't already done so, edit your PostNuke profile and let let us know where you are, what you do & what your interests are.)
|
| |
|
|
|
|
|
Posted: Jan 25, 2012 - 10:14 PM |
|

Joined: Dec 15, 2011
Posts: 93
|
|
you are telling me that i have to put a timer in my program to count a tick every 10ms and then to change the lights from on to off and vise versa every 50tikcs or you are telling me to adjust the clock of the cpu so as a tick to take place every 10ms and so after 500ms = 10*50 to change the state from on to off and vise versa?
ok tell me how would i do the this, i am ready to do it following your orders.
but please just tell me why the game program is not functional with my avr stk500? |
|
|
| |
|
|
|
|
|
Posted: Jan 25, 2012 - 10:35 PM |
|

Joined: Dec 15, 2011
Posts: 93
|
|
i also want to ask that:
in case that i define the cpu speed at 3,686Mhz
and then in the program i ask a delay of 500ms for something wouldnt this delay take place for 0,5sec? |
|
|
| |
|
|
|
|
|
Posted: Jan 26, 2012 - 04:25 AM |
|


Joined: Mar 27, 2002
Posts: 18760
Location: Lund, Sweden
|
|
|
Quote:
in case that i define the cpu speed at 3,686Mhz
and then in the program i ask a delay of 500ms for something wouldnt this delay take place for 0,5sec?
Yes, but only if the AVR is actually running at 3.686 MHz.
Important, and repeated: The F_CPU define does not in any way affect at what frequency the AVR is actually running at. It is there to tell the compiler and avrlibc about the actual frequency so that correct delays can be generated. If the F_CPU define does not mirror the actual CPU frequency then the times of the delays will be wrong. |
|
|
| |
|
|
|
|
|
Posted: Jan 26, 2012 - 09:41 AM |
|


Joined: May 04, 2007
Posts: 3529
Location: Geelong Australia, Home of the "Cats"
|
|
|
Quote:
but please just tell me why the game program is not functional with my avr stk500?
I/we dont have any idea. But you nor being able to get a second period LED flash does not help. That must be fixed first!
Then we will show you how to implement a heartbeart using interrupts...in fact I will show you now.
Having the heartbeat working, we will work through the rest of the game, but we never want to hear again nothing works,
as there will ALWAYS BE A 1 SECOND HEARTBEAT.
Code:
#include <avr/interrupt.h>
volatile uint8_t tick;
uint_t heart_beat_timer=50;
//before the main loop you must code Timer2 for 10mS. CTC Timer Compare interupt. & enable global interrupt
TCCR2A=(1<<WGM21); //enable T2 compare match interrupt divide by 64
TCCR2B=(1<<CS22)|(1<<CS21)|(1<<CS20);
OCR2A=0x9b; //This is for 16 Mhz, you will need to change it
sei();
//in your main loop you will have the following
if(tick)
{
tick=0;
if(--heart_beat_timer)
{
heart_beat_timer=50;
LEDPORT^=(1<<LEDBIT);
}
}
ISR(TIMER2_COMPA_vect) //10 ms. interrupt to drive task handler
{
tick=1;
}
Thats all! No delays involved...almost magic! |
_________________ Charles Darwin, Lord Kelvin & Murphy are always lurking about!
Lee -.-
(If you haven't already done so, edit your PostNuke profile and let let us know where you are, what you do & what your interests are.)
|
| |
|
|
|
|
|
Posted: Jan 26, 2012 - 11:21 AM |
|


Joined: Mar 27, 2002
Posts: 18760
Location: Lund, Sweden
|
|
|
Lee wrote:
But you nor being able to get a second period LED flash does not help. That must be fixed first!
Please note that the code I sugested should behave thus: 1 second on, 1 scond off.
So to be nitpikingly correct, the period should be two seconds.
-----
stavfot!
I am still awaiting a definitive answer on what you saw. Was it "one second on, one second off"? Or was it "one second for a complete on-off cycle"?
Please don't post anything else here before answering that unambiguously! I will not even start to look at your game before I get to a definitive and final conclusion re you clock frequency etc. I have up to now invested several hours on that matter, and if we don't come to a final conclusion my time has been completely wasted. I hope you understand that I do not want that. I hope you respect that I do not want that. I hope you will act accordingly.
Personally I dont care at all if you are impatient and want other stuff to work. I just want return on my investment.
I am also of the opinion that trying to get the game to run before you have control over the CPU clock is like trying to walk before you can crawl. Or rather, like eating without having control of your bowels..
Ansers on the clock problem first, please! |
|
|
| |
|
|
|
|
|
Posted: Jan 26, 2012 - 11:32 AM |
|


Joined: May 04, 2007
Posts: 3529
Location: Geelong Australia, Home of the "Cats"
|
|
|
Quote:
So to be nitpikingly correct, the period should be two seconds.
Ah, OK, I did not look at the code.
In which case stavfot, implement the ISR driven Blinkey & when you have that working migrate
that to your game.
My investment in time is also, that you develop good debugging skills, as you can be assured you will always
be plagued with bugs, but Johan & I may not be around for ever. |
_________________ Charles Darwin, Lord Kelvin & Murphy are always lurking about!
Lee -.-
(If you haven't already done so, edit your PostNuke profile and let let us know where you are, what you do & what your interests are.)
|
| |
|
|
|
|
|
Posted: Jan 26, 2012 - 07:14 PM |
|

Joined: Dec 15, 2011
Posts: 93
|
|
mr johan
i answer straight clean as clean water!:
THE LIGHTS WERE FOR 1SECOND ON AND FOR 1 SECOND OFF! SO THE PERIOD OF THE WHOLE PHENOMENON WAS 2 SEC.
let go on if you dont mind please! |
|
|
| |
|
|
|
|
|
Posted: Jan 26, 2012 - 07:17 PM |
|


Joined: Sep 04, 2002
Posts: 21396
Location: Orlando Florida
|
|
| Now we need to change every timer setting that was calculated for the 20MHz 324 and recalculate the divisors for 3.684MHz. Also need to set project setting in avrstudio for 8515 rather than mega324. |
_________________ Imagecraft compiler user
|
| |
|
|
|
|
|
Posted: Jan 26, 2012 - 08:20 PM |
|

Joined: Dec 15, 2011
Posts: 93
|
|
how is this going to happen? could you be more specific?
i have already chosen from the menu of avr studio the atmega8515 micro processor . what else should i do?
how am i going to change those timer settings that you refer? |
|
|
| |
|
|
|
|
|
Posted: Jan 26, 2012 - 08:44 PM |
|


Joined: Mar 27, 2002
Posts: 18760
Location: Lund, Sweden
|
|
|
Quote:
i answer straight clean as clean water!:
THE LIGHTS WERE FOR 1SECOND ON AND FOR 1 SECOND OFF! SO THE PERIOD OF THE WHOLE PHENOMENON WAS 2 SEC.
While that is good news there is (still) no reason to scream.
Yes, that is good news. You now have control of what CPU frequency the AVR is running at, and you know what to define F_CPU to.
We can now move on.
 |
|
|
| |
|
|
|
|
|
Posted: Jan 26, 2012 - 08:51 PM |
|


Joined: Sep 04, 2002
Posts: 21396
Location: Orlando Florida
|
|
| I went back and looked at the game program, and seems like it should run now. I was looking for a delay that was based on the clock value (which is different than the original version) rather than a number of milliseconds. |
_________________ Imagecraft compiler user
|
| |
|
|
|
|
|
Posted: Jan 26, 2012 - 09:18 PM |
|

Joined: Dec 15, 2011
Posts: 93
|
|
unfortunately the game still does not run..
what might be the problem?
is the code to "heavy" for that cpu?
or what else could the problem be? |
|
|
| |
|
|
|
|
|
Posted: Jan 26, 2012 - 09:35 PM |
|


Joined: Mar 27, 2002
Posts: 18760
Location: Lund, Sweden
|
|
What did you learn from the "blinky" experience?
Cut the game program to pieces. Start with just a small part of it and make that work. Then, in small steps, add piece by piece making sure that every added piece works as it should.
If the game program is not formed so that it can be cut down, then it is a bad design. Start afresh.
If you are not able to do that, then you are reaching for a too complex program right now. Start with something simpler.
All professional programmers, and any good amateur, works in small steps. It will not be different for you. |
|
|
| |
|
|
|
|
|