OSC Calibrator and High Voltage Fuse Resetter for 8-Pin ATtinys

Overview

TinyCalibrator - OSC Calibrator and High-Voltage Fuse Resetter

Because the 8-pin ATtinys only have a few GPIO pins available, they are usually operated without an external clock. The internal oscillator does a good job in most applications, but when it comes to precise timing, its +/-10% accuracy is often insufficient. Fortunately, the oscillator can be calibrated, increasing its accuracy to +/-2% or better. There are a few ways to perform this manual calibration, but several steps are required. The TinyCalibrator does this fully automatically by a push of a button. In order to make the device more versatile, a high-voltage fuse resetter was also integrated, with which "bricked" ATtinys can be reset to the factory state.

pic2.jpg

Hardware

The TinyCalibrator is supplied with 5V via a Micro USB connector. Since the frequency of the oscillator depends on the supply voltage of the ATtiny, an HT7333 voltage regulator was integrated. A switch can then be used to choose whether the oscillator should be calibrated for 3.3V or 5V.

The ATtiny84 was chosen as the microcontroller for the TinyCalibrator because it has exactly the necessary number of GPIO pins. For accurate frequency measurements, the ATtiny84 is operated with an external 12 MHz crystal. Since the current software version only requires about 3.7 kByte, an ATtiny44 can also be used.

To generate the 12V for the High-Voltage Serial Programmer, an ST662A charge pump IC was chosen, which was specially designed for such applications and needs only a few external components. The 12V is controlled by a MOSFET and applied to the RESET pin of the target ATtiny if necessary. The remaining programming lines to the target are protected against a short circuit with resistors.

The user interface utilizes three buttons and a 128x64 pixels OLED display.

pic1.jpg

Software

Basic Principle

To carry out the calibration, a program is first uploaded to the target ATtiny using the integrated High-Voltage Serial Programmer. In addition, the factory oscillator calibration value (OSCCAL) is written to the EEPROM. The program on the target ATtiny reads the EEPROM and writes the value to the OSCCAL register. Then it applies an oscillating signal with half the clock frequency to pin PB0. Since the fuses were previously set so that the target ATtiny runs with a prescaler of 8, a signal with 1/16 of the oscillator frequency is applied to PB0.

#include <avr/io.h>
#include <avr/eeprom.h>

int main(void) {
  OSCCAL = eeprom_read_byte(0);
  DDRB   = 0b00000001;
  TCCR0A = 0b01000010;
  TCCR0B = 0b00000001;
  while(1);
}

This frequency is measured by the TinyCalibrator and compared with the target value. The oscillator calibration value (OSCCAL) is then adjusted accordingly and written to the EEPROM of the target ATtiny. This process is repeated until the OSCCAL value, which leads to the lowest frequency deviation, has been found.

calibrating.png

High-Voltage Serial Programmer

The code for the High-Voltage Serial Programmer (HVSP) is quite unspectacular. Simply put, for each action, a series of instructions are sent over the data lines to the target ATtiny and the corresponding response is read. The process and the instructions are well described in the data sheet.

hvsp.png

Frequency Measurement

The timer/counters of the ATtiny84 are used for the frequency measurement. PB0 of the target ATtiny, which outputs a signal with 1/16 of its oscillator frequency, is connected to the T0 input of the ATtiny84. Timer0 counts the pulses at T0 and timer1 stops the measurement after a time of 32 milliseconds. From this, the oscillator frequency of the target ATtiny can finally be calculated.

I²C OLED Implementation

The I²C protocol implementation is based on a crude bitbanging method. It was specifically designed for the limited resources of ATtiny10 and ATtiny13, but it works with some other AVRs (including the ATtiny84) as well. The functions for the OLED are adapted to the SSD1306 OLED module, but they can easily be modified to be used for other modules. In order to save resources, only the basic functionalities which are needed for this application are implemented. For a detailed information on the working principle of the I²C OLED implementation visit TinyOLEDdemo.

Compiling and Uploading

If using the Arduino IDE

  • Make sure you have installed ATtinyCore.
  • Go to Tools -> Board -> ATtinyCore and select ATtiny24/44/84(a) (No bootloader).
  • Go to Tools and choose the following board options:
    • Chip: ATtiny84(a)
    • Clock: 12 MHz (external)
    • Millis/Micros: disabled
    • Leave the rest at the default settings
  • Connect your programmer to your PC and to the ICSP header of the device.
  • Go to Tools -> Programmer and select your ISP programmer (e.g. USBasp).
  • Go to Tools -> Burn Bootloader to burn the fuses.
  • Open TinyCalibrator sketch and click Upload.

If using the precompiled hex-file

  • Make sure you have installed avrdude.
  • Connect your programmer to your PC and to the ICSP header of the device.
  • Open a terminal.
  • Navigate to the folder with the hex-file.
  • Execute the following command (if necessary replace "usbasp" with the programmer you use):
    avrdude -c usbasp -p t84 -U lfuse:w:0xff:m -U hfuse:w:0xd5:m -U efuse:w:0xff:m -U flash:w:tinycalibrator.hex
    

If using the makefile (Linux/Mac)

  • Make sure you have installed avr-gcc toolchain and avrdude.
  • Connect your programmer to your PC and to the ICSP header of the device.
  • Open the makefile and change the programmer if you are not using usbasp.
  • Open a terminal.
  • Navigate to the folder with the makefile and the Arduino sketch.
  • Run "make install" to compile, burn the fuses and upload the firmware.

Operating Instructions

  1. Select the desired supply voltage (3.3V or 5V) with the switch.
  2. Connect a 5V power supply to the micro USB port.
  3. Place the ATtiny13/25/45/85 in the IC socket and press any key. Use an SOP adapter for SMD parts.
  4. Select the function you want and follow the instructions on the display.

After the calibration process, the optimal OSCCAL value remains in memory address 0 of the EEPROM and can continue to be used. To do this, program the EEFUSE to preserve EEPROM memory through the chip erase cycle, otherwise the OSCCAL value will be lost after uploading new firmware. Your code should then contain the following function:

#include <avr/eeprom.h>
void readOSCCAL(void) {
  uint8_t value = eeprom_read_byte(0);
  if (value < 0xFF) OSCCAL = value;
}

Of course, the OSCCAL value can also be set directly without the EEPROM. Remember that the OSCCAL value is displayed in hexadecimal.

OSCCAL = 0x66;

References, Links and Notes

  1. TinyHVSP
  2. I²C OLED Tutorial
  3. Nerd Ralph's PiggyFuse
  4. ATtiny84 Datasheet
  5. ATtiny85 Datasheet
  6. ATtiny13A Datasheet

pic5.jpg

You might also like...
PlotFS is a fuse filesystem for efficient storage of Chia plot files.

PlotFS PlotFS is a fuse filesystem for efficient storage of Chia plot files. PlotFS is not a traditional filesystem. It is mounted read only for farmi

An eventing framework for building high performance and high scalability systems in C.

NOTE: THIS PROJECT HAS BEEN DEPRECATED AND IS NO LONGER ACTIVELY MAINTAINED As of 2019-03-08, this project will no longer be maintained and will be ar

An AI for playing NES Tetris at a high level. Based primarily on search & heuristic, with high quality board evaluation through value iteration.

StackRabbit An AI that plays NES Tetris at a high level. Primarily based on search & heuristic, with high-quality board eval through value iteration.

PHP Encoder, protect PHP scripts in PHP 8 and PHP 7, High Performance, Compitable with X86_64, MIPS, ARM platform and Ubuntu/Centos/OpenWRT system.

What's FRICC2? FRICC2 is a PHP Script encryption tool. When you are developing a commercial software using PHP, the script can be distributed as encry

Visualization Library is a C++ middleware for high-performance 2D and 3D graphics applications based on OpenGL 1.x-4.x supporting Windows, Linux and Mac OS X.

Visualization Library 2.2 Gallery About Visualization Library is a C++ middleware for high-performance 2D and 3D graphics applications based on the in

The FLIP Fluids addon is a tool that helps you set up, run, and render high quality liquid fluid effects all within Blender, the free and open source 3D creation suite.

FLIP Fluids The FLIP Fluids addon is a tool that helps you set up, run, and render liquid simulation effects. Our custom built fluid engine is based a

A C++11 large integer library with effective high performance, simplistic in nature and also clean in the eyes.

BigIntegerCPP BigIntegerCPP is a C++11 port of large integer library used in CryptoLib4Pascal. It allows mostly parsing of numbers as strings in diffe

This repository is used for automatic calibration between high resolution LiDAR and camera in targetless scenes.
This repository is used for automatic calibration between high resolution LiDAR and camera in targetless scenes.

livox_camera_calib livox_camera_calib is a robust, high accuracy extrinsic calibration tool between high resolution LiDAR (e.g. Livox) and camera in t

Fast and easy to use, high frequency trading framework for betfair

Hedg Fast and easy to use, high frequency trading framework for betfair About Hedg In the sports trading industry, low latency is really important. Th

Comments
  • keep one version of code

    keep one version of code

    I noticed you have a .ino file for Arduino builds, and a .c file for building with a makefile. If you have just the .ino file, you can compile it with a makefile by passing the -x option to avr-gcc. https://github.com/nerdralph/picoUART/blob/master/examples/make.inc#L8

    opened by nerdralph 4
  • was SCI delay needed?

    was SCI delay needed?

    https://github.com/wagiminator/ATtiny84-TinyCalibrator/blob/main/software/TinyCalibrator_v0.5.ino#L327

    The datasheet says the minimum clock period is 220ns. I had no problems with a period of 250ns (cbi + sbi instructions on a 16MHz AVR), so I'd think that you certainly wouldn't need the delay on a t84 running at 12MHz.

    opened by nerdralph 1
  • cost reduction/optimization options

    cost reduction/optimization options

    The t84 RC oscillator is much better than the t85 when it comes to stability and tuning resolution. Last year I wrote an improved OSCCAL tuning function for Micronucleus, that could be used in your calibrator project. https://github.com/nerdralph/micronucleus-firmware/blob/asm/firmware/osccal.S This issue thread has some details about the tuning: https://github.com/micronucleus/micronucleus/issues/182

    This would also free up 2 pins on the t84, and one or both of them could be then used for a PWM-based charge pump instead of the external ST662.

    opened by nerdralph 2
  • update signature row with tuned OSCCAL value

    update signature row with tuned OSCCAL value

    A few years ago I started working on a HV OSCCAL tuner that uses undocumented commands to modify the signature row calibration values. I got a prototype version working, and then started work to discover how to do it without HV. I was able to erase the signature page, but a couple attempts to brute force search for the write signature page command did not succeed.

    I never got around to cleaning up the code, but after seeing your project I thought it would be a useful feature in HV mode to skip the use of EEPROM and just modify the OSCCAL value that gets loaded on reset. Here's the code: https://github.com/nerdralph/piggy-prog/tree/master/PiggyTune

    opened by nerdralph 18
Owner
Stefan Wagner
Stefan Wagner
UEFI Application for CPU Voltage/Frquency and Power Management adjustment. Great for undervolting.

Reduce CPU Power Waste and Gain Performance. Greener and Meaner! ______ ______ _ (_____ \

null 125 Dec 30, 2022
Voltage Controlled Digital Core Multimode Oscillator using Mozzi library on Arduino

Arduino-VDCO Voltage Controlled Digital Core Multimode Oscillator using Mozzi library on Arduino Its a digital Oscillator/Voice for the Eurorack Stand

null 47 Dec 12, 2022
recording OSC messages with ofxPubSubOsc

ofxRecordOsc recording OSC with ofxPubSubOsc. Dependencies ofxOsc ofxPubSubOsc 0.3.2- Notice if you got error on ofx::RecordOsc::Player::play, please

ISHII 2bit 5 Nov 21, 2021
An experimental dynamic malware unpacker based on Intel Pin and PE-sieve

Pin'n'Sieve A dynamic malware unpacker based on Intel Pin and PE-sieve (deploys PE-sieve scan on specific triggers). Caution: during the process the m

hasherezade 54 Dec 16, 2022
Seam is a pin-based node editor for OpenFrameworks that makes prototyping visual systems easier and faster.

seam Seam is a pin-based node editor for openFrameworks built using: openFrameworks Dear ImGui the node editor extension for ImGui It is heavily WIP,

Austin Clifton 2 Jan 2, 2022
CaribouLite turns any 40-pin Raspberry-Pi into a Tx/Rx 6GHz SDR

CaribouLite CaribouLite is an affordable, educational, open-source SDR platform that is also a HAT for the Raspberry-Pi family of boards (40-pin versi

CaribouLabs.co 858 Dec 15, 2022
A read-only, license friendly, FUSE based btrfs implementation

btrfs-fuse About This is a read-only btrfs implementation using FUSE (Filesystem in Userspace). Although btrfs is already in mainline Linux kernel, th

Qu Wenruo 10 Oct 13, 2022
FUSE file system for ZIP archives

title section header footer date MOUNT-ZIP 1 User Manual mount-zip 1.0 November 2021 NAME mount-zip - Mount a ZIP archive as a FUSE filesystem. SYNOPS

Google 49 Dec 28, 2022
Tiny implementation of the GNU/Linux CGroupFS (sans resource controllers) as a PUFFS or FUSE filesystem for BSD platforms

CGrpFS CGrpFS is a tiny implementation of the GNU/Linux CGroup filesystem for BSD platforms. It takes the form of a either a PUFFS or FUSE filesystem,

null 13 Nov 8, 2022
This project is a fuse crash recovery framework

This project is a fuse crash recovery framework. When the fuse user mode filesystem is performing read or write operations, if it terminates abnormally, the framework can automatically restore the fuse user mode filesystem process.

null 19 Jan 2, 2023