Turn-key PCB assembly services in prototype quantities or low-volume to mid-volume production runs

Why to move from ASM to C

ASM language is a low level programming language. It takes tons of time to develop embedded programs. Now even 8 bit microcontrollers arent as smal as they were earlier. The program memories are climbing to megabyte(s). Program structure becoming more complicated because of bigger functionality demand. This is why it is better to use higher level programming languages like C. By using C language you are not overwhelmed by details. You don’t have always to think about hardware logic to be able to program its restricted tasks. It is better to give this work to C compiler which helps you to avoid bugs in silicon level. Another C language benefit against ASM language is portability. Lets say you work on one embedded system architecture and decide to move to other maybe more advanced. If your previous program were written in ASM language, then you will need to rewrite (modify) this code from scratch. Using C language you are able tu run program on different microcontroller without significant modifications. This also reduces the costs of your project upgrade. Continuing the thought it is good to mention, that using C it is easy to save specific hardware routines to libraries which are…

Continue reading

Shelling The Intel 8-bit Hex File Format

Intel 8-bit Hex File Format is the most common hex file format used in the world as far as I know. There is also Motorola Hex file format and maybe other. Creating applications with AVR-GCC we usually select ihex output file format what means Intel hex file format. Lets go through it and see whats inside. It is simple as 6 and 6 (six and six), because each Hex file line consists of six parts. And there can be 6 record types in hex file. Lets go through all six parts of each line: Start code is always character ‘:’; Byte count takes one byte (hex pair) indicating a number of bytes in a data field of the lin. Usually there are 16 or 32 bytes of data in each line; Address takes two bytes (16 bits – four hex digits). Address shows the beginning of memory position for the data. 16 bits gives a limit of 64kilobytes. This is worked around by specifying higher bits via other record types; Record type takes one byte (two hex digits). It defines the type of data field; Data is a sequence of n bytes (2*n hex digits); Checksum is one byte (two…

Continue reading

Easy start with AVR EEPROM using WinAVR

AVR microcontrollers are loaded with some amount of EEPROM (Electronically Erasable Read-Only memory ) memory. This is handy feature allowing developers to store program parameters like service information, constants, menu strings etc. Atmel states that AVR EEPROM memory can be rewritten over 1000000 times. Reading is unlimited. In this article I am going to show how to store data to EEPROM by defining a variables. For this we need to include eeprom.h header from avr directory (#include “avr/eeprom.h” ). Then we can just write simple variable declaration using simple attribute EEMEM: #include “inttypes.h” #include “avr/io.h” #include “avr/iom8.h” #include “avr/eeprom.h” //store initial byte to eeprom uint8_t EEMEM eeprombyte=0x10; //store initial word to eeprom uint16_t EEMEM eepromword=0x5555; //store string to eeprom uint8_t EEMEM eepromstring[5]={“Test\0”}; int main(void) { //RAM byte variable uint8_t RAMbyte; //RAM word variable uint16_t RAMword; //RAM array of bytes uint8_t RAMstring[5]; //read byte from EEPROm and store to RAM RAMbyte = eeprom_read_byte(&eeprombyte); //read word from EEPROM and store to RAM RAMword = eeprom_read_word(&eepromword); //copy string fro mEEPROM to RAM eeprom_read_block ((void *)&RAMstring, (const void *)&eepromstring,5); return (0); }   EEMEM keyword indicates to compiler that variables are stored in EEPROM and it creates separate .eep file which has to be…

Continue reading

Signal sampling mechanism

Sampling is a process when continuous time signal is represented by series of discrete samples while reconstruction is reverse process when these samples re recreating adequate continuous time signal. Bellow the overall process is illustrated. Sampling is a process when continuous time signal is recorded every T seconds by multiplying by an impulse train. If signal is sampled in frequency domain. For this we need signal transformed in to frequency domain. The frequency spectrum has to be band-limited. The impulse train after transformation becomes impulse train with scale in heigh 1/T. Multiplication in time domain becomes a convolution in frequency domain. After convolving the signal is scaled and shifted. The signal in frequency domain becomes periodical. In order to reconstruct the signal x(t) from sampled spectrum first we need to extract the original spectrum. For this ideal filter is needed to take single spectrum from spectrum signal train. Low pass filter fill cut other copies of spectrum. The filter should have cut off at f=±1/(2T) and Gain of T: After this reconstruction can be done. Ideal filter in frequency domain is a sinc function in time domain. This means that multiplying spectra by box in frequency domains means convolving with…

Continue reading

RS232 interface standard overview

This is pretty old standard but stil widely used in embedded systems. Using RS232 interface standard the ata is sent bit by bit. Usually first comes LSB. Receiver receives data by knowing the position of each data piece and delay. In order to ensure the quality of data transmission, we need to control the start of transmission. This is done by acknowledgment procedure. Lets take assymetrical type of interface RS232-C. Transmitter sends RTC (request to send) signal to receiver. In other hand receiver detects this signal, finishes previous operation and then sends to receiver CTS (clear to send) signal, what menas that receiver is ready to accept data. Without CTS transmitter cannot start data transmission. Note: In RS232 interface logical “1“ corresponds to voltages from -3V to -12V and logical “0“ corresponds to voltages from +3V to +12V. The logical level in interval -3V to +3V is undefined. Lets take some example. If we want to send byte 1100111011 This byte is sent assynchronously. This means that receiver doesn’t know when transmitter will start sending data. But anyway there is some means needed to inform about the start of transmission. For this is START bit used at the beginning of…

Continue reading

AVR watchdog reset timer-practical approach

This is continuing of thread Why use watchdog variable timer. This post is about how watchdog timer on AVR microcontroller works and how to control it. As we mentioned earlier, watchdog timer is a distinct timer counter, which generates reset signal when it fill up. After watchdog timer counts up to maximum, it generates a short pulse duration 1 clock cycle. This pulse triggers internal reset timer counting up to tout. AVR watchdog timer is distinct clock generator which runs at 1 MHz. Watchdog timer has a prescaler module. So reset interval can be selected by adjusting the prescaler. Generally there are three things you have to do while controlling watchdog timer: enable, disable, and set prescaler. First of all we need to set watchdog timer prescaler. Prescaler settings can be set in WDTCR(WatchDog Timer Control Register) register(Atmega8). Prescaler is set by setting three bits (WDP2, WDP1, WDP0) of WDTCR register(see table bellow): In order to be able to control watchdog timer, there some logic needs to be preserveed. In order to enable watchdog timer just set WDE bit in WDTCR. Disabling and setting prescalelr is more complicated because some sequence of operations has to be made. Write „1“ to…

Continue reading

Why use watchdog variable timer

Most of embedded microcontrollers contain watchdog timer. Watchdog variable timer is literally a „watchdog“. Watchdog timer continuously inspects the program float. Basically if microcontroller program hangs, then watchdog timer resets it and brings embedded system back to life. The idea is very simple. Lets say, you know, that your program has to be executed during 20ms. And you know that worst case scenario is 30ms. Then you set watchdog variable timer connected to highest priority interrupt – RESET. Once Watchdog timer is triggered, timer counts up to time you set and then it resets the MCU. The only way to avoid reseting is to send command to watchdog timer to start counting over. Technically watchdog variable timer is nothing more that retriggerable one shot multivibrator. The use of watchdog timer may be various. The one mentioned above is like a program execution loop. Once all procedures are performed, the MCU resets and starts over. Another more valuable and mostly used is for system reset if code failure occur. You may set some flags indicating was procedure successful or not. If not, than you can fire watchdog timer to restart MCU and start over. The only problem with watchdog timer is…

Continue reading