Tuesday, August 17, 2010

Creating Minimum System Atmega8535

 What is the minimum system?

 The minimum system is a series of at least where the microcontroller chip can work. Atmega8535 microcontroller has dilengapi with internal oscillator, so no crystal or resonator is required external to the CPU clock source. However, this oscillator maximum 8Mhz so I suggest to keep using an external crystal.Internal oscillator by the manufacturer gives a chance 1 MHz, and to change it we need to change the settings of Fuse bits, for setting fuse bits need to be careful, because this setting is so vulnerable because if the wrong setting microcontroller can cause damage, I had corrupted a microcontroller.

Minimum System AVR is very simple where only connect AVCC to VCC and +5 V and GND and AGND to the ground and reset pin is not connected to anything . Chip will be reset if the voltage is zero or RST pins are forced to zero. This is the minimum system without using a crystal. For those who wear the above plus a series of crystal-crystal on pins XTAL1 and XTAL2.The following minimum system which uses a crystal (I recommend making the use of crystals)
Combination the above are the minimum system used to control the LEDs.The above circuit can use the live trace deeptrace, eagle, proteus, or other programs that you mastered. For those who are lazy to download the trace made by me, which I pake softrware deeptrace 2009, please download here
downloadernya can use a downloader that my previous post
 
 display the following minimum system in deeptrace
 For the prgram and the way I described in my program filling the next posting.

from  http://etekno.blogspot.com/2010/06/proyek-1-membuat-sistem-minimum.html

PWM Configuration for PIC16F877 microntroller

PWM can be used to control a motor driver or generate sound samples.


The register specifically used to configure PWM are the TRISC, PR2, CCP1CON, CCP2CON, CCPR1L, CCPR2L and T2CON registers. There are two PWM channels on the PIC16F877. These modules are coined CCP1 et CCP2. These modules are implemented on pins 16 and 17 of the PIC16F877. There are two ways to connect these pins to a L293D H-Bridge. I recommend to connect these to the L293D Chip Enable pins. PWM then controls the percentage of time the chip is enabled.

There are two parameters that affect the behavior of the PWM. The first one is the frequency of the pulses, the second is the length of these pulses. The length of the pulse is also called the duty cycle, e.g. the percentage of time the motor is enabled. In an ideal environment, if a motor normally exhibit 100 RPM, then it should do 25 RPM with a 25% duty cycle

It is important to experiment with these parameters to find the configuration that is right for your application because no two motors are the same. Some motors are better when the frequency is low (between 2 000-5 000 Hz). Other motors are best when the frequency is high, say between 15 000 and 20 000 Hz. Note that a low frequency (between 1 000 and 8 000 Hz) will produce an audible sound that can be very annoying. I have tested three robots with varying weight (500 g to 15 kg) and with different motors and have found that a frequency of 15 000 to 20 000 Hz gives good results. I have never seen any robot move with a duty cycle of less than 50%. If you want to do this, you have to find ways to control PWM in software, i.e. for a duty cycle of 25%, use a 50% duty cycle and turn PWM 50% of the time. Ideally, you will find motors that are not too fast at 50% and fast enough at 100%.

The TRISC register must be initialized so that RC1 et RC2 are identified as output ports (bits 1 and 2 of TRISC must be set to 0). CCP1CON and CCP2CON are used to configure CCP1 and CCP2 modules mode. A value of 12 configures these modules for PWM mode.

Timer2 is used by CCP1 and CCP2 modules for PWM purposes. Timer2 prescaler is configured using bits TCKPS0 et TCKPS1 of T2CON register (bits 0 and 1). A value of 0 for these two bits configures a prescaler of 1. Bit TMR2ON (bit 2) must be initialized to 1 to start Timer2.PR2 register controls the pulse frequency. The formula used to calculate the pulse period is:(PR2 + 1) * 4 * TOSC * (Timer2 prescaler value).Pulse frequency is 1 / period. If PR2 is equal to 255 and the PIC runs at 20 MHz, pulse frequency is 19.53 kHz with a Timer2 prescaler of 1, i.e. 1 / ((255 + 1) * 4 * 1 / 20 000 000 * 1).

The CCPR1L et CCPR2L registers configure the "duty cycle". The "duty cycle" is relative to PR2. If PR2 is 100 and CCPR1 is 50, then the "duty cycle" is effectively 50% (half of PR2).
CCS provides macros to configure these registers appropriately. Here is an example program that shows how to configure PWM with CCS:

demopwm.c

Graphic LCD

Done working on Graphic LCD (GLCD) interfacing with 89c51. Here is exapmle  asm file and hex code file.
And following are the connection pattern for GLCD and 89c51.
 

DC Motor Control with Microcontroller ATmega8535

At mega 8535 microcontroller can use control dc motor that is on pin d where there have PWM control. DC motor can rotate because of the induction when the motor is connected to the DC voltage source. DC motor control with microcontroller if it is done more easily than without the microcontroller. We can change the direction of rotation of DC motor directly by changing the polarity of the voltage source. To change the speed of DC motors can be done by changing the size of a fox-voltage source. Control with a microcontroller as well as principled, but with an automated system. We do not have to change the cable from the motor to the battery if you want to change the direction of rotation, we just provide the logic 0 or 1 to the microcontroller is performed on the program in the microcontroller. To change the velocity is also easier because we simply use the existing PWM feature on the microcontroller. Maybe there are still many who do not know what PWM

PWM (Pulse Width Modulation) is a technique to get the effect of the analog signal from a digital signal to falter. PWM can be generated using only digital i / o which functioned as an output.



  In the example above the waves, the comparison between high signal (1) and low signal (0th) is the same. Above the wave is said to have 50% duty cycle. Duty cycle is the ratio between the width of high signal (1) the overall width of the cycle (cycle). If the PWM wave amplitude is 5 volts, then the average stress (as if to analog) that we get is 2.5 volts. Here's an example of wave PWM with duty cycle 10%, if the amplitude of wave 5 volts then we will get the average analog voltage 0.5 volts.



In  ATMEGA8535 have two way control PWM, the PWM can be generated from the first port input / output is enabled as output. The second is to utilize the facilities of the function of the PWM timer / counter which has been provided. With this facility, the timing of the process of high / low digital signal will not disrupt the sequence of other programs being executed by the processor. In addition, by using this facility to enter how many servings we lived on and off time period on a wave PWM registers. OCR1A, OCR1B and OCR2 is register a place set PWM duty cycle.
The following schematic DC Motor Control with Microcontroller ATmega8535 of my own, please trace itself, or if you want to please make my request in the comments section below ini. Click image to enlarge......




I separate the circuit into three main sections so that it is easy to understand and analyze our series, namely the minimum system, motor drivers, and motors (as a major expense). The minimum system the same as in my previous posting, the next part of the driver. in fact we can directly connect the microcontroller to the motor without a driver, this can be done if the motor that we use a small motor. we need a big motor for the drivers, these drivers can be made also with the MOSFET (often called the H-Bridge), we can use a more practical ie L298 driver ic, ni ijenis drivers able to control two motorcycles and also features the legs to control the PWM .
For our experiment we only use a single dc motor alone, here are photos from the series that I created.



For the program you can see below. Use the AVR Studio software (after AVR studio also install WinAVR is installed so that it AVRstudio supports the C language, because the standard AVRstudio using assembly language). To download your program can use the USB downloader downloader atapun series which has also been my post. The following program

#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>

#define    DDR_motor    DDRD    //DDR untuk Motor
#define    PORT_motor    PORTD    //PORT untuk Motor

#define en_ka         5        // Enable L298 untuk motor kanan
#define dirA_ka     2        // Direction A untuk motor kanan
#define dirB_ka     3        // Direction B untuk motor kanan
#define pwm_kanan    OCR1A

void delay_ms(int ms)
{for (int i=0;i<ms;i++){_delay_ms(1);}}

void maju(unsigned int pwm)
{
PORT_motor |=(1<<dirA_ka);        //motor maju
PORT_motor &=~(1<<dirB_ka);
pwm_kanan=pwm;                    //pwm motor kanan
}

void mundur(unsigned int pwm)
{
PORT_motor |=(1<<dirB_ka);        //motor maju
PORT_motor &=~(1<<dirA_ka);
pwm_kanan=pwm;                    //pwm motor kanan
}


int main (void)
{

DDR_motor=0xFF;
PORT_motor=0x00;


    TCCR1A= (1<<WGM11)|(1<<WGM10)|
            (1<<COM1A1)|(0<<COM1A0)|
            (1<<COM1B1)|(0<<COM1B0);
           
    TCCR1B= (0<<WGM13)|(1<<WGM12)|
            (0<<CS12)|(0<<CS11)|(1<<CS10);
    TCNT1=0x0000;
    OCR1A=0;
    OCR1B=0;
    sei( );


while(1)
{
mundur(1000);
delay_ms(5000);
maju(700);
delay_ms(3000);

}
}

see the main program, with a PWM motor will resign in 1000 over 5000ms (5 seconds) and then will forward denan PWM motor 700 for 3000ms (3 seconds). and the program will be repeated a maximum of motor-ulang.Kecepatan happen if we gave in 1000 and the minimum PWM value (motor stopped) if the PWM value of 0, see the main program, which is backward (1000) that mean the motor will spin backwards at top speed because the PWM is 1000