Go Down

Topic: Atmel 328P lowering clock speed to 8 MHz (Read 1 time) previous topic - next topic

Nolebrain

Hello Gents,

I built my own PC board using the Atmel 328 P chip and successfully used Arduino as ICSP to upload the bootloader. Although, now my problem is that my board has a 8 MHz crystal oscillator and the chip runs at 16 MHz. I know a simple solution would be to replace the oscillator, but being a SMT chip this would be difficult. So can anyone tell me what I need to adjust to do this in software? I have read that it should be a text file where I can divide the number in half. My program does not use any timing functions, but in case I need to in the future is there a library that will correct the timing? Is this the Prescaler header library? Sorry I know these questions are fundamental, but I am eager to test my prototype.

The reduction in clock speed was done in order to reduce power consumption, as my device just spits out A/D values. Any help is greatly appreciated!!

Nolebrain

Update 1: with the standard bootloader upload complete, I've tried to program my chip but it says "avrdude: stk500_getsync(): not in sync: resp=0x00".

Update 2: I went into:  arduino version\hardware\arduino\avr\boards and created a new board type, adjusted the devicename.build.f_cpu=4000000L.

Then I restarted the IDE, attempted to re-upload the bootloader with the new board type but received more out of sync errors from avrdude. I must not be following the correct procedure here. Does anyone know what I am missing?

Will pay for anyone willing to walk me through this!

Jack Christensen


...my board has a 8 MHz crystal oscillator and the chip runs at 16 MHz.


Well, no. If the crystal is 8MHz, then the chip runs at 8MHz. Here is an 8MHz version of Optiboot that may help, and also an accompanying entry for boards.txt.
MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

Nolebrain

Jack,

Thanks for the quick reply!! I am going to copy the text into the my boards file for the pro328. I downloaded the hex file for optiboot as well. Do I just create a new bootloader of that name? It looks like the boards.txt file directs to it (pro328.bootloader.file=optiboot_atmega328_pro_8MHz.hex).



smeezekitty

There is a good chance you have the fuses misprogrammed
Avoid throwing electronics out as you or someone else might need them for parts or use.
Solid state rectifiers are the only REAL rectifiers.
Resistors for LEDS!

Jack Christensen


Jack,

Thanks for the quick reply!! I am going to copy the text into the my boards file for the pro328. I downloaded the hex file for optiboot as well. Do I just create a new bootloader of that name? It looks like the boards.txt file directs to it (pro328.bootloader.file=optiboot_atmega328_pro_8MHz.hex).


Yes. In my case, it's in the folder: \arduino\arduino-1.0.5\hardware\arduino\bootloaders\optiboot
MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

pico

Also, you can set the fuses so that you can run the 328p clocked at approx. 8.0MHz using the internal rc oscillator, obviating the need for an external xtal entirely.

Although you can further calibrate the internal rc ocillator, clock frequency will be more sensitive to temperature variation than if using an external xtal. However, if high level of clock accuracy is not of particular concern to your application, can be a useful way to simplify your design.

WiFi shields/Yun too expensive? Embeddedcoolness.com is now selling the RFXduino nRF24L01+ <-> TCP/IP Linux gateway: Simpler, more affordable, and even more powerful wireless Internet connectivity for *all* your Arduino projects! (nRF24L01+ shield and dev board kits available too.)

dc42

For designs I move off the Arduino on to PCB or stripboard, I don't bother with the bootloader. Instead I upload the program via ICSP. This also frees up the serial port pins on the atmega328p.
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Nolebrain

Alright, after some sleep I am back at it!

I copied Jack's text into my boards.txt file and extracted the .hex file into my optiboot folder.
I am using the example sketch Arduino ISP to upload the bootloader on my Atmel 328P through SPI.
Once I have the sketch on my Uno I am switching boards to the pro328 in order to upload the 8 MHz version.
At which I attempt to burn bootloader and receive this error:

Code: [Select]
processing.app.debug.RunnerException
at processing.app.debug.BasicUploader.burnBootloader(BasicUploader.java:288)
at processing.app.Editor$47.run(Editor.java:2509)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)


I believe my procedure is correct, what could be the problem here?

Also, interesting comment about the internal oscillator! I looked at the fuse calculator for the 328P at 8 MHz, according to http://www.engbedded.com/fusecalc/
The fuse values for the 328P are -U lfuse:w:0x62:m -U hfuse:w:0xd9:m -U efuse:w:0xff:m.

Is there any other adjustments besides changing these in the boards.txt file? If possible I would like to use the external oscillator in the event I want to run at 4 MHz.

Huge help so far guys!

Nolebrain

Ok guys, no luck sorting out those errors with Jack's pro328 bootloader.

I went back to different board (listed below) and successfully bootloaded to my board, but upon attempting to load a program on my board I receive:
Code: [Select]
avrdude: stk500_getsync(): not in sync: resp=0x00

Here is my board config that I am currently using:
Code: [Select]
pcb.name=PCB
pcb.upload.tool=avrdude
pcb.upload.protocol=arduino
pcb.upload.maximum_size=32256
pcb.upload.speed=9600

pcb.bootloader.tool=avrdude
pcb.bootloader.low_fuses=0xFF
pcb.bootloader.high_fuses=0xDA
pcb.bootloader.extended_fuses=0x05
pcb.bootloader.unlock_bits=0x3F
pcb.bootloader.lock_bits=0x0F
pcb.bootloader.file=optiboot/optiboot_atmega328.hex

pcb.build.mcu=atmega328p
pcb.build.f_cpu=8000000L
pcb.build.core=arduino
pcb.build.variant=standard


I am certain my fuses are not correct, although the bootloader would not let me upload with the fuses set to Low: 0x62 High: 0xD9 Ex: 0xFF
Can anyone help me understand why this is not working correctly? The fuses are set for the default 328P configuration.


dc42

The standard fuse settings should be fine even if you are using a 8MHz crystal instead of 16MHz.

Did you burn the optiboot built for 8MHz clock speed? If not and you are using the standard 16MHz optiboot instead, then in order to upload a sketch to your board, you will need to change your board config file entry (or create a new one) that says to use half the normal baud rate.

But as I said before, for standalone boards, it is easiest to forget the bootloader and upload the sketch via ICSP instead.
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Nolebrain

Ok good idea! Here is my setup, I have an Arduino Uno R3 connected to my board via SPI (MISO,MOSI,SCK,RESET,PWR,GND). How does one directly upload code via ICSP? I'm guessing I load my program on the Uno first, but how do you initiate a transfer to the standalone chip? Sorry first time, trying to learn as much as a I can!


dc42


Ok good idea! Here is my setup, I have an Arduino Uno R3 connected to my board via SPI (MISO,MOSI,SCK,RESET,PWR,GND).


1. Wire up your standalone board to your Arduino (running ArduinoISP) and configure the IDE exactly as you would for burning the bootloader.

2. Use the "Upload using programmer" menu option instead of the "Upload" option. Alternatively, hold down the shift key while pressing the Upload tool button.
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Jack Christensen


Here is my board config that I am currently using:
Code: [Select]
pcb.upload.speed=9600


The 8MHz bootloader uses an upload speed of 57600. Here is the boards.txt entry that I am currently using with 1.0.5:

Code: [Select]
uno8.name=Arduino "Uno" @ 8MHz
uno8.upload.protocol=arduino
uno8.upload.maximum_size=32256
uno8.upload.speed=57600
uno8.bootloader.low_fuses=0xff
uno8.bootloader.high_fuses=0xde
uno8.bootloader.extended_fuses=0x05
uno8.bootloader.path=optiboot
uno8.bootloader.file=optiboot_atmega328_pro_8MHz.hex
uno8.bootloader.unlock_bits=0x3F
uno8.bootloader.lock_bits=0x0F
uno8.build.mcu=atmega328p
uno8.build.f_cpu=8000000L
uno8.build.core=arduino
uno8.build.variant=standard


Quote

I am certain my fuses are not correct, although the bootloader would not let me upload with the fuses set to Low: 0x62 High: 0xD9 Ex: 0xFF. Can anyone help me understand why this is not working correctly? The fuses are set for the default 328P configuration.


The five most significant bits of the extended fuse byte are unused. A person would think from the datasheet that the default setting would equate to 0xFF but in fact this causes an error. For the factory setting, use:

Code: [Select]
whatever.bootloader.low_fuses=0x62
whatever.bootloader.high_fuses=0xD9
whatever.bootloader.extended_fuses=0x07
MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

Go Up