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

Oscillator frequency and code speed

One of important questions you ask when considering microcontroller project is wat oscillator frequency to choose. Usually it depend desired level of performance. In general application speed is directly determined by oscillator frequency. If you double the oscillator frequency, the application will rin in double speed. But wee do not compare different processors by frequency, but by other quantity – MIPS (Million Instructions Per Second). Why it is so? Because different MCU require different clock cycles for performing one operation. For instance AVR microcontrollers require 1 (some 2) clock cycles for one instructions while Intel 8051 microcontrollers require a minimum of 12 oscillator cycles. So if Clock frequency is 12MHz then 8051 microcontroller will work at performance of 1 MIPS. AVR microcontroller which uses 12MHz crystal will work at about 12 MIPS. But do we always need maximum performance? Many developers like to select maximum oscillator value that is supported by selected MCU. For instance if Atmega128 supports 16MHz frequency, then many people automatically choose values near to this value. Sometimes it is bad practice because: Many applications do not require high level of performance that microcontrollers can provide; In many CMOS based MCU there is almost linear relation between…

Continue reading

Use neural sensors to build smart sensor systems using microcontrollers

Neural networks are a broad topic. But this small example demonstrates how to create a primary neural sensor which takes resistive readings from multiple sensors and multiply it by weight factor and then sum the results. Results are compared to three level threshold. Without going too deep into neural networks, we can say, that neural cell thresholds are similar to natural biological neurons. For instance pain levels: itch is a low level of pain while burning sensations are combined with cold and warm feelings. Neural sensors can operate in the same way. Let’s take typical neural sensors which consist of two inputs with some weights and three outputs. Depending on the threshold level that the sum of inputs gives – we have an output signal on one of three outputs. Let us build real-world neuron with two inputs and three outputs. As a sensor, I will use potentiometers which can be replaced by photocells or temperature sensors. According to these two sensor readings, a neuron can have three states: low medium high This could be like low light, medium light and high light, o low temp and so on. If you decide to put neuron to your robot, this could…

Continue reading

Sample routine of working with LPT1 port under windows XP in CPP language

This is simple routine of sending and reading of byte from LPT1 port under Windows XP. LPT port has four types of pins: 8 output pins accessed via the DATA Port 5 input pins (one inverted) accessed via the STATUS Port 4 output pins (three inverted) accessed via the CONTROL Port The remaining 8 pins are grounded Now we are interested in Data pins. Set up driver according to post: Acces LPT and COM ports easily under windows NT-2000-XP. I have written and compiled example under DEV-CPP tool-set, which you can download from https://www.bloodshed.net/. Start New console project Create new cpp file and save it to project directory. Also copy porttalk_IOCTL.h and pt_ioctl.c files to project directory. These files you will find in the package portalk22.zip. Test program: Compile this program and run it. You should see results like this: Now it is time to connect your microcontroller and start experimenting. Good luck. Test routine project files for DEV-CPP are here:LPT1 Sample Project

Continue reading

Program LPT and COM ports easily under windows NT-2000-XP

If you are working with embedded projects usually you have concerned about how directly control computer ports like LPT or COM. Basically no one wants to mess up with driver writing or reading tons of documentations in order to send some bytes via IO port to your target board. Earlier when DOS, win95 and win98 operating systems were popular accessing I/O ports was easy as there weren’t any protections – simple code could do the job. Under NT/2000/XP situation is different. These operating systems has strict control of I/O ports. Read more about this here: www.beyondlogic.org. If you will try to access ports directly under windows XP, then you will get error mesage: How to solve this problem without writing your own driver and without rewriting old DOS or win98 programs. Well there is a solution that allow you to run programs under windows 2000/XP and talk to ports directly. Download PortTalk program from www.beyondlogic.org. Now you have two ways of running programs – but don’t forget to read porttalk.pdf which is included in package. Solution No.1 Download portalk22.zip and unzip it in separate folder somewhere. Then copy allowio.exe directly to the directory where is you program which you want…

Continue reading

Build your own AVR JTAG ICE clone

After unsuccessful attempts to run a few programs which drive peripherals like USART and Timers on Atmega128 I decided to make JTAG debugger. I hope it will allow me to see what is happening may atmega128 corrupted, or something is wrong with the software or with hardware. The most widely used AVR JTAGICE clone is AVR miniICE, which is compatible with original AVR JTAGICE. AVR JTAG mainly is used for target board debugging in the real world. And of course, you also can program your AVR’s with it. To build this board is very ease as its schematic is simple: AVR_JtagICE Schematic List of materials you will need: Amount-Type-Title 2-470R-R1, R2 1-10K-R3 2-22p-C7, C8 6-100n-C1,C2,C3,C4,C5,C6 1-LED-G-D1 1-LED-R-D2 1-ATmega16L-DD1 1-MAX3232-DD2 1-7.3728 MHz-Q1 All secret in its firmware, but don’t worry – it is ready to go. AVR MiniICE has the following properties: Is compatible with AVR JTAG ICE; It is capable of debugging and programming Atmega microcontrollers with JTAG interface; Real-time debugging support; Regular updates of firmware to support new types of AVR; Upgrades can be done directly from AVR Studio; Power supply from 2.6 to 6V; Connects to AVR Studio through COM port; Two LED indicators (Power and Connect). Now…

Continue reading

AVRSIDE-free alternative IDE for WINAVR

Author (Jurek Szczesiul) of AVRSIDE program decided that there is not enough functionality with standard Programmers Notepad. He started to write his own IDE, which expands functionality and usability. Project is still in development stage but looks very promising. Main features are: SDI interface model with as much space for code as possible; creating single/multifile projects; compile and make / build operations available; makefiles edition – directly set options you need; compilation log file creation; different syntax highlighting for C and ASM; jump – to – error makes easy code cleaning; avr – gcc assembler code preview for single file and whole project; multi file project import from any folder; auto creating dependencies for header files; libraries manager; simple symbols browser; code templates and avrlibc functions auto-completion; automatic hint for function declaration number of searching tools; embedded ISP interfaces based on com port and USB. Project page of AVRSIDE. Download AVRSIDE from here.

Continue reading

Function calls and stacking of parameters in embedded systems

Usually when you write C programs for microcontrollers you use functions that can be called any time in main program or in another function. Compiler compiles these functions as subroutines. These functions can be called from main function or from other functions – this is called nesting (nested subroutines). If you see the listings of compiled program you will see that subroutines are called by using call or rcall keyword. The argument of this instruction is an subroutine address which will be executed on the next processor cycle. Call instruction also writes return address from function to the stack to continue program after returning from function. The next instruction begins execution at the start of the subroutine and returning from function is done after ret instruction which also restores an address of program counter in hardware level. Stack is also used to store all arguments of function – it usually depends on compiler hos it is done. But in general compiler generates code which: Push all arguments to stack; Call the function; Allocate storage for all local variables in the stack; Perform the function; Deallocate local variables from stack; Return from function; Deallocate the space used by arguments. All these…

Continue reading