#Noe's Thread

1 messages · Page 1 of 1 (latest)

bronze kayak
#

What an absolute headache

#

Do you know what crystal I should use at 3.3V?

#

Also I'd be interested to see where you saw that on the datasheet @rigid fractal

#

Noe's Thread

rigid fractal
#

"29.4 Clock Characteristics"

bronze kayak
#

Ah yeah, I was reading that

rigid fractal
bronze kayak
#

I realize this implies an Atmel-ICE just comes with a calibration utility

rigid fractal
#

yeah, some of the Atmel-branded programmers have oscillator calibration support

bronze kayak
#

I might just do that and run at something like 300 baud rate

#

Since I transfer such little data at a time, I really don't need speed

rigid fractal
bronze kayak
#

Yeah I don't wanna interrupt the other guy asking for help

#

I just have no idea what to do here

#

I got my hands on this 10 MHz clock but the fuses are just killing my brain @rigid fractal

#

I can't interpret what's going on in this datasheet

rigid fractal
#

first of all, what kind of clock is it?

bronze kayak
#

Crystal

#

2 pins

rigid fractal
#

when you say you might have bricked the chip, what exactly happened?

bronze kayak
#

So I have more chips, I can bail it if I need to, but

#

I was modifying the options with my Atmel-ICE, and it just has a drop-down of all the possibilities

#

I chose one which looked right, but totally forgot to record what I'd done so I could find a way to reverse it if it was a mistake maybe

#

It's just this

#

I chose an option, but forgot to record my changes, and now I can't communicate with that chip

#

I think I chose something like ext low-freq crystal, and I know it said +65 ms at the end too

#

But right now, I just have no idea what the differences between these options are

#

Datasheet is not helping explain

rigid fractal
#

so you can't communicate with the chip at all? via ISP?

bronze kayak
#

Yeah it fails to enter programming mode

#

Can't read the signature or anything, it's gone

rigid fractal
#

if you had written down the hex values, that would help a lot in troubleshooting

bronze kayak
#

Yeah that's what I meant by recorded what I did

#

I forgot to do that

rigid fractal
#

you're pretty sure your selection included "ext" and "low-freq crystal"?

bronze kayak
#

Yes

#

And +65 ms at the end

#

But I have no idea what the 1K CK, 32K CK, 14 CK stuff means

rigid fractal
#

oscillator cycles, i think. it gives it time to stabilize the oscillation

#

oscillators take time to start up and become stable

#

"low-freq" typically means a 32.768kHz watch crystal, so the electrical configuration will be way off for a 10MHz crystal

bronze kayak
#

Dang it

#

I guess I'm going for the "full-swing" options huh

rigid fractal
#

you don't have to use "full-swing"; i think there's an option for low-power crystal that isn't low-frequency

bronze kayak
#

Page 26

#

On page 27, I think I'd like "Crystal oscillator, slowly rising power"

rigid fractal
#

so i think you can apply an external clock at approximately the expected frequency to XTAL1, and you'll be able to talk ISP to the chip (slowed down to 1/4 the actual clock speed)

bronze kayak
#

Why just XTAL1?

#

I'm gonna be honest with you, I actually have no idea how crystal oscillators work as discrete components, and I don't know what XTAL1 and XTAL2 each mean independently

rigid fractal
#

because XTAL1 is the input, and XTAL2 is the output, of an inverting amplifier configured as an oscillator, according to the datasheet

bronze kayak
#

I see this diagram, and it is what I have hooked up

#

Got them both at 22 pF

rigid fractal
#

yeah, the oscillator might not start up properly for a crystal that's almost 1000 times as fast as what it's configured for

bronze kayak
#

I honestly don't have a problem letting that chip go

#

For now, anyway. I want to see this configured properly, then maybe I'll think of saving him later

#

But I have more chips

#

I just have to be careful...

rigid fractal
#

yeah. you might be able to recover this chip eventually, but it might not be worth the trouble, depending on your priorities

bronze kayak
#

So what I'm seeing here is this

#

It looks promising

#

So I need to have CKSEL3..1 set for a low-power crystal, right?

#

And then configure CKSEL0 and SUT1..0 for that option

rigid fractal
#

i think so? make sure you're configured for the correct frequency range, or it might not start up

bronze kayak
#

Because to me it seems page 27 figure 8-4 is describing the sub-options when CKSEL3..1 are set for low-power oscillator?

bronze kayak
#

What really is the difference between low-power and full-swing

#

Oh, I guess it's better for "noisy environments" (I do not know what that means)

rigid fractal
#

environments that are noisy enough to disrupt the oscillator or clock subsystem, i guess. also, it'll consume more power

bronze kayak
#

What's "rail-to-rail swing on the XTAL2 output"

rigid fractal
#

i assume it means that the oscillator's inverter swings all the way from ground to positive supply voltage

bronze kayak
#

Ah okay

rigid fractal
#

i guess if you wanted to see for yourself, try both options and hook up a scope to XTAL2 (assuming that its probe doesn't disrupt the oscillator in the low-power mode!)

bronze kayak
#

picture here so I can look back in a second

#

Hmmm

#

How does 0xFF look?

#

I think I want 0xFF

bronze kayak
#

It's 0b11111111

#

It didn't brick!!!

#

I think I got it!

rigid fractal
#

yay

bronze kayak
#

Yes I know

#

The automative sheet has this info, the regular one I found did not

#

Maybe I'd found a summary sheet

#

Why are there different sheets? Something about temperature grades I'd heard?

rigid fractal
#

yeah, you might have found a summary sheet

#

different temperature grades, electrical specs, etc. the higher-level architecture is probably fairly similar

bronze kayak
#

Much nicer

#

Although it derails slightly, if you notice

#

Seems it does

rigid fractal
#

you could single-frame the video around transitions and check the time stamps, assuming you trust the time base on your camera 😁

bronze kayak
#

Could I ask you what's the deal with capacitors?

#

Why does the crystal need that feedback from the caps

rigid fractal
#

i don't remember exactly. i think it has to do with the particular way the crystal's impedance rapidly changes near its resonant frequency

bronze kayak
#

I'd like to understand this more

#

Never mind, it barely derails

#

I just ran the timer for about 5 minutes, and the gap between the seconds and the light stayed pretty much exactly the same

#

That is great

bronze kayak
#

Okay there's...quite a problem here

#

So I'm using my ICE to debug the program

#

When I send it something, I can see down there what it got

#

I have an Arduino hooked to the chip's receive line

#

And a serial terminal open to send things to the chip manually this time

#

If I send the same individual character at a time, it always shows the same character number, which seems like a good sign

#

But when I send things as a block, it's very inaccurate

rigid fractal
#

what do you mean? i can guess that you might be expecting UART input to be queued while your debugger is stopped, but that's probably not what's actually happening

bronze kayak
#

No, no, I have it stopped and waiting for input on that very program

#

When I send an input, it breaks on the line that's yellow in the picture, and shows me the byte it just read

rigid fractal
#

you have set a breakpoint on that yellow line?

bronze kayak
#

Yes

#

If I send the same exact text character on my terminal, the same number always shows up, which I guess is a good sign

rigid fractal
#

so when you're sending multiple bytes, that breakpoint triggers, the processor stops, and any bytes after that will likely be lost

bronze kayak
#

But if I send, say, the text, "123", it doesn't seem to read "1", "2", "3", it reads 2 arbitrary-looking numbers

rigid fractal
#

the rest of the world doesn't stop just because your debugger hit a breakpoint

bronze kayak
#

I thought there was a buffer kind of thing here

rigid fractal
#

even if there were, i think interrupts are disabled while stopped at a breakpoint. like the processor clock is effectively frozen

bronze kayak
#

Ah okay

rigid fractal
#

i think you're going to have to read in multiple bytes, then set a breakpoint after that, if you want to see what your program is doing when receiving multiple bytes at once

#

sometimes a microcontroller can have peripherals continue to run while stopped at a breakpoint, but they're typically more advanced ones that have DMA capability

bronze kayak
#

I've hooked up TX

#

Got a loopback, no breakpoint

#

More efficient

#

Okay, I've confirmed

#

It doesn't even understand what I'm saying

#
void loop()
{
    if (Serial.available())
    {
        Serial.write(Serial.read());
    }
}
#

I'm running this in the chip now

#

Blue is sent, purple is received

#

Wow, I am completely lost.....

#

All I can think of right now is that maybe the Arduino library just isn't affected by the F_CPU being set by me, and is just statically designed to be run at 16MHz. What do you think of that theory?

rigid fractal
#

the Arduino core's hardware serial does some internal buffering, i think, and Serial.read() might return -1 on error (but maybe that doesn't fully explain what you're seeing)

#

how are you capturing the numbers you're printing out?

bronze kayak
#

Cross-linked TX/RX @rigid fractal

bronze kayak
rigid fractal
#

so those numbers are coming from the debugger? which way did you set that up?

bronze kayak
#

Now I'm not using the debugger breakpoints

#

I'm just running that code

#

Communicating with the chip with an arduino and a serial monitor

rigid fractal
#

those numbers in blue and purple… what exactly is printing them?

bronze kayak
rigid fractal
#

and that terminal program is connected to a USB UART adapter connected to your chip?

bronze kayak
#

An arduino middle-man yes

rigid fractal
#

are you setting F_CPU in your sketch or in compiler flags?

#

also if you hardwire a loopback to your USB UART "adapter", do you see the expected result?

bronze kayak
#

By that do you mean connecting TX and RX together in one wire?

bronze kayak
#

WHAAAAAT??!?!

#

What is going on here.....

#

What. Is. Going. On. Here

#

This can't be. I plugged a 16MHz clock into the ATmega instead of the 10MHz...just to see if it would change anything

#

And it seemed my theory is correct

#

The Arduino API is hardcoded in 16 MHz, and it does not like running in 10 MHz

#

I don't understand...why is the 16MHz clock working? I'm running on 3V3, so why is the 16MHz clock working. This is against the datasheet

#

It's perfect now on 16MHz

rigid fractal
bronze kayak
#

So what does it even mean to not be recommended to run it

#

What's supposedly going to go wrong

rigid fractal
bronze kayak
#

Oh you're telling me I have to recompile this all

#

I get it

#

Somehow...because the preprocessor already went through the HardwareSerial impl files in an environment where F_CPU was something else. Is that it?

rigid fractal
# bronze kayak What's supposedly going to go wrong

could be anything could go wrong, if the datasheet doesn't say explicitly. but i imagine it would be stuff like different components might not consistently keep up with a 16MHz CPU clock at 3.3V, and you could get all kinds of corruption or incorrect behavior

rigid fractal
bronze kayak
#

Wonder where I could set this up in my environment...

#

Atmel Studio

rigid fractal
#

are you using the Arduino IDE or something else?

#

i dunno how Atmel Studio handles it. it might use the boards.txt from an Arduino install, or it might keep its own versions of things around just to be difficult

bronze kayak
#

Oh wait

#

It does ask me for the path of the Arduino IDE

#

When I created the project, it did

#

Wait, oh my gosh

#

It asked me for the Arduino path AND what board I used

rigid fractal
#

ok, you'll probably have to locate the boards.txt in the Arduino IDE library files, and create a boards.local.txt in the same directory. and make a new board definition with a different F_CPU, maybe copied from the Uno

bronze kayak
#

I said a nano

#

I'm already here

#

I'll copy from the nano since when Atmel Studio asked me what board I said nano

#

Arbitrarily

#

I just wanted the standard lib

#

So I didn't care

rigid fractal
#

i'd have to look up exactly what the nano is, but it does look like a 16MHz board

bronze kayak
#

Oh it's basically identical to Uno

#

But it's breadboard friendly is all

rigid fractal
#

it looks like 328 instead of 328P, so maybe some subtle dfiferences

bronze kayak
#

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

bronze kayak
rigid fractal
bronze kayak
#

Well, I was

#

Remember I murdered him

#

I have a collection of mixed m328s and m328ps

rigid fractal
#

but yeah, copy the nano section into a boards.local.txt and rename it to something different, set the f_cpu correctly, and try again?

#

you'll have to update the board choice in Atmel Studio after that

bronze kayak
#

Everything between the large rows of asterisks right?

rigid fractal
#

they're hash marks ### in my version, but yeah, probably. there might be something more clever you can do by adding a menu item to the existing nano.menu stuff, but i'm less familiar with how that works

#

and you might have to explicitly delete build directories to force a rebuild

bronze kayak
#

This is the most ridiculous thing I've done

#

And it's hilarious

#

I hope it works

bronze kayak
#

IT WORKED

#

THAT WORKED

#

GAHAHA

#

WHAT

rigid fractal
#

yay

bronze kayak
#

Oh my gosh, that is awesome

#

That has been

#

A journey

#

Jesus

rigid fractal
#

yeah, you're basically rolling your own custom Arduino board by using parameters that are substantially different from the standard boards

bronze kayak
#

I feel like I've grown so much in these past 2 days, it's hilarious

#

God, the pain

rigid fractal
#

hey, it's a learning experience!

bronze kayak
#

Time to clean up my room....

#

What a mess

#

How much you go through vs how messy the desk gets. Linear relationship

rigid fractal
#

weird. apparently the Arduino Nano is a 3.3V ATmega328 board clocked at 16MHz. so it's a production dev board that's technically overclocking the chip

bronze kayak
#

Seriously?

#

Are you sure?

#

Because it has a 5V output pin

rigid fractal
#

oh sorry, i misread something and it's v3.3 (hardware revision) in the datasheet

bronze kayak
#

What does that mean

rigid fractal
#

it means my brain scrambled something when i read it and saw 3.3V instead of v3.3. i checked again and elsewhere in the Nano datasheet it seems to say the MCU is powered at 5V

bronze kayak
#

Ah

bronze kayak
#

@rigid fractal Now that I got it working with Arduino standard library

#

I'm...tempted to go raw

rigid fractal
#

how raw? avr-libc? AVR assembly language?

bronze kayak
#

C

#

I'm not that crazy

#

And I'm decent at C

rigid fractal
#

rolling your own C code to use the UART module is probably doable. you'll need to read the datasheet very carefully, of course, and programming ISRs is its own kind of special adventure

bronze kayak
#

And I know for sure that made me better at datasheet reading

#

So I can go through pain again

#

Oh hey I found it

ISR(TIMER0_OVF_vect)
{
    static uint8_t currentFrame;
    
    if (++currentFrame == TOTAL_FRAMES)
        currentFrame = 0;
        
    setActiveFrame(currentFrame);
}

int main()
{
    DDRB |= 0b00001111;                    // Prepare all outputs
    DDRD = 0xff;
    
    TCCR0B = (1 << CS02) | (1 << CS00);    // 1024 prescaler. ISR active
    TIMSK0 = (1 << TOIE0);
    
    sei();
    
    while (1)
    {
        for (uint8_t layer = 0; layer < 3; layer++)
        {
            clear();
            draw(layer);
        }
    }
}
bronze kayak
#

@rigid fractal I wanna thank you again for your patience with me