## Control motor PWM schematic

In general there are two ways to control DC motor speed: by varying supply voltage and pulse width modulation (PWM). First control method is not convenient especially in digital systems. It requires analog circuitry and so on. Second motor speed control method is very convenient for digital systems, because all control is made using only digital signals. As you already know PWM (Pulse Width Modulation) is all about switching speed and pulse width (duty cycle). Duty cycle is ratio of signal time ON/T. T is period of signal. In above diagram you see two signals. First duty cycle is about t1/T=1/3 and another’s duty cycle would be about t2/T=2/3. And notice the period of signals are the same. If we apply these signals to switching transistor we would get control over effective voltage across motor: Vefective=(tON/T)*Vcc; Where tON-signal on time over one period T. In this way you can control…

## Programming AVR fuse bits – oscillator settings

I guess many of you were confused when programming AVR fuse bits. I get many newbie questions like “I programmed Atmega8 but it doesn’t work”. Then my standard answer is: “Did you touch configuration bits?” and if yes, then I am almost 90% sure that he did it wrong. Most of them understands wrongly that programmed fuse bit in configuration should be left unchecked and opposite. Let’s take a look at widely used programming software – PonyProg. First thing you do before programming chip is set configuration bits (Atmega8 in picture): The first attention should be paid to clock sources. There are Four bits controlling Atmega8 clock sources: CKSEL0, CKSEL1, CKSEL2, CKSEL3.

## Small note on how to start LCD in 4 bit mode

When LCD is working in 4 bit mode, then data has to be sent by nibbles â€“ portions of 4 bits. Just remember that first goes high nibble then follows lower one. Each nibble has to be strobed with control signal E separately. Following list is describing how to start LCD in 4 bit mode: Wait for 15 ms after power is switched on; Write 00000011 (0x03) to LCD; Wait for 5 ms; Write 00000011 (0x03) to LCD; Wait for 160 us; Write 00000011 (0x03) to LCD; Wait for 160 us; Write 00000010 to enable 4 bit mode (after this command start sending in nibbles); Set interface length; Turn off display (0x00 and 0x08 nibbles); Write 00000001 (0x00 and 0x01 in nibbles) to clear display; Set cursor move direction by setting cursor bits; Enable display; After initialization is complete you may write any character or command to it.

## Connect LCD to Atmega using 3 wires

After I implemented interfacing LCD to ATmega8 using 2 wires https://www.scienceprog.com/interfacing-lcd-to-atmega-using-two-wires/ I decided to make another one example but with 3 wires. Using 3 wires makes control much simpler as it is easier to control data flow to shift register. Here I used the same super cheap 74HC164 serial in parallel out register. LCD to shift register is connected in 8 bit mode. LCD strobe pin E is controlled with Atmega PC2 pin. Register is clocked with PC1 and data is transferred with PC0 pin. Notice, that I used same data line (PC0) to control LCD RS pin. RS pin is controlled in this way: after 8 bits are sent to shift register, then enable data line by setting ‘1’ (PC0) without clocking and after this LCD E pin is strobed. For more details take a look at my source code at the end of article. If there is any…

## RTC example on ARM7 LPC2148 using WinARM

Finally got my LPC2148 RTC working on my development board. arm7 base development board for lpc2148 I am quite new to ARM microcontrollers, so I managed to make few tests using them by driving some peripherals and writing some test routines. First code I tried was simple LED blink program first lpc2148 arm7 microcontroller test led blink This one is running microcontrollers real time clock (RTC) and generating interrupts every second. When Interrupt occurs microcontroller sends particular message to UART that I could see via Terminal program. The main program: /****************************************************************************** * * WinARM RTC application * * – UART0 send in Interrupt-Mode * – Sends message every seccond. * – RTC interupt every second ******************************************************************************/ #include “types.h” #include “LPC214x.h” #include “config.h” #include “armVIC.h” #include “uart.h” uint32_t time_toggle=0; static void rtc0(void) __attribute__ ((interrupt (“IRQ”))); static void lowInit(void) { // set PLL multiplier & divisor. // values computed from config.h PLLCFG…

## Microcontroller eats too much of RAM

All you know that microcontrollers have limited amount RAM and EEPROM. For instance ATMega128 has 4-Kbytes of RAM, 4-Kbyte of EEPROM. This may seem quite enough for some applications, but more complicated routines require more of RAM. And there is no compiler that can do better optimization on usage of ram than programmer. The main aim of reaching this is reducing dependence on global data, stack and the heap. So if your application running in microcontroller eats too much of RAM then you should develop some strategy of using its RAM. Lets seeâ€¦ if you use constants as global values, why not to move them to EEPROM area? You can easily do this by compiler when you declare your variables by using const keyword: const uint8_t a=10; I compiled some code using this declaration and compiler (AVR-GCC) compiled .eep file which can be burned to microcontrollers EEPROM. In this way…

## Minimizing microcontroller code size

Reducing microcontroller code size isn’t ease task, but what if you want resulting code to fit your available memory? Minimizing microcontroller code size can be done in two ways: Firs is using compilers optimization feature by code size. This optimization is very dangerous. Your optimized code may not work as supposed to because compiler may eliminate some code like empty loops or adding zeros. For example compilers like to remove for(int i=0;i by leaving one or several iterations. So don’t think that your optimized code will work as un-optimized. There are other things you can do to minimize microcontroller code size. One of them is avoiding usage of standard libraries routines. Because these libraries are general and handles all standard possible execution cases. By including them in your design you include a bunch of code you dont need. If it is possible it is better to write your own routines…