Calendar

December 2018
M T W T F S S
« Nov    
 12
3456789
10111213141516
17181920212223
24252627282930
31  

Categories

Active supporter of WikiPedia
Support Wikipedia

Geocaching

Profile for uwezi

A tiny watchdog

In a recent quick-and-dirty project with a Wemos D1 mini clone I had some problems with the reliability of the code. The ESP8266 contains two watchdogs which have the sole purpose to reset the chip if the firmware ever should get stuck. Previously I experienced these watchdogs to be too aggressive, but this was not the case now.

In this project I send sensor data directly to an MySQL database using Chuck Bell’s library, but once in a while the code would get stuck. From a debug LED I know that this happens while executing the MySQL INSERT query. How is this possible? Well, the watchdogs must be fed somehow in spite of the code hanging, and there is no built-in timeout either.

On Facebook it was suggested to build an external watchdog. This evening I now finally considered first to use a 74HC123 monostable as a trigger for the reset of the ESP8266 if the debug LED stops blinking. But then I reconsidered and grabbed an ATtiny13A out of my box and wrote a small program.

The watchdog timeout time can be set externally by means of the three pins PB[2:0] as a three bit number, where the actual time is (n*2+1) seconds, i.e. between 1 s and 15 s. Triggering the watchdog is done by toggling the pin PB3, each transition 0-1 and 1-0 restarts the internal timeout.

/*
 * 20181206_tiny13_watchdog.c
 *
 * Created: 2018-12-06 21:48:06
 * Author : uwezi
 */


#define F_CPU 1000000UL
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>

volatile int8_t timeout, count;

ISR(PCINT0_vect)
{
  count = timeout;  
}

ISR(TIM0_COMPA_vect)
{
  count --;
  if (count <= 0)
  {
    count = timeout;
    PORTB &= ~(1 << PB4);
    _delay_ms(200);
    PORTB |= (1 << PB4);
  }
}

int main(void)
{
  DDRB   = (1 << PB4);
  PORTB  = (1 << PB4) | (1 << PB3) | (1 << PB2) | (1 << PB1) | (1 << PB0);
 
  timeout  = (((PINB & 0b111) << 1) + 1) * 4;
  count    = timeout;
 
  PCMSK  = (1 << PCINT3);
  GIMSK  = (1 << PCIE);
 
  OCR0A  = 243;   // 4 Int/s
  TCCR0A = (1 << WGM01) | (0 << WGM00);
  TCCR0B = (0 << WGM02)
         | (1 << CS02) | (0 << CS01) | (1 << CS00);
  TIMSK0 = (1 << OCIE0A);
 
  sei();      

  while (1)
  {
    timeout  = (((PINB & 0b111) << 1) + 1) * 4;
    _delay_ms(500);
  }
}

Hacking IKEA trådfri lighting automation

I recently visited IKEA again and got interested in their affordable line of home automation/LED lighting products called TRÅDFRI (meaing wireless in a play-with-words kind of Swedish). Of course there was already an internet community active in hacking these devices and I joined in.

Getting started

I installed the gateway and after pairing devices […]

Continue reading Hacking IKEA trådfri lighting automation

project update: a TTL/CMOS computer

Exactly one month later – our electronics course at Uppsala University just approaches its end – and I got the next shipment for my new project: 1.1 km of equipment wire.

new project: a TTL/CMOS computer

Watching Ben Eater’s youtube series on his breadboard computer based on discrete logic chips inspired me to pursue my own construction. Apart from a lack of time I also needed some more breadboards, which arrived today.

twenty new […]

Continue reading new project: a TTL/CMOS computer

A visitor on the balkony

http://www.sciencetronics.com/greenphotons/wp-content/uploads/2018/02/20180226_balkong_malmabacke.mp4

Top deal of the week?

Today I received a newsletter from the publisher Elektor. I am offered a special deal on a Peltier power generator which can power an LED light from a small candle. And this for an astonishing price of €99.95 instead of the normal price of €119.95.

Great offer from Elektor.

I’ll have to buy […]

Continue reading Top deal of the week?

Troubel with Telia – again

Sorry, this entry is only available in Svenska.

240×320 TFT with touch on an ATmega328

It’s been a while since I purchased some TFT modules on eBay. These modules come in different sizes and two varieties – with and without integrated touch controller XPT2046. The controller in the TFT display itself is an ILI9341 wired up to be controlled by SPI.

240×320 pixel TFT display with integrated resistive […]

Continue reading 240×320 TFT with touch on an ATmega328

Replacing three remotes

Idea

You know the problem – with every new gadget comes a new remote control, and while there are programmable and universal remote controls out there, they will never just do what you want.

The three main remotes in my living room.

For controlling my tv, my digital box and one of the […]

Continue reading Replacing three remotes

(Deutsch) Ach Ihr schon wieder

Sorry, this entry is only available in German.