High Voltage Coils

electrical and mechanical engineering

Atmel xmega signal / sinusgenerator using DAC

Posted on 14. December 2015 in low voltage experiments

Hi all,

after several thoughts about how to create a sound with an xmega32a4 microcontroller from ATMEL, i detected two easy approaches to stick to, PWM (puls width modulation) or DAC (Digital Analog Converter). After thinking about the most flexible approach, i choose the DAC.

My code consists of 3 parts.

  1. static sinus lookup table, precalculated 12bit values, stored in a 16 bit word array
  2. A timer, which is acting as the sample rate clock, for example 48kHz
  3. The DAC, which will receive new values if the timer overflows

The hardware wiring is very simple, PORTB2 (DAC Channel 0 output) directly connected to an audio amplifier.

DAC working at 48kHz sample frequency

#include <avr/io.h>
#include "driver/avr_compiler.h"
#include "driver/driver_clksys.h"

const uint16_t sin1kHz[48] = {2048,2315,2578,2831,3071,3294,3495,3672,3821,3939,4025,4077,4095,4077,4025,3939,3821,3672,3495,3294,3072,2831,2578,2315,2048,1781,1518,1265,1025,802,601,424,275,157,71,19,1,19,71,157,275,424,601,802,1024,1265,1518,1781};

uint8_t idxsin = 0;
#define MAX_IDX 48

ISR (TCC0_CCA_vect)
{	// Timer overflow, put next sample into DAC
	DACB.CH0DATA = sin1kHz[idxsin];
	if (idxsin >= MAX_IDX) { idxsin = 0; }

int main(void)

	Config32MHzClock(); // set systemclock to 32MHz

	TCC0.CNT = 0; //Reset timer 0
	TCC0.PER = 167; // 21us @ 32MHz = ~48kHz
	TCC0.CTRLA = TC_CLKSEL_DIV4_gc; // Prescaler
	TCC0.INTCTRLB = TC_CCAINTLVL_LO_gc; // TCC0_CCA_vect, Compare Match


	DACB.CTRLB = 0x00; // single channel operation PB2 only
	DACB.CTRLC = 0x08; // Vref = Analog Supply Voltage
	DACB.CTRLA = 0x04; // CH0EN = Enable Channel 0
	DACB.CTRLA |= 0x01; // ENABLE = Start the DAC




1kHz @ 48kHz measured at uC output

The result is not bad, but feeding this to into my amplifier without additional filtering, results in  disturbing crackling noises. To reduce the “stair” effects, i choose to increase the sample frequency from 48kHz to 100kHz.

DAC working at 100kHz sample frequency

To make this work, i just need to reconfigure the timer parameters and sinus lookup table.

const uint16_t sin1kHz[100] = {2048,2177,2305,2432,2557,2681,2802,2920,3034,3145,3251,3353,3449,3540,3625,3704,3776,3842,3900,3951,3995,4031,4059,4079,4091,4095,4091,4079,4059,4031,3995,3951,3900,3842,3776,3704,3625,3540,3449,3353,3251,3145,3034,2920,2802,2681,2557,2432,2305,2177,2048,1919,1791,1664,1539,1415,1294,1176,1062,951,845,743,647,556,471,392,320,254,196,145,101,65,37,17,5,1,5,17,37,65,101,145,196,254,320,392,471,556,647,743,845,951,1062,1176,1294,1415,1539,1664,1791,1919};

uint8_t idxsin = 0;
#define MAX_IDX 100

ISR (TCC0_CCA_vect) 
	DACB.CH0DATA = sin1kHz[idxsin];	
	if (idxsin >= MAX_IDX) { idxsin = 0; }

int main(void)

	TCC0.CNT = 0;
	TCC0.PER = 157;	 // 10us @ 32MHz = ~100kHz	
	TCC0.CTRLA = TC_CLKSEL_DIV2_gc; // Prescaler
	TCC0.INTCTRLB = TC_CCAINTLVL_LO_gc; // TCC0_CCA_vect, bei Compare Match
	DACB.CTRLB = 0x00; // single channel operation PB2 only
	DACB.CTRLC = 0x08; // Vref = Analog Supply Voltage
	DACB.CTRLA = 0x04; // CH0EN = Enable Channel 0
	DACB.CTRLA |= 0x01; // ENABLE = Start the DAC


1kHz @ 100kHz measured at uC output

The result is not perfect, but the sinus at the amplifier output is completely clean, without any additional sidebands or crackling noises.


signal after amplification measured at the loudspeaker

Performance measurements showed, the CPU load is at ~17% (time between samples = 10us @100kHz, time in ISR = 1,7us), which means that in theory, the sample rate may be pushed to 400kHz. For a better performance, i would recommend using the xmega DMA. A good implementation can be found at the AVR Xplain , Atmel AVR1508: XMEGA-A1 Xplained training – XMEGA DAC document, chapter “Task 4”.

Raspberry Pi weather station

Posted on 9. November 2015 in low voltage experiments

Hi folks,
i have the need, to see the temperatures at my home place from a remote location. While surfing the internet, i found a quite simple solution to retrieve the temperature, humidity and air pressure from a sensor hooked up to a raspberry pi.

Hardware needed:

Software architecture:

The data acquisition software is written in python and runs as a service on the raspberry pi. Parts of the software are based on the BME280 script, provided by Shinichi-Ohki link to repository.

Every 10 minutes, data is gathered, and then being transmitted to a database via an URL GET request in the format (mypage.php?temp=25&druck=1028&feuchte=23).

The php script reads out the parameters, provided in the request, does a validity check and if succeeds, inserts the data into a mysql database.

For easy readout of the data, an html site provides an interface to the database. It displays the average temperature of the last 30 minutes and a line chart containing the values of the day.


The software ran in test mode in my home lab for about 2 weeks without problems. Since 8th of November 2015, the hardware was installed at it’s final destination on the attic. The raspberry is housed in a case mounted to the wall on the inside, while the sensor is connected to 1 meter of wiring, residing on the outside.

If this system performs good in real life situations, i am looking forward to improve the software, so i can run a little monthly statistic. But for now all major features i need are implemented.


Ural butt warmer for the cold months

Posted on 18. October 2015 in Motorcycles

Hi folks,
brace yourself, winter is coming. To prevent myself from freezing while winter driving, I decided to tune my motorcycle with a seat heater, alias “butt warmer”.
This modification if very simple, but took some time to make it practical in terms of usability and maintenance.

List of materials:

  • heating element, 12V – 38W, 320x137mm, link to shop
  • automotive fuse, 10A
  • automotive water resistant connectors, 2 pins from ebay (AMP superseal)
  • switch rated 6A with protective cover
  • scrap metal and a little box as housing

This is the schematic. The box contains an LED, which is used to indicate the status of the heating element. Because the switch is not connected to the ignition key, the heater will continue working, even if the motorcycle is not running. A problem of this wiring scheme, if you forget to turn of the heater, it will completely drain the battery!
Advantage of this scheme is the ability to directly hook up a charger to the battery, without needing to remove the battery from the vehicle.


Put everything in a little box, seal it, so the box is waterproof. Also add two connectors, male and female, so accidentally cross the wires is excluded. If you cross the wires, you will see the result, because the LED is always on, the heater will be able to be switched on and off normally.


Put the heating element on top of the seat, seal it with protective cover and solder a connector to it.


Hide the connector to the battery underneath the box (to loosen the box, only 2 screws need to be removed). Leave the connector to the seat above, to it can be easily disconnected.


Riding with the heater:
My first impression was very bad. I soldered everything together, threw the switch and nothing happened. After 2 minutes the heat started, but just by touching it with my hands, it felt very cold.
So i decided to do a little test ride, with outside temperatures of about 12 – 5 *C. I was wearing a jean and on top of it protective trousers. The system works perfectly, even trough the large amount of clothes! Because of the large heating area and directly sitting on the pad, it takes about 1 minute to heat up. After 3 minutes i needed to switch it off, because the temperature was very hot 😉
Because of the mounting position, i can directly switch the heater on while driving with ease. Switching off is even simpler, because by closing the protective cover, the switch will also move to off position.

This modification is very simple, works great, costs about 50€ and a weekend with some free time. It’s a good addition for winter drivers and may be removed in about 20 minutes.




Jacobs ladder and steel wool

Posted on 9. October 2015 in high voltage experiments

This article displays just some pictures made from a simple two wire jacob’s ladder with steel wool cover. The steel wool ignites and creates hot arrows shooting from the center of the spark gap.


a single spark climbing up the ladder, but with longer light exposure


the spark is igniting the steel wool


steel wool wound up to an isolating stick, arking to a metal plate


Small Tesla Coil – 0,5 m height – 20W

Posted on 9. October 2015 in high voltage experiments

Some pictures from my smallest Tesla coil, driven by a fly back transformer from an old TV and a 555 timer IC. This machine works at about 15kHz, and drives a single IGBT450 FET, with an operation Voltage of about 12V.

Light bulb lit without wires attached

small arks from the top ~15cm

additional arcs, the lamp in the background is lit, although it is not switched on




Tags: , ,


Ural Ranger / Gear Up electronic interface for onboard diagnostics

Posted on 9. October 2015 in Motorcycles

Hi Folks,

i did some research on the electronics of my sidecar, a URAL Ranger ( or Gear Up in the US) model year 2014. This machine uses an electronic fuel injection (EFI) instead of a standard carburetor. Unfortunately this means some additional reverse engineering to get full access to all aspects this machine.



1.) Which connector is being used?

The “protection” cap is also a working connector, but i didn’t want to use it, so i ordered another one from RS-components. (RS order number 511-0168)

Molex MX150L – 6 Pole  /  MOLEX 19418-0011
link to shop

In addition to the connector, it is mandatory to insert the pins. (RS order number 511-0067)
link to shop


2.) How to connect to a remote OBD device?

I used a OBD (on board diagnostics) cable extension 1m from ebay, which i cut in half and soldered the pins according to the schematic below


Molex connecter – OBD Pins

2 CAN LO – 14 CAN LO
3 BAT GND – 4 chase GNDand 5 signal GND
4 BAT + – 16 Supply Voltage

resulting in the following cable



3.) Readout data from the motorcycle

For reading out the data i am using a DIAMEX Scandevil. This is a handheld ODB scanner, so no additional software is needet to read out data from the motorcycle. It is also possible to insert a SD card and store sensor values directly on the flash drive, while riding the bike.

link to manufacturer


My first tests worked out great, i was able to detect both EFI units, read out the sensor values like RPM, outside temperature and ignition timing.