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

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

How to use inline ASM using WinAVR

I have been working on optimisation of one of my C codes. I needed one function to be as optimal as possible. I decided to use inline ASM to achieve this. I decided to write few lines about this. There are few rules that is necessary to follow. Each ASM statement is divided by colons into 3(up to four parts): Assembler instructions part; A list of output operands (comma separated); A list of input operands (comma separated); Clobbered register – usually left empty.

Continue reading

Marking of AVR microcontrollers

There is quite big variety of AVR microcontrollers that ATMEL company produces. This article is about how to Extract information about AVR microcontroller using its marking on package. Each microcontroller has its own mark on package: numbers and letters. First is microcontroller type. After follows suffix of three fields. First field is one or two digits what indicates maximal operation frequency MHz. Second field is a letter showing package type. And third field shows the temperature range of working environment. There are couple more marking letters „L“ and „V“ after microcontroller type. This means that microcontroller operates at low or very low voltages (and frequencies of course). Table of microcontroller packaging types Letter Package Lead Pitch (mm) A TQFP 0.8 J PLCC 1.27 M MLF 0.5 P PDIP 2.54 S SOIC 1.27 Y SSOP 0.65 There are two types of operating temperature ranges: Letter T, ºC C 0…70 I -40…+85 And couple examples at the end: Marking VCC, (V) Fmax, (MHz) Package Attiny15L-1PI 2.7-5.5 1.6 8pin PDIP Atmega64-16AI 4.5-5.5 16 64lead TQFP Atmega325V-8MC 1.8-5.5 8 64lead MLF Attiny2313-20SI 2.7-5.5 20 20lead SOIC

Continue reading

AVR controlled DDS generator software writing

During my spare time, I am developing the program for the AVR controlled DDS generator. I decided to write software using WinAVR tool-set. How far ahead I have moved with this? I have implemented: Menu system; Reading previous generator configuration from EEPROM; Setting signal mode; Storing last generator configuration to EEPROM to be loaded after reset; Four types of signal output (square, sawtooth, triangle and sine wave); Things I still need to do: Ability to change signal frequency; Implement other signals (listed below); Make program clean-up; Signals in AVR controlled generator: 0 – OUT_|¯|_ – square wave(done); 1 – OUT|/|/| – sawtooth(done); 2 – OUT|\|\| – reverse sawtooth(awaiting); 3 – OUT/\/\/\ – triangle(done); 4 – OUT~~~~ – sine wave(done); 5 – OUT-NOISE – noise signal(awaiting); 20 – PWM-OCC – timer output compare mode(awaiting); 21 – PWM-SINMDS  sine wave modulated PWM(awaiting); 22 – PWMSQSMDS – sine wave modulated PWM. PWM positive, SQ  negative polarity(awaiting); 23 – PWM-CMDS – custom PWM. Will be possible to set custom duty cycle(awaiting); Signal generation Square, sawtooth, triangle and sine waves are generated by reading values from flash memory. Fragment of the sine wave is as follows: //———————————————– //signals saved in flash memory const uint8_t sinewave[]…

Continue reading

Reading AVR button status using WinAVR

If you want to bring some interactivity to your embedded projects, one option is to add buttons. This allows you to control program flow, set parameters and much more. Few words about AVR ports. AVR Port pins can be configured as input or output. See table for all general pin configurations: DDRx register is so called direction register; PORTx – is port output register; PINx – is pin input regsiter; So there can be three options for input and two for output. If you are doing some simple routines with AVR microcontrollers, you maybe are familiar with configuring output from port. Just write ‘1’ to DDRx register and then send data to PORTx register: For instance: DDRD=0x0F; //sets lower nibble as output; PORTD=0x05 //output ‘1’ to PORTD pins 0 and 2; If you want to read input signals there are normally couple ways to do this. For input DDRx register always should be set as input ‘0’ pin values. PORTx register can be set in two ways: If PORTx is set to ‘1’, then internal pull-up resistor is enabled depending on PUD bit in SFIOR register. If PORTx pin is set to ‘0’ then internal pull-up is disabled despite PUD…

Continue reading