Go Down

Topic: help with running seperate ATmega328P (Read 863 times) previous topic - next topic

1Proxy0

Nov 19, 2018, 05:40 pm Last Edit: Nov 19, 2018, 05:40 pm by 1Proxy0
I want to use a seperate ATmega328P for to replace some older interface chips (SD <-> 8-bit parallel, and PS/2 -> 8-bit parallel) so i tested if i could program it without having to have the Arduino boot loader on it

i used the Arduino IDE to write a small program that just blinks an LED (1sec on, 1sec off), exported the file as Binary and loaded that onto the chip with the TL866II Plus

Program:

Code: [Select]

void setup() {
  pinMode(8, OUTPUT);

}

void loop() {
  digitalWrite(8, HIGH);
  delay(1000);
  digitalWrite(8, LOW);
  delay(1000);

}


i then build the circuit exactly like this:

(sorry for bad quality)

Caps: 22 pF
Resistor: 1 kOhm
Crystal: 20 MHz (like it says on the site)


and once i powered it it worked... sort of

now here is the problem, the LED is on and off for around 15 seconds instead of the programmed 1 second.

did i do something wrong with the circuit? or the program? when using the binary files i used the one without bootloader, is that the problem or why is the chip so much more slower than it should be.

6v6gt

#1
Nov 19, 2018, 07:18 pm Last Edit: Nov 19, 2018, 07:28 pm by 6v6gt
You can't do much wrong with that program. It is so simple.
I guess you should look at the fuse settings on the chip. It looks like the standard is an effective 1 MHz clock rate and your program is expecting 16 (or maybe 20) times that.

http://www.engbedded.com/fusecalc/

1Proxy0

#2
Nov 19, 2018, 08:06 pm Last Edit: Nov 19, 2018, 08:07 pm by 1Proxy0
You can't do much wrong with that program. It is so simple.
I guess you should look at the fuse settings on the chip. It looks like the standard is an effective 1 MHz clock rate and your program is expecting 16 (or maybe 20) times that.

http://www.engbedded.com/fusecalc/
what do you mean with "an effective 1 MHz clock rate"?

isn't the chip set to run at 20MHz like it says on Digikey? do i have to change the Arduino IDE to 20MHz somehow?

also i'm sorry but i have no idea what any of those things on that site mean.

EDIT: also why am i being thrown out of the thread each time i reply or comment? it's really annoying

srnet

what do you mean with "an effective 1 MHz clock rate"?
When you programmed it, from the Arduino IDE presumably, what settings did you use ?
http://www.50dollarsat.info/
http://www.loratracker.uk/

1Proxy0

#4
Nov 19, 2018, 10:27 pm Last Edit: Nov 19, 2018, 10:31 pm by 1Proxy0
When you programmed it, from the Arduino IDE presumably, what settings did you use ?
where is the setting for that in the IDE? and how does that effect the speed at which the program runs?

EDIT: wait i just noticed these settings in the programmer



they seem to somewhat match the fusebit things. are these of any significance?

westfw

Quote
isn't the chip set to run at 20MHz like it says on Digikey? do i have to change the Arduino IDE to 20MHz somehow?
No, the digikey number is the MAXIMUM ALLOWED clock rate.
You have to set the CHIP (using the fuses) to know that it has an external crystal that it should use, and not to do additional modifications of the clock.  (The default is to run from an 8MHz internal clock, and to further divide that by 8, giving a 1MHz final clock rate.)
I think you want to un-set all the checkboxes in the first column (Fuse Low Byte) EXCEPT for CKSEL3.
See the chip data sheet, and/or http://www.engbedded.com/fusecalc/

pert

why am i being thrown out of the thread each time i reply or comment? it's really annoying
There is a forum setting that might control this:
  • Hover the mouse pointer over your avatar in the top right corner of the screen.
  • Click "Profile".
  • Click "Forum Settings > Edit".
  • Click "Settings > Look and Layout".
  • Check "Return to topics after posting by default."
  • Click "Change Profile".

6v6gt

The process of loading the Arduino bootloader onto the chip via the Arduino IDE sets the fuses on a raw chip. You have chosen not to use the bootloader but if you compiled the program in the Arduino IDE, what target board did you select? A standard Uno for example would generate code assuming  a 16Mhz crystal.

1Proxy0

The process of loading the Arduino bootloader onto the chip via the Arduino IDE sets the fuses on a raw chip. You have chosen not to use the bootloader but if you compiled the program in the Arduino IDE, what target board did you select? A standard Uno for example would generate code assuming  a 16Mhz crystal.
I selected the Uno.

Wish I knew how to set it to expect a 20 MHz clock

No, the digikey number is the MAXIMUM ALLOWED clock rate.
You have to set the CHIP (using the fuses) to know that it has an external crystal that it should use, and not to do additional modifications of the clock.  (The default is to run from an 8MHz internal clock, and to further divide that by 8, giving a 1MHz final clock rate.)
I think you want to un-set all the checkboxes in the first column (Fuse Low Byte) EXCEPT for CKSEL3.
See the chip data sheet, and/or http://www.engbedded.com/fusecalc/

Alright I need to set those checkboxes right and try again.

Also does this mean 20 MHz is too much? Now I already brought like 4 20 MHz crystals for this.

pert


1Proxy0

The easiest way is to use MiniCore:
https://github.com/MCUdude/MiniCore
Thanks I'll try that too.

Say you got a link to the Datasheet of the ATmega 328p pu? The microchip site won't load on desktop and mobile.

westfw

Datasheets:
Direct datasheet link to Microchip
Datasheet stored at Farnell/Newark

+1 for MiniCore...


Quote
Check "Return to topics after posting by default."
Huh - I didn't know that that existed!




1Proxy0

Datasheets:
Direct datasheet link to Microchip
Datasheet stored at Farnell/Newark

+1 for MiniCore...

Huh - I didn't know that that existed!




The second one worked thanks!


I also didn't knew that option existed. It makes little sense that it's not enabled by default since most forums work like that.

1Proxy0

Thanks everyone for the help, now it works perfectly!


pert

Congratulations!

It looks like you are missing the 0.1 uF decoupling capacitors on the power lines. You might get by without them but really you should use them

Go Up