F_CPU defining -simulating project for timer0 in normal mode

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello

I am working on a simulation project. It mean that I should only simulate this atmel project on proteus.

My project is a simple clock in timer 0- I have a atmega16 microcontroller and a character lcd.that resulte should me hour,minute,second howing on lcd.

I should use F_CPU once 2MHz and then 8MHz.

First I form my circuit in proteus then start to write my code in atmel studio by F_CPU=2 MHz . I calculate my register values in normal mode by N=256(cs00 and cs01). And I pressed   F7 and then I  ran it in proteus by double clicking on micro and choosing internal RC 2MHz and  by  use of its hex file. it worked well and correctly. Resulted Minute and hour and second was completely true and there was no error in code and simulation. And lcd showed correct and time was correct.

But when I change my F_CPU to 8MHz by typing  F_cpu=8000000 and changing my calculation it didnt worked.  I mean When I ran the simulating it didn’t worked. Lcd showed nothing or strange things showed. I choose micro frequency by double clicking on micro and choosing external 8MHz . but lcd shows strange things. I asked someone  my problem.he said it is because of defining F_cpu for external oscillator in atmel. He mean that for only internal oscillator we write #define F_CPU  2000000  and for external we should type another code  or define it by another way. I didn’t get his words.

Now  My question is that why when I change 2MHz internal to 8MHz  external (even internal) it doesn’t worked. My calculation is true. What I forget to do? What is wrong? How should I correct it.

Thank you

Aasshh

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Have you tried this on real hardware?

 

ie, is it an actual AVR problem - or a Proteus problem.

 

First obvious question is whether just changing F_CPU in your source code is sufficient to get Proteus working at that speed.

 

AIUI, Proteus has lots of tools & facilities for debugging both your code and your hardware - have you used them?

 

Proteus is a 3rd-party product totally unrelated to Microchip (or Atmel) -  For Proteus support, you need to go to LabCenter:

 

https://www.avrfreaks.net/commen...

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

This is clearly a school project, your teacher is there to help you with this, so you should be asking him/her your questions!

Good luck with your school work!

 

Jim

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You mean that my code in atmel is correct abd my problem is in proteus?? I dont know abour proteus debuging tools. So you think i dont have problem in my code and i should think about proteus settings or tools??

Aasshh

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Aashkanpasha wrote:
You mean that my code in atmel is correct abd my problem is in proteus??

No. I mean that you need to investigate to find out whether it is a "real" problem, or a Proteus issue.

 

In particular, you need to ensure that you are correctly configuring Proteus.

 

Or, as Jim said, go to your teachers for help.

 

I dont know abour proteus debuging tools.

Then you need to get to know them!

 

You said it's a "simulation project" - so you meed to know how to use your simulator!

 

What is the point in paying for a Proteus licence, and then not using its facilities?!

 

So you think i dont have problem in my code and i should think about proteus settings or tools??

See above

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...