Close

Theory of Operation

A project log for Attiny High Voltage Fuse Reset-er

I've started playing around with the Attiny series of chips but want a way to recover them in case of bad fuse settings

sjm4306sjm4306 04/14/2022 at 14:380 Comments

In my recent projects moving to the Attiny series of microcontrollers, I've found a need to be able to reset chips I've accidentally "bricked" through incorrect fuse settings that prevent low voltage serial programming. So in this video we take a look at a pcb I designed based on work by Paul W (https://www.rickety.us/2010/03/arduin...) and Jeff Keyzer (https://mightyohm.com/blog/2008/09/ar...). Huge thanks to Paul and Jeff for their software and hardware which this project wouldn't be possible without.

So the design is fairly straight forward, it's basically just an onboard atmega328p that is programmed to bitbang the serial programming protocol for reading/writing fuses to the attiny series of chips. The gotcha is to reset fuses for chips that have had serial programming disabled or the reset pin set as a gpio you need to place the chip into a high voltage programming mode. This is achieved by pulling the reset pin high with 12V instead of the normal method of pulling it to ground from vcc. So in addition to the atmega we also need a 12v supply (well technically 11.5-12.5V will do according to the datasheet).

I can do this easily by powering the whole circuit from a 12V DC wallwart and use a cheap linear regulator to generate 5V for the logic but it's a bit inconvenient to need a separate supply adapter. So I opted to generate the 12V onboard from the USB power input jack. There are quite a few ways to accomplish this but I wanted to try my hand a closed look compensator design. I could've gone with a switched cap converter but in the end I designed a boost converter around discrete components. Controlling these components is the same atmega that's doing all the serial control of the slave attiny chip. I accomplish this by using a timer interrupt to calculate the PID output at a 2kHz sample/computation rate. PWM frequency is selected to be as fast as possible to decrease required component size, and with the atmega this comes to around 32kHz at 8 bit resolution.

PID calculation in the interrupt is fairly simple/conventional:

//executes at 2kHz via interrupt, execution takes ~140uS, all voltages in mV
  
  ADCSRA |= (1<<ADSC); //start conversion
  while((ADCSRA>>ADSC)&0b1){;}  //wait till conversion done

  //measurement=supply*fbgain*((double) analogRead(FB)/1024);  //in mV
  //precalculate mult=supply*fbgain/1024 to speed up calculation
  measurement=mult*ADC; //grab 10 bit measurement

  //Max voltage on reset pin is 13V
  if(measurement>13000){   //safety net, cut pwm if voltage rises above 13V
    OCR1A=0;
  }
  
  error=reference-measurement;  //calculate error and I,D terms
  integral+=error;
  derivative=error-last_error;
  
  if(integral>limit){integral=limit;}    //set term limits to prevent excessive windup
  if(integral<-limit){integral=-limit;}
  
  if(derivative>limit){derivative=limit;}
  if(derivative<-limit){derivative=-limit;}

  output=p_gain*error+i_gain*integral+d_gain*derivative;

  if(output>240){output=240;} //limit output within pwm control range
  if(output<0){output=0;}

  OCR1A=output;  //set pwm value to calculated output
  last_error=error;  //update last error value

The analog voltage at the 12V rail must be measured by the atmega, this is handled by using a voltage divider (iirc I used 10K and ~20K resistors to safetly drop the output by a gain of ~0.3, within the 0-5V range of the atmega ADC). The software multiplies by the inverse of this gain in order to calculate the unscaled original voltage.

 This compensator runs continuously shortly after power is plugged in and will constantly adjust the boost converter output to 12V. There is an additional transistor on the 12V output which allows the atmega to set the attiny's reset pin to either 12V or 0V.

When the start button is pressed the atmega reads the device identifier for the chip to determine what slave chip is attached and thus can look up the correct fuse settings. It will then read the current fuse values, program the new ones and then read back the values to make sure they were programmed correctly. If anything doesn't match the display show's an error and the buzzer will beep three times to notify the user.

I utilize hardware I2C to write to the 0.91" 128x32 OLED display with a graphical driver software I've written in the past. From the original example HV programmer software I used based on Paul W's and Jeff Keyzer's work, the uart serial interface remains intact so opening a serial terminal with the device connected over usb will still show their original interface. I just added the PID control, OLED, Button and Buzzer software to make it operational standalone without a computer. Finally the circuit is based off the schematic found on Paul's site, except for the additional connection to the attinyX4 series of chips, the discrete boost converter circuitry and the additional OLED/button/buzzer. I designed the pcb in Eagle and ordered via JLCPCB.

Discussions