All Projects → wagiminator → ATtiny84-TinyCalibrator

wagiminator / ATtiny84-TinyCalibrator

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

Programming Languages

C++
36643 projects - #6 most used programming language
Makefile
30231 projects
c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to ATtiny84-TinyCalibrator

ATtiny13-TinySolder
T12 Quick Heating Soldering Station
Stars: ✭ 45 (+15.38%)
Mutual labels:  avr, attiny, attiny13a, attiny13
ATtiny13-TinyRemoteXL
12-Button IR Remote Control
Stars: ✭ 33 (-15.38%)
Mutual labels:  avr, attiny, attiny13a, attiny13
ATtiny85-TinyCharger
Single-Cell Li-Ion Battery Charger with Monitoring
Stars: ✭ 20 (-48.72%)
Mutual labels:  avr, attiny, oled, attiny85
ATtiny85-TinyLoad
Electronic Dummy Load
Stars: ✭ 32 (-17.95%)
Mutual labels:  avr, attiny, oled, attiny85
ATtiny13-TinyUPS
Uninterruptible Power Supply
Stars: ✭ 92 (+135.9%)
Mutual labels:  avr, attiny, attiny13a, attiny13
ATtiny85-TinyDFPlayer
MP3-Player
Stars: ✭ 22 (-43.59%)
Mutual labels:  avr, attiny, oled, attiny85
ATtiny85-USB-C-Tester
Simple USB-C Power Delivery Tester
Stars: ✭ 20 (-48.72%)
Mutual labels:  avr, attiny, oled, attiny85
ATtiny85-TinyFMRadio
FM Radio with RDS
Stars: ✭ 51 (+30.77%)
Mutual labels:  avr, attiny, oled, attiny85
DigiOS
Mini OS emulator for Digispark (an Attiny85 based microcontroller).
Stars: ✭ 46 (+17.95%)
Mutual labels:  avr, attiny, attiny85
ATtiny13-TinyTacho
Simple RPM-Meter
Stars: ✭ 36 (-7.69%)
Mutual labels:  avr, oled, attiny13a
AVR-Programmer
Collection of AVR Programmers and Accessories
Stars: ✭ 25 (-35.9%)
Mutual labels:  avr, attiny, programmer
vusbtiny
Small ISP programmer that uses an ATtiny running V-USB
Stars: ✭ 18 (-53.85%)
Mutual labels:  avr, programmer
Xling
Xling, a pocket demon
Stars: ✭ 30 (-23.08%)
Mutual labels:  avr, oled
antispy-jammer
Simplest ultrasonic ANTISPY voice recording jammer based on ATTINY13 / ATTINY85 / ARDUINO with PAM8403 module driving piezo ultrasonic transducers (and optionally AD8933 signal generator)
Stars: ✭ 39 (+0%)
Mutual labels:  attiny85, attiny13
ustd
Micro-standard-library providing minimal and portable array, queue and map for attiny avr, arduinos, esp8266/32 and linux, mac
Stars: ✭ 14 (-64.1%)
Mutual labels:  avr, attiny
Nokolino diy
The small and naughty MP3-monster. DIY version.
Stars: ✭ 20 (-48.72%)
Mutual labels:  attiny85, attiny45
Avr Cheat Sheet
AVR cheat sheet for the ATmega328p
Stars: ✭ 64 (+64.1%)
Mutual labels:  avr, programmer
timonel
ATtiny85/45/25 I2C bootloader
Stars: ✭ 108 (+176.92%)
Mutual labels:  attiny85, attiny84
Arduino Deep Sleep
An example of proper and most advanced way to put ANY AVR Arduino boards in to sleep
Stars: ✭ 31 (-20.51%)
Mutual labels:  avr, attiny85
CorePartition
Universal Cooperative Multithread Lib with real time Scheduler that was designed to work, virtually, into any modern micro controller or Microchip and, also, for user space applications for modern OS (Mac, Linux, Windows) or on FreeRTOS as well. Supports C and C++
Stars: ✭ 18 (-53.85%)
Mutual labels:  avr, attiny85

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. For an in-circuit oscillator calibrator take a look at TinyICOC.

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. TinyICOC
  3. I²C OLED Tutorial
  4. Ralph Doncaster's PiggyFuse
  5. Oscillator Calibration Sketch for ATtiny13
  6. Oscillator Calibration Sketch for ATtiny25/45/85
  7. ATtiny84 Datasheet
  8. ATtiny85 Datasheet
  9. ATtiny13A Datasheet

pic5.jpg

License

license.png

This work is licensed under Creative Commons Attribution-ShareAlike 3.0 Unported License. (http://creativecommons.org/licenses/by-sa/3.0/)

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].