High Voltage Coils

electrical and mechanical engineering

Home - Category: low voltage experiments

Category: low voltage experiments

How to use Atmel’s “atprogram” cli command line interface to program a production file into an xmega

Posted on 12. September 2017 in low voltage experiments

Hi all,
a very long headline for this simple task, but it hits the spot! Former Atmel (now Microchip) provides a very powerful back end programmer, intended to be used within a production line, to automate the programming process, without having to use Atmel Studio.

What are the benefits of using a production file? Very simple, have the user signatures, eeprom, flash and fuses combined in a single file. Then write a little batch script to burn this elf image into multiple micro controllers.


1.) How to generate a production file?

Open your project with Atmel Studio, then enter the “Device Programming” dialog. There is a own tab called “production file”. Use the lower half of the dialog, below the “Save to ELF production file” line. Choose a valid hex file for the flash, optional a eeprom and user signitures file. Then choose which of the files should be stored from the check boxes. Note that it is also possible to store the fuses and lockbits. If checked, the fuses and lockbits of the currently connected micro controller will be stored, so make sure they are configured correctly. Click on the “Save” button to store the production file.


2.) How to flash a production file from Atmel Studio?

Test your production file by using the upper part of the dialog. Enter a filename into “Program device from ELF production file”. Next choose which part of the production file you want to flash, all none existing parts will be grayed out and are not select able! Click on “Program” to flash the whole device with a single mouse click, very handy 😉


3.) How to flash a production file from a batch scrip without Atmel Studio?

Create an empty text file and name it “start_flash.bat”. Copy the textfile provided below, alter your device and tool, then start flashing.

@echo off
cd "C:Program Files (x86)AtmelStudio7.0atbackend"
atprogram -t atmelice -i pdi -d atxmega32a4 program -c -fl -fs --verify -f "d:mytestfile.elf"

After execution will result in the following console output.


A little bit of explanation:

“@echo off” will silence the console directory output after each script command, when removed, the result will be much more unreadable

“cd” will change the directory to the atbackend path of the Atmel Studio installation folder, make sure this folder matches your installation path

“c:” is just here for the purpose if you start your batch script from a different drive then c:

“atprogram” is used to do the heavy lifting
“-t atmelice” means which tool i want to use, enter “atprogram list”  to see all available tools, for example my output
simulator       No serialnumber found
atmelice        J41800059125
“-i pdi” means i want to use the pdi interface for programming
“-d atxmega32a4” is my target microcontroller

“program” means i want to flash the contents of a file
“-c” perform a chip erase
“-fl” write flash
“-fs” write fuses
“–verify” after programming, memory contents need to match the target file
“-f <filepath>” this is my production file

4.) I want additional information about the features of atprogram!

use the console commands
“atprogram help” to get a full list of features.
It is also possible to get additional information about a single command, for example
“atprogram help program” will give you detailed information about all command line parameters available for the “program” command.

Fix android black screen while telephone call, unable to end call

Posted on 9. August 2017 in low voltage experiments

Hi all,

recently i had a serious problem with my Android Sony Xperia Z3. Everything is working perfectly, but as soon as i receive a call and i accept it, the display turns off and i am unable to use the phone. After doing a little research, it seems this is quite a common problem for the Xperia phones.

The reason is very simple, there is a proximity sensor on board, which detects if the phone is held to the ear. If so, the display will turn black, to prevent accidentally pushing any buttons (like dismiss call ).





How did i manage to fix this issue?

1.) Hotfix to be able to use the phone and end a call, even with black screen


Enable “Power button ends call”

2.) Do a hardware test and see if the sensor is working

Settings -> About phone ->Diagnostics->Test -> Ear proximity

3.) Lucky in my case the sensor is working, but only if i apply pressure to it, doing so i found out that the display is loosing connection to the housing. If there is a gap between the sensor and the display, it will not work correctly, so time to glue the display to the housing.

4.) get a cheap replacement “display seal” from ebay (look for “xperia z3 klebedichtung” in german)

5.) Switch off the phone, clean the whole display on the outside

6.) Carefully heat up the front plate with a hairdryer, remove the front display.

7.) Clean all sensors on the inside

8.) Put in the new seal and press the cleaned display to the housing to have a solid connection

9.) Turn on the phone and see if everything is working again 😉



setup raspberry pi with spdns – secure point DNS

Posted on 14. February 2016 in low voltage experiments

Hi folks,
my ISP is changing my IP address once a day, but still i wanted to connect to my raspberry pi homeserver from the internet. After some experimentation time i found a nice solution to work with.

1.) Register and setup spdns
Register as a new user at spdns.de
Setup a new virtual hostname for example “myhost.spdns.eu”

2.) setup a little python script
I downloaded a script from the user “mmichaa” python_script
and altered the main function of the script

def main(argv):
	if len(argv) != 4:
		print ''
		print "tUSAGE: " + __file__ + ' <hostname> <user> <passwd>'
		print ''
		return None
	hostname = argv[1]
	user = argv[2]
	passwd = argv[3]


def main(argv):	
	hostname = 'myhost.spdns.eu'
	user = 'myusername'
	passwd = 'mypassword'

so you do not need to provide the username and password as command line parameters.

3.) setup a cron job to automatically start the script
alter the cron configuration by entering

sudo crontab -e

add a new line at the end of the document

@hourly python /home/pi/spdns-client.py

test the script

sudo /etc/init.d/cron restart



Rescue a DNT DigiMicro C11 Digital Microscope from scrap

Posted on 18. December 2015 in low voltage experiments

There is a very simple way to get an old DNT DigMicro C11 camera working in Windows 8.1. The company DNT has moved on with a newer products like the “DigiMicro Scale 2.0” link to product page , but stopped support for older products. Unfortunately the newer software does not recognize the old hardware, so i found a way to make this product working on a modern system (W8.1).

In the device manager, the camera hardware id was detected as:


The valid driver for this camera is “SN9C201” from Sonix Inc.
download the driver file (USB20PCCam_5.7.26000.0.exe) from the link below USB20PCCam_5.7.26000.0.exe


the device will be detected in the device manager

To display the image i used the VLC Mediaplayer, available from http://www.videolan.org. Open the player and use the function “CTRL + C” open device. Set the mode to “Direct Show”, device to “USB2.0 PC Camera (SN9C201)” and the audio to “None”, this step is mandatory or it will not work correctly!


The device works perfectly


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.