Replies: 2 comments 5 replies
-
I can't answer all of your questions, but for starters, have a good look at the diagram in 10.2.1, which describes how different clock sources can be used to drive different parts of the microcontroller. The megaTinyCore takes care of mapping out the actual clock speed (or what it thinks it is) and ensuring that millis() and micros() are close to what they should be. I've got into the habit of using "Burn bootloader" before I upload sketches, since it sets fuses consistently with the sketch. The behaviour you're describing suggests a misalignment. You should not need to worry about "clock speed" etc unless you want to do some of your own playing with other timers. As for specific questions: |
Beta Was this translation helpful? Give feedback.
-
On these parts, they start with prescale of 6, and then the user application can change that prescale. That is done by the megaTinyCore init() function which makes the CPU clock run at the selected speed from tools submenu. (whether it is derived from 16 MHz or 20 MHz depends on a fuse - this is set automatically to match the selected option when using the Arduino IDE to upload to non-Optiboot boards (Optiboot boards require a burn bootloader cycle, since normal uploads can't change their fuses)) However, you have overridden main - from which init() is called. Thus the clock controller is not configured to match your desired clock speed. The PWM timers to make analogWrite() work aren't set up either, nor is millis()/micros() timekeeping, The ADC is not configured. There is no menu option that will make the speed match the startup speed, (which is either 2.66MHz or 3.33 MHz) because these are values for which the timekeeping math is very hard, and which nobody has a particular desire to use. (note though that the megaTinyCore bootloader for serial uploading does run at this speed, since it doesn't need timekeeping and does need to fit in 256 instruction words. The millis/micros setting makes no difference until init is called (well, I think the ISR is still defined, but not enabled), because it is also configured in init() which is not being called because you overrode main. Note that this is by no means unique to megaTinyCore - all Arduino cores will be practically non-functional without their init() being called; the modern AVRs more-so because they don;t have clock fully controlled by fuses (but on the plus side, you can't fuse these to use an external clock that isnt present and lock yourself out until you can supply one, you can just tell them to try to switch to one, and if it's not there, the chip will run off internal oscillator and I think I have it do a blink code (maybe only DxCore has that) if you don't know much about this stuff, as you say, why are you using an advanced technique like overriding main and taking full control of program flow? It's an Arduino core - you can write Arduino sketches pretty much like you would for an Uno or similar, and not have to worry about configuring the clock, because that is done for you before setup is called :-P megaTinyCore does not support the ultra-slow clock options. Didn't seem like there was a compelling use case for them, and a bunch of stuff doesn't make much sense in that context. |
Beta Was this translation helpful? Give feedback.
-
Hi, folks. I have an ATtiny3216F that I have just started playing with, and am trying to understand the clock speed options in the Arduino IDE using megaTinyCore, programming with an Arduino UNO via jtag2udpi.
Here's my code:
I have
Clock Speed
set to1 MHz
andmills()/micros()
set toEnabled
. I have an LED wired toPB1
.While running the code, I counted 19 full cycles of my LED flashing in 43.5 seconds. In other words, the while loop is running at ~0.44 Hz rather than the intended ~0.17 Hz. In other other words, the MCU is counting ~2290 ms as ~6000 ms.
3216 datasheet: http://ww1.microchip.com/downloads/en/DeviceDoc/ATtiny3216-17-DataSheet-DS40002205A.pdf
Here are my questions:
mills()/micros()
setting make any difference here?Clock Speed
setting in the Arduino IDE, via megaTinyCore, saying "set your internal oscillator to this speed", or, is it saying "assume that you are wired to an external oscillator at this speed"?Thanks!
Beta Was this translation helpful? Give feedback.
All reactions