How to know system freq (solved)

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

hi everyone.
First i apologize about my english, i know it's not the best :D
I'm trying to do a RTC using my arduino board and the AVRStudio, and with an external programmer.
The board have a 16MHz crystal osc and I've set the SUT_CKSEL fuses register in "osc crystal 8MHz - " with 16CK + 4.1ms, and selected de CKDIV8 bit (selected means unprogrammed, am I wrong?). Doing that i suppose i have a System freq equal to 16MHz.
After that I use de CTC mode and obtain the OCR1A value like this:

OCR1A=((Sys Freq/Pre)/Target freq)-1
OCR1A=((16000000/1024)/1)-1=15624

Well, when I do everything and try to run the program my led doesn't blink each second, it make it about 2 or 3 seconds.

I think that de formula I'm using it's not wrong, then the problem it's that I don't know the system freq.

Thanks

Sorry about my english one more time

Last Edited: Wed. Nov 3, 2010 - 02:51 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Why on earth did you change the fuses? - the Arduino is delivered with fuses already set to allow it to run at 16MHz from the crystal.

Anyway avrcalc says that for 16MHz with /1024 prescaler the CTC value to use in OCR1A is 0x3D08 which is 15,624. So the number you are using looks right if F_CPU really is 16MHz

Remember of course that if you toggle an LED in the compare interrupt that the actual frequency will be half the timer rate because on the first interrupt it switches on and on the second it switches off. So if you want a 1Hz blink you need to run the CTC at 2Hz so set OCR1A to 7811 insead.

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

Your English is very good.

You never need to use an external programmer. The Arduino comes with a bootloader.
The external programmer will destroy the bootloader.
Just remember to program the bootloader back again (via the Arduino IDE).

You should NOT have a tick for CKDIV8 fuse.
Report back with the values of your Fuses.
i.e. READ the fuses.

Yes. Your formula is correct. (if you have no prescaler)

Personally, I just use the bootloader with my Arduino.

David.

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

I use an external programmer because I don't really like the Arduino IDE. I've set the fuses register because I thought that destroying the arduino's bootloader the fuses would be reset.
What I have to do to set the cpu to 16MHz? I've been made i wrong?

Thanks for your answers

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

Quote:

I use an external programmer because I don't really like the Arduino IDE.

But you can continue to use the Arduino's bootloader without bothering with the IDE. Just build your .hex with your favourite toolchain then use avrdude to program it via the bootloader. Even if you do use ISP there's no need to change anything but the BOOTRST fuse so the AVR boots at 0x0000 rather than the BLS.
Quote:

to make the led on for half a second and off for another second (period = 1 second), you will need to divide the calculated value by 2.

Is there an echo echo echo echo.. in here?

EDIT: BTW /arduino/hardware/boards.txt lists the default fuses as:

diecimila.bootloader.low_fuses=0xff
diecimila.bootloader.high_fuses=0xdd
diecimila.bootloader.extended_fuses=0x00

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

I'm sorry clawson, but I don't understand well how to do it...

Quote:

EDIT: BTW /arduino/hardware/boards.txt lists the default fuses as:

diecimila.bootloader.low_fuses=0xff
diecimila.bootloader.high_fuses=0xdd
diecimila.bootloader.extended_fuses=0x00 

All the same I would like to know how to configure my Atmega328P to work at 16MHz with the AVRStudio and my external programmer

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

I was simply saying that if you want to put the Arudino back to the way it was when you got it you set the low fuse to 0xFF, the high fuse to 0xDD and the extended fuse to 0x00.

However if you don't plan to put the Arduino bootloader back in the one thing you will want to change is the BOOTRST fuse setting so that means changing that extended vale to 0x01 rather than 0x00

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

clawson wrote:
Is there an echo echo echo echo.. in here?
No. No. No.
Is there an echo-o-o in here-here-here?

Iluvatar is the better part of Valar.

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

Ok.
Thank you very much!

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

Hi!
Like clawson said to me, I've tried to reset de fuses regysties to their default values

diecimila.bootloader.low_fuses=0xff 
diecimila.bootloader.high_fuses=0xdd 
diecimila.bootloader.extended_fuses=0x00 

I've modified correctly the low and high fuses but I couldn't modify the extended fuses. The compiler return a "verify error" and then the value of the extended fuse go to 0xFE or 0xFD or 0xFF. I've tried many times but I couldn't...

I've tried to burn the arduino bootloader too, but I couldn't. The arduino compiler return a "sync error".

Sorry about the big mistakes I'm doing and thanks to everyone for the help.

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

Quote:

The compiler return

Why would the compiler be involved in fuse setting? Did you mean your ISP programming software?

Do note that in the 168 datasheet that the top 5 bits of the extended fuse are shown as "not used" and with value 1 not 0. So maybe try 0xF8/0F9 rather than 0x00/0x01

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

Sorry!!!
You're right, I mean the programming software. Like I said before my english is very poor :D

I've been able set the extended fuse to 0xf8, but when I try to burn the bootloader using Arduino IDE to my 328P I've got this error message:

avrdude: stk500_getsync(): not in sync: resp=0x00
avrdude: stk500_disable(): protocol error, expect=0x14, resp=0x51 

Can I burn the bootloader with the programming software? I mean, if I have the .hex file of the bootloader, I could do it, could I?

thanks for your answer.

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

You should be able to - the sync error is because ISP really just uses SPI and when a 4 byte ISP command sequence is sent to a device the programmer expects to see the bytes it sent echoed back 1 byte later (for some commands). If this doesn't happen it reports "not in sync". So it's probably a noisy clock signal or something like that.

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

finally I could fix the problem
Thanks to everyone!! :D