Atmega 328P / Arduino Clock Pin Questions - Page 1
Forum section: electronics / general

author: Electro Fan
author_rank: Super Contributor
timestamp: September 30, 2015, 05:46:10 am
content: Per the two attached diagrams, what is the reason for the alternative pinout number and naming conventions? (Maybe A is per Atmel/the Atmega and B is per Arduino?). (A is per Arduino and B is per Atmel/the Atmega?)For example, the clocks pins on diagram A are labeled PB6 and PB7; on diagram B they are labeled 9 and 10. Any significance or preferences worth noting?Whatever the names are for these two pins, what is the difference between them (or are they supposed to be the same)? On the unit I am measuring they both seem to be just under 16MHz, but they differ by about 18kHz. The slower clock seems to have more peak-peak amplitude, and a different DC offset.Thanks

author: westfw
author_rank: Super Contributor
timestamp: September 30, 2015, 05:55:28 am
content: PB6/PB7 are internal AVR Port/bit numbers. If you turn off the crystal oscillator, you can access those pins as GPIO on PORTB.9/10 are chip pin numbers; chip pin numbers start at 1 on one corner of the chip and increment as you go around the chip counter-clockwise (at least for DIPs and similar formats); the clock pins happen to be on pins 9 and 10 of the DIP chip.

author: Electro Fan
author_rank: Super Contributor
timestamp: September 30, 2015, 06:24:10 am
content: Quote from: westfw on September 30, 2015, 05:55:28 amOK, thanks - I think I had the Arduino vs Atmel naming conventions backwardI crossed out the wrong guess in the first post above and corrected it so the diagram for Pinout A is per Arduino and the diagram for Pinout B is per Atmel/the Atmega. (If this is wrong, let me know. Thx)I think the diagram below makes the mapping clear. 1-28 is from Atmel. PB0, PC0, PD0, etc. are from the AVR/Arduino.*So, now onto the question about whether the two clock pins should measure the same frequency and voltage, or if they are different for some reason....?

author: helius
author_rank: Super Contributor
timestamp: September 30, 2015, 06:56:59 am
content: Quote from: Electro Fan on September 30, 2015, 06:24:10 amIt is still wrong. The pins 1-28 are the physical pins of the chip: they are not "per" any convention. All chips in DIP-28 packages number their pins in the same way (even though the precise dimensions can vary between vendors). And even more generally, Pin 1 is always adjacent to the dot molded into the plastic, no matter what kind of package it is.The first diagram you posted is the one that shows all of the functions available on each pin (the pin numbers 1-28 are not shown because they are obvious from the context. But they are still the same numbers). The function that is used on any particular application is selected using configuration registers or "fuses". The programmer burns those into the chip so it will function as intended with the circuit on the board. An Arduino is just one application that has programmed the chip for a board called "Arduino". The functions they selected appear to be the ones in your second diagram.QuoteYou aren't specific about what conditions you were "measuring". On this micro, pins 9 and 10 are optionally used for either clock input, crystal, or GPIO (as labelled in your first diagram). Like almost every other pin on the chip, their function is defined by a configuration register. When it is configured for a crystal, the chip drives a pulse out of one pin and through the crystal, which returns the pulse into the other pin, forming a clock circuit. It should be obvious that the signals on both pins cannot be the same, as one is before, and the other after, the crystal.

author: obiwanjacobi
author_rank: Super Contributor
timestamp: September 30, 2015, 08:35:37 am
content: I always understood that the act of measuring a crystal-clock influences the actual value. So I always assumed that small variations in (parasitic) capacitance may also affect the actual clock. Perhaps the two clocks you measured were constructed differently (breadboard/pcb) or had different caps (tolerance)?

author: Electro Fan
author_rank: Super Contributor
timestamp: September 30, 2015, 09:19:03 am
content: Quote from: helius on September 30, 2015, 06:56:59 amUh, Ok - all chips with 28 pins are numbered 1-28, and pin 1 is always adjacent to the dot. I guess that's what I'd call "convention". The rest of the numbering/naming nomenclature comes from the realm of the Arduino board and app. Cool. ThanksSo, pins 9 and 10 are the same at the time of manufacture but they can be configured (with a configuration register) for one of three different functions: i) clock input, ii) crystal, or iii) GPIO.Let's set aside iii) GPIO.Does i) clock input mean the pin is configured to receive a clock - maybe from another pin on the chip, or something external to the chip, or does it have some other meaning? (Or is the clock input function the pin that generates the pulse(s) that drive the crystal?)That leaves leaves ii) crystal. My impression of a crystal is that it establishes/creates/vibrates a particular frequency.So, I think what you are saying is that one of the pins generates a pulse (or a series of pulses?) and the pulse(s) drive into the crystal which results in a frequency being given to the other pin (and together the pulse output pin/crystal/input pin create the clock circuit). (I need some help with the assignment of the input and output terms.)In the particular Uno that I'm using I made a simple sketch that sends some text from the PC to the Uno to a LCD which displays the text. I don't think I made any specific code for configuring the two clock pins. Is there a default configuration that these two pins might use?I think this was the basis for the sketch:http://playground.arduino.cc/Main/LiquidCrystal- maybe something in here configured Pins 9 and 10?I'm pretty foggy on why one clock pin would drive a crystal into another clock pin all for the purpose of adjusting one pin by about 18 kHz on roughly 16 MHz (or maybe it's a coincidence they are so similar in frequency?).Or maybe it's the parasitic / measurement effect mentioned by obiwanjacobi? But that would seem to contradict the notion that "it should be obvious that the signals on both pins cannot be the same, as one is before, and one after, the crystal."If you have any links to articles that explain these two pins, the crystal, and the clock circuit I'll be happy to read up on itThanks!

author: Electro Fan
author_rank: Super Contributor
timestamp: September 30, 2015, 10:07:06 am
content: Ok, doing my own research - but not sure if I'm getting anywhere,or as Yogi Berra said: "We're lost, but we're making good time."http://www.martyncurrey.com/arduino-atmega-328p-fuse-settings/https://www.arduino.cc/en/Main/StandaloneAdd a 16 MHz external clock between pin 9 and 10, and add two 22 pF capacitors running to groundhttp://sphinx.mythic-beasts.com/~markt/ATmega-timers.htmlMost crystal-derived clocks give better than 0.01% accuracy.I measured the frequencies at pins 9 and 1015,976,200 Pin 1015,957,800 Pin 999.88%0.01% crystal accuracy99.89%15,957,800 Pin 915,976,200 Pin 10100.12%0.01% crystal accuracy100.11%Throw in some of the effect described by obiwanjacobi and maybe pins 9 and 10 should be running at pretty much the same frequency (ie, ~16MHz)?- still up for understanding how pins 9 and 10 and the crystal work together....

author: ralphd
author_rank: Frequent Contributor
timestamp: September 30, 2015, 10:42:00 am
content: Xtal1 and xtal2 are the input and output of the inverting amplifier. I'm pretty sure the datasheet goes into the details of this. On a scope the output will be higher voltage than the input.

author: K5HJ
author_rank: Regular Contributor
timestamp: September 30, 2015, 01:55:43 pm
content: Pins 9 and 10 are exactly the same frequency. You are affecting this frequency by probing the pins and changing the capacitance.If you want to get an accurate reading, enable the "clock out" fuse and measure the frequency on pin 14.Randy

author: Electro Fan
author_rank: Super Contributor
timestamp: September 30, 2015, 03:42:23 pm
content: Thanks to everyone for all the help in figuring this out (I'm not there yet, but things seem to be getting clearer).For clarity, the pins are:XTAL1 = inputXTAL2 = outputBelow are some excerpts from the spec sheet for the 328P:(I've left out the discussion of Clock Startup Sequences - trying to figure out the post-startup stuff first)http://www.atmel.com/Images/doc8161.pdf8.3 Low Power Crystal OscillatorPins XTAL1 and XTAL2 are input and output, respectively, of an inverting amplifier which can beconfigured for use as an On-chip Oscillator, as shown in Figure 8-2 on page 29. Either a quartzcrystal or a ceramic resonator may be used.This Crystal Oscillator is a low power oscillator, with reduced voltage swing on the XTAL2 output.It gives the lowest power consumption, but is not capable of driving other clock inputs, andmay be more susceptible to noise in noisy environments.In these cases, refer to the ”Full SwingCrystal Oscillator” on page 30.C1 and C2 should always be equal for both crystals and resonators. The optimal value of thecapacitors depends on the crystal or resonator in use, the amount of stray capacitance, and theelectromagnetic noise of the environment. Some initial guidelines for choosing capacitors foruse with crystals are given in Table 8-3 on page 29. For ceramic resonators, the capacitor valuesgiven by the manufacturer should be used.The Low Power Oscillator can operate in three different modes, each optimized for a specific frequencyrange. The operating mode is selected by the fuses CKSEL3..1 as shown in Table 8-3on page 29.8.4 Full Swing Crystal OscillatorPins XTAL1 and XTAL2 are input and output, respectively, of an inverting amplifier which can beconfigured for use as an On-chip Oscillator, as shown in Figure 8-2 on page 29. Either a quartzcrystal or a ceramic resonator may be used.This Crystal Oscillator is a full swing oscillator, with rail-to-rail swing on the XTAL2 output. This isuseful for driving other clock inputs and in noisy environments. The current consumption ishigher than the ”Low Power Crystal Oscillator” on page 28.Note that the Full Swing CrystalOscillator will only operate for VCC = 2.7 - 5.5 volts.C1 and C2 should always be equal for both crystals and resonators. The optimal value of thecapacitors depends on the crystal or resonator in use, the amount of stray capacitance, and theelectromagnetic noise of the environment. Some initial guidelines for choosing capacitors foruse with crystals are given in Table 8-6 on page 31. For ceramic resonators, the capacitor valuesgiven by the manufacturer should be used.The operating mode is selected by the fuses CKSEL3..1 as shown in Table 8-5

author: Electro Fan
author_rank: Super Contributor
timestamp: September 30, 2015, 03:59:22 pm
content: Starting to summarize some findings...Question: With the scope probe, should the voltage on Pins 9 and 10 be measured with DC coupling or AC coupling? (Either way with Vpp I get about 1.2V for Pin 9 and 0.8V for Pin 10. Perhaps this reflects the spec sheet comment in Section 8.3 regarding reduced voltage swing on XTAL2 output?) Is the preferred measurement Vpp, or something else? Thanks

author: Hideki
author_rank: Frequent Contributor
timestamp: September 30, 2015, 06:57:29 pm
content: Like K5HJ said, the frequency on both pins is the same before you start measuring it.Your oscilloscope probe's capacitance will change the frequency in a different way depending on which side you're measuring. With a 1x probe you might even stop the oscillation completely. 10x will usually work, but it will affect the signal, so to properly measure a crystal oscillator, use a probe with even more attenuation than 10x or with as low capacitance as you can get.AC/DC coupling is mostly irrelevant. Especially when you measure Vpp, which is the "voltage swing" that the datasheet is talking about.

author: K5HJ
author_rank: Regular Contributor
timestamp: September 30, 2015, 07:24:36 pm
content: I might also add that the voltage swings will vary with probe loading as well.I can't think of a good reason to measure this anyway. Unless it's just out of curiosity.Just keep in mind that things are not always as they seem.Randy

author: Electro Fan
author_rank: Super Contributor
timestamp: October 01, 2015, 06:18:33 pm
content: Quote from: Hideki on September 30, 2015, 06:57:29 pmHideki, Thanks.I am using a 10x probe. Given that the frequency is the same on both pins before measuring them, and given that the same probe is being used to measure both, what is it about the probing process that results in the different frequencies?What is it about the DUT and/or scope circuitry that results in Pin 9 having a lower frequency (and a higher voltage) and Pin 10 having a higher frequency (and a lower voltage)?Why does the scope's probe change these two pins' performance in a different way?Is there any chance that while the two pins have the same frequency (before being measured) that the (relatively high?) capacitance of the probe effectively impacts not only these two pins but also the larger circuit in which they participate - and since one pin is before the crystal and one is after the crystal the differences I am seeing are not just the impact of the probe capacitance on pins 9 and 10 but the impact of the capacitance on the DUT circuit (which reflects the two pins' different positions in the overall DUT circuit)?EF

author: K5HJ
author_rank: Regular Contributor
timestamp: October 01, 2015, 08:44:46 pm
content: The frequency is the same on both pins whether you are probing them or not.The capacitance of the probe changes the parallel resonance of the crystal circuit and is different depending on whether you are probing the input or the output of the internal amplifier.The overall frequency is dictated by the parallel resonance of the crystal with the external capacitance factored in. This includes the pins, the board, the crystal holder, the external capacitors and the probe.This is why the crystal is specified with a certain load capacitance.Randy

author: Hideki
author_rank: Frequent Contributor
timestamp: October 01, 2015, 09:10:44 pm
content: To solve this mystery, it would help if you had some understanding of how a typical cmos crystal oscillator works.https://en.wikipedia.org/wiki/Pierce_oscillatorU1 is a cmos inverter with R1 (usually 1 Mohm or more) biasing it into a high gain linear amplifier. Sometimes there's an additional resistor from the output to the crystal, to limit the drive level. This would be inside the chip, while the "filter circuit" part of the loop through C2, X1 and C1 isconnected outside. Very simpllified, it acts like a very sharp bandpass filter that only passes the frequency the crystal is tuned to. To make it oscillate at the correct frequency, C1 and C2 must be of the correct value - otherwise it will be mistuned a bit.When you touch your probe to one of the sides, the capacitance of the probe adds to the capacitance of C1 or C2, and this will of course change the resonant frequency a little.To see exactly how the frequency changes depending on what side and how much you add, you will have to dive in to the evil crystal oscillator maths

author: Electro Fan
author_rank: Super Contributor
timestamp: October 01, 2015, 09:15:00 pm
content: Quote from: K5HJ on October 01, 2015, 08:44:46 pmHi Randy,Thanks - I'm buying all of that, so I'm soldNext question: do the voltages measure different on the pins different because of the impact of the capacitance on the impedance? Thx again.

author: Electro Fan
author_rank: Super Contributor
timestamp: October 01, 2015, 09:23:51 pm
content: Quote from: Hideki on October 01, 2015, 09:10:44 pmHideki,Thanks - that is informative.Given that - "To make it oscillate at the correct frequency, C1 and C2 must be of the correct value - otherwise it will be mistuned a bit" - perhaps this type of circuit is particularly sensitive to changes in capacitance loading?

author: K5HJ
author_rank: Regular Contributor
timestamp: October 01, 2015, 09:24:59 pm
content: The probe would affect the pins differently depending on whether you are probing the input of the amplifier vs. the output.But, as ralphd stated, the output will always be higher, probe or not.Back to my earlier post. If you really want to know the frequency, you can turn on the clock out function and measure it on pin 14.This will be a buffered output and the frequency is unaffected by the probe.Randy

author: K5HJ
author_rank: Regular Contributor
timestamp: October 01, 2015, 09:28:56 pm
content: This circuit is designed so you CAN tune it. Adjusting the capacitor values allows you to zero in to the desired frequency.This is operating the crystal in parallel resonance mode. In series mode it doesn't "tweak" so easily.Randy

author: Electro Fan
author_rank: Super Contributor
timestamp: October 01, 2015, 09:49:59 pm
content: Quote from: K5HJ on October 01, 2015, 09:24:59 pmRandy, thanks. I did see that, but I was under the impression that as per your instructions it would require enabling the "clock out" fuse. I know this is going to be hard for you and some of the guys here to believe, but I haven't changed any fuses (other than the ones made by Little Fuse and Buss). I just tried measuring the frequency on pin 14 and it doesn't seem to be behaving nicely - I think I might need a link to some instructions on how to enable the "clock out" fuse. EF

author: Electro Fan
author_rank: Super Contributor
timestamp: October 01, 2015, 09:55:08 pm
content: Quote from: K5HJ on October 01, 2015, 09:28:56 pmSo for example, if the frequency is currently 15.9 MHz changing the capacitor values could enable the frequency to be set to 16.0 MHz? (Any ideas regarding where on a Uno would be the easiest way to implement such a capacitor/capacitance change?)

author: K5HJ
author_rank: Regular Contributor
timestamp: October 01, 2015, 10:00:23 pm
content: You would have to change C1 and C2 to a lower value to raise the frequency.But, first you have to verify what the actual frequency is. You cannot do this by probing the pins.Here is a good document on crystals you might find enlightening:http://www.foxonline.com/pdfs/xtaldesignnotes.pdfRandy

author: K5HJ
author_rank: Regular Contributor
timestamp: October 01, 2015, 10:06:24 pm
content: Since you are operating in the Arduino world, I'm not sure you would have to tools to manage the fuses.You could write some code to enable a PWM output on a pin and measure its frequency.Randy

author: Electro Fan
author_rank: Super Contributor
timestamp: October 01, 2015, 10:13:07 pm
content: Quote from: K5HJ on October 01, 2015, 10:00:23 pmExcellent article - Thanks!

author: K5HJ
author_rank: Regular Contributor
timestamp: October 01, 2015, 10:14:44 pm
content: I might also add, the frequency is probably "close enough" anyway. Even if you tweak it, it will vary depending on temperature.Any applications that require high accuracy would need an external, temperature compensated oscillator.Randy

author: Len
author_rank: Frequent Contributor
timestamp: October 01, 2015, 11:02:23 pm
content: Quote from: K5HJ on October 01, 2015, 10:06:24 pmThe Arduino software comes with the avr-gcc compiler & tools, including avrdude which is used to manage the AVR fuses.

author: westfw
author_rank: Super Contributor
timestamp: October 02, 2015, 12:29:21 am
content: QuoteThe Uno uses a ceramic resonator whose capacitors are built-in. I don't think that those are as tuneable as a crystal. (and in any case, there are no existing capacitors or footprints for capacitors that would make it easy to change/add capacitance.)(Derivatives ("clones") may be set up differently.)

author: Electro Fan
author_rank: Super Contributor
timestamp: October 03, 2015, 04:20:06 am
content: Quote from: K5HJ on September 30, 2015, 01:55:43 pmHi Randy, here is a progress report:I used a TL866A programmer to change the fuse for pin 14 on the Atmega328P. In the MiniPro software for the TL866A I selected CKOUT and hit program it confirmed a successful write. Then I did a read and it confirmed success + I could go back in the MiniPro search function and see the code as I expected it too look.Next I moved the Atmega from the TL866A to the Arduino. I probed pin 14 with the scope and sure enough, it displayed 16 MHz (not the 15.9 MHz I had previously seen on the crystal in and out pins. So far, so good - but the LCD display connected to the Uno wasn't showing the text as it had previously, so I tried uploading the sketch with the text to the Uno/LCD; the IDE showed a successful upload, but nothing appeared on the LCD.Next, I moved the Atmega from the Arduino to the TL866A and removed the checkmark next to CKOUT, and then returned the Atmega to the Arduino. Still no text on the display at that point, but when I uploaded the sketch to from the IDE to the Arduino the text came back to the LCD.So, mostly good. I was under the impression that turning on CKOUT was just a another way of getting a (more accurate?) frequency read from the Atmega (vs. from pins 9 and 10 next to the crystal). Maybe enabling CKOUT does something else?One other thing I noticed when I had CKOUT enabled and probed pin 14 is that the signal on the scope exhibited what look alike some jitter. I didn't spend much time playing with it since I was in a hurry to see if I could get the chip re-programmed - so that's all I know so far.Any idea further insight regarding CKOUT and it's impact on the sketch would be appreciated.Thanks, EFImage shows CKOUT unchecked; with it checked pin 14 reads 16 MHz but the sketch in the Atmega no longer runs (and the Atmega won't accept a sketch upload); when it is unchecked the Atmega performs normally (accepts a sketch).

author: westfw
author_rank: Super Contributor
timestamp: October 03, 2015, 08:52:25 am
content: Well, you obviously prevent other uses of pin14 (arduino digital D-8), which the LCD example you referenced in your other thread is trying to use as one of the signals to the LCD...

author: Electro Fan
author_rank: Super Contributor
timestamp: October 05, 2015, 12:38:48 am
content: Quote from: westfw on October 03, 2015, 08:52:25 amI've been trying to find a concise description of the function of pin 14 on the 328P but no luck yet. Please let me know if you see a link to something that describes pin 14.In the meantime I came across this - looks pretty interesting:http://courses.cs.washington.edu/courses/csep567/10wi/lectures/Lecture6.pdfUpdate - looks like it's easier to find information as "PB0" - especially in the Atmel datasheet- but I'm still not clear about what it does even after reading it

author: obiwanjacobi
author_rank: Super Contributor
timestamp: October 05, 2015, 05:24:36 am
content: To get a feel for the potential functions of a pin, I always refer to the pinout (DIP?) diagram. The PA, PB, PC and PD pins are your basic GPIO pins - if they're in the right mode and/or other modes are not active. If you have JTAG (fuse?) and ADC disabled pretty much every GPIO pin is available (from memory).So if you want all the functions that pin14 can perform, simple search the document (pdf) for all the designators listed between parenthesis with the pin. PCINT0, CLK0 and ICP0. From memory I can tell you that PCINT stands for Pin-Change Interrupt - the rest I can't remember for sure. If you have found a reference to the designator you're searching for, make sure the chapter is really about the correct subject - although other references to your pin might be worth checking out too.Hope it helps.

author: westfw
author_rank: Super Contributor
timestamp: October 05, 2015, 09:14:34 am
content: QuoteYou seem to have some ... odd ... pieces of knowledge missing, to be trying to figure out how things are working by probing around with a scope and such; maybe you should try to find an appropriate book about microcontroller or microcomputer basics and do some reading instead of probing. (I don't mean this to be an insult, but it's hard for me to figure out what to say. It reminds me of a book I read once where an adolescent character was trying to read, without ever having learned about letters.)

author: K5HJ
author_rank: Regular Contributor
timestamp: October 05, 2015, 02:37:59 pm
content: I second what westfw and obiwan said.The purpose of enabling clock out was so you can assure yourself that the frequency is correct. Mission accomplished.If your application uses pin 14 for some function, the enabling clock out disables this function.Sounds like everything is is working properly.You really should refer to the data sheet in this device. All of this information is spelled out in detail.Edit:http://www.atmel.com/images/Atmel-8271-8-bit-AVR-Microcontroller-ATmega48A-48PA-88A-88PA-168A-168PA-328-328P_datasheet_Complete.pdfRandy

author: Electro Fan
author_rank: Super Contributor
timestamp: October 05, 2015, 08:16:54 pm
content: Quote from: K5HJ on October 05, 2015, 02:37:59 pmRoger that - I changed the fuse, checked the clock, got 16MHz, all good - that part of the mission is accomplished.I had assumed incorrectly that when I got 16MHz on that pin that the rest of the chip/program/circuit would run - but clearly turning that pin into 16MHz of output removed some other function. I get it - so I was just trying to figure out in (simplified terms) what the other functions of that pin might be.In reading the datasheet I saw the following:PB0ICP1 (Timer/Counter1 Input Capture Input)CLKO (Divided System Clock Output)PCINT0 (Pin Change Interrupt 0)• ICP1/CLKO/PCINT0 – Port B, Bit 0ICP1, Input Capture Pin: The PB0 pin can act as an Input Capture Pin for Timer/Counter1.CLKO, Divided System Clock: The divided system clock can be output on the PB0 pin. The divided system clockwill be output if the CKOUT Fuse is programmed, regardless of the PORTB0 and DDB0 settings. It will also beoutput during reset.PCINT0: Pin Change Interrupt source 0. The PB0 pin can serve as an external interrupt source.I'm guessing that when I changed the fuse to produce 16 MHz output that I invoked CLKO. Even though it refers to a "divided clock" I got the full 16 MHz. (I'm not sure if divided means it could also run at 8MHz and other specified frequencies, etc. or if divided simply means "divided into clock cycles" in general - it's this type of ambiguity that simply requires enough experience to gain context, but to the experienced person it seems strange to even ask, I guess.)One of the definitions I need is for "Port". I get what a telecommunication/networking port is on a PC or router, etc. I realize that ports can be physical or logically specified. What I need to read and much better understand isSection 14. I/O-Ports. I think if I can get a better grip on port naming conventions and port functions (and probably shift registers too) a lot of this stuff will become more clear. Some of it is getting clear on the concept, part of it is the terminology, and a big part is just consolidating the knowledge through some hands on experience.When I started at EEV I couldn't have explained Ohms Law. Believe it or not (I'm betting you guys can believe it) it took me a long time to figure out the concept of voltage drops, pull up and pull down resistors, and I'm still barely comprehending capacitance. And inductance is out there over the horizon. But with some basic V=IR I'm traveling on a path to understanding how High and Low voltage is created, clocked, and interpreted (Hex, Binary, ASCII, etc.). From there I'm working my way to shift registers and deeper into microcontrollers. Along the way is C and the IDE. To you guys it's like "wow, where has he been - under a rock?" To me it's like "wow, when you get out from under the rock it's sunny and there's a lot to see".Thanks for the help.

author: Electro Fan
author_rank: Super Contributor
timestamp: October 05, 2015, 08:48:10 pm
content: Quote from: westfw on October 05, 2015, 09:14:34 amwestfw,I appreciate the knowledge and help (and I don't mean this be an insult) but if the teacher could layout the hierarchy that explains how letters make words, words make sentences, sentences make paragraphs, etc. it might be easier for the student to learn to read. Having said that, it's 100% on the student to figure out how to frame the questions and then maybe the teacher would have a better chance of concisely answering the questions and/or providing relevant surrounding context. The trick in many things is to diagnose the situation. What you are correctly diagnosing is that I have some knowledge and insights in some areas and a total lack of knowledge in others. If I could find the shortest path from A to Z I'd take it but in the meantime I'm searching for it. Realistically, it's a long journey (learning electricity, analog and digital, hardware and software, and more) even on the shortest path so I'm trying to enjoy the journey - and along the way I'm open to you and anyone here who wants to weigh-in with any info, links, etc. Every new piece of data and concept that falls into place during the journey is like finding and smelling a rose.EF

author: helius
author_rank: Super Contributor
timestamp: October 05, 2015, 09:51:31 pm
content: I tried to layout some of that hierarchy in my first reply, but as usually is the case, what you write to somebody is either obvious to them or flies over their head.The pins on the chip (well if you really want to be precise, the pins are part of the package; they are bonded to pads on the integrated circuit) contain multiplexers to switch multiple different peripheral functions. A multiplexer is a kind of fan-in switch that selects 1 out of N inputs to connect to its single output. It has a distinctive circuit symbol that makes its role clear. The signal that drives the multiplexer (mux) to tell it which input to select, comes from a control line in the circuit. In the ATMega, these control signals are called "fuses" even though they are really just bits in a special EEPROM area. The significance of the "fuse bits" is that the program running inside the chip can't change what peripherals are assigned to each pin in the cases where they are determined by the fuse bits. That can only be programmed externally.In most cases, each pin has a small set of peripherals that connect to its mux: each peripheral can either go to a particular pin, or none at all. Some MCUs have more flexible "routing" so you can choose any of the pins for each peripheral, but the ATMega doesn't have that. When you read the data sheet, it will explain (usually in the first pages!) what peripherals are available on each pin. When you see "PA0", that means: the peripheral is a {P}ort, named Port {A}, and this pin is bit 0 in the port. A Port is a GPIO (General Purpose I/O) peripheral that is read or written to directly as a register in the software. Whatever is written to the port address is driven out of the port's pins (when it is enabled for output); when the port address is read, it stores whatever is coming in the port's pins. It's common for each of the port's pins to be configurable (in software) for input or output, but you still load or store all the bits in parallel. Each port (Port A, Port B, etc) has its own address (or "register") that the software is programmed to use. The port is a very basic peripheral that is effectively under full software control; other peripherals have more specialized functions that run in hardware.For example, one of the other peripherals available on the same pin as PB0, ICP1, is an event input for the timer. Each time it changes to some state (high-to-low or low-to-high), it sends a hardware pulse to the timer that resets, decrements, etc., all in hardware and independent of the software code. Only when it is enabled, of course.The COUT peripheral is used to drive external circuitry with a clock signal that's synchronous with the ATMega chip. It has a hardware divider so that it can be used for multiples of the internal clock: So every 6 internal clock cycles, output 1 external clock pulse, for instance. This saves the need for an external 74HC292. The divisor is stored in another register: by writing different values to it in code, you could implement a tone generator.

author: Electro Fan
author_rank: Super Contributor
timestamp: October 06, 2015, 02:54:56 am
content: Quote from: helius on October 05, 2015, 09:51:31 pmhelius, Thanks - that was great! Very informative and helpful. I appreciate it. If there was a way to flag a post and index it for others to read on the subject I'd flag it for sure. I've read it a few times and it is helping me navigate the Atemga spec sheet. Thanks gain, EF

author: CustomEngineerer
author_rank: Frequent Contributor
timestamp: October 06, 2015, 03:09:56 am
content: Quote from: helius on October 05, 2015, 09:51:31 pmI already knew all of that and I still feel like I learned something reading it. Great explanation.