I've been building a MAX7221-inspired #ATmega48 -powered code to drive up to 16 7-segment digit display. For whatever reason, it was trying to display N-1 blanks and a "0" as the first digit when fed with valid #SPI input. After several evenings of debugging, I realized that I had the SDI wire hooked up to the wrong pin on the #AVR. *facepalm* Moving the wire to the correct place made everything work. #electronics
#electronics #avr #spi #atmega48
This morning, I looked through the datasheet for the #ATmega48 and was reminded that waking up from sleep takes some time - specifically, 4 cycles to go from idle to ready for the interrupt handler. So, I took the sleep out from the code hoping to see the 10-11 cycles turn into 6-7 cycles...but nothing changed. Hmm... #electronics
Tonight's #electronics experiment was about looking at the pin change interrupt latency. The #ATmega48 was externally clocked at 10MHz and PB0 was supplied with a 1Hz signal in phase with the clock. The pin change ISR simply strobes PB1. I measured the delay between the PB0 and PB1 rising edges.
The latency was either 1.02us or 1.12us, which is 10 or 11 clock cycles + 20ns. 😢
Then I changed the PB0 square wave to 33Hz and measured again: 1.02-1.22us, with just about every value in between.
Me a year ago: whoa! I can look at waveforms which change in less than a microsecond!
Me now: This microcontroller has a 27ns delay between the clock's rising edge and the rising edge on the GPIO pin that it sets. That's boring.
Ok, it actually is impressive that a cheap #ATmega48 microcontroller can do that. The jitter on the GPIO pin is rather good too - the period of the toggled pin has a 265ps stddev.
So, what am I making? I'm building a BME280-based temp/pressure/humidity logger. I know I'm not the first and won't be the last.
Once a minute, the #ATmega48 gets the current measurements from the #BME280 via SPI and dumps the raw 8-byte measurement to the serial port. The next step is to make it log the data to an SPI flash as well.
For example, the measurement '5428007e8e004a95' translates to 19.386 degC, 1015.645 hPa, 33.671%rh.
The feeling when you program a microcontroller for a 4 second periodic interrupt, measure 4.03125 seconds, and when trying to calculate the amount of compensation you realize that you have an #offbyone tick error which equates to 31.25ms. After fixing it, you get 4.00000241 seconds on the counter. 🤦♂️ Not bad for #ATmega48 with a 32768Hz crystal. 😎 #electronics
#electronics #atmega48 #offbyone