Thursday, 17 February 2011

Analog To Digital Converter use AVR-009


On this page I will provide tutorials that can help to start learning a microcontroller. In this tutorial, I will give examples of the application microcontroller programming using C language

Good! ... Let's start learning.

Now we will learn to use a microcontroller to convert data from analog data into digital data, or better known as the Analog to Digital Conversion (ADC). In this project we will use microcontroller AVR-009 from Circuits-Home. In this tutorial, I will give examples of flame control LED display and control of motor using a potentiometer on the basis of a reference voltage ATmega8535 AVR microcontroller ADC channel.

 
AVR-009 microcontroller kit (www.circuits-home.com)

Before creating the program, the first job we have to do is understand about the hardware specs.

A. AVR-009 Kit Specifications:
MCU             : AVR ATmega8535 (compatible with series MEGA16 and MEGA32)
Crystal          : 8 MHz
Pin Description        :
Porta = as channel DC servo motor driver, ADC, and LEDs.
PORTB = path to programming microcontrollers (MISO, motions, SCK).
PORTC = connect with a seven segment display unit
PORTD = connect with DC motor drivers MP and 2 units of tag-switch.
Power: About 5 volts DC.

Once we know the specification of hardware, now let us work on our project.

B. Running Programs CodeVision-AVR:
Step 1 = Run the CodeVisionAVR IDE software.
Step 2 = Make a new project with CodeWizard
Step 3 = Type the code on the text editor That show after you choose "File>> Generate, save, and exit".

C. Example C program:
Next, I provide an example program (in C) use the ADC to control the flame LED display and DC motor (Permanent Magnet) by using the AVR-009 kit. Here's the program.

I. ADC to control the LED display.

#include    
#include
#define ADC_VREF_TYPE 0x00 

// Read the AD conversion result
unsigned int read_adc(unsigned char adc_input)
{
 ADMUX=adc_input | (ADC_VREF_TYPE & 0xff);
 delay_us(10);                   // untuk stabilisasi tegangan input ADC         
 ADCSRA|=0x40;                   // Start the AD conversion 
 while ((ADCSRA & 0x10)==0);     // Wait for the AD conversion to complete
 ADCSRA|=0x10;
 return ADCW;
}

void main(void)
{
 DDRA=0xF3;
 DDRB=0xFF;
 DDRC=0xFF;
 DDRD=0x3F; 

 ADMUX=ADC_VREF_TYPE;
 ADCSRA=0x85;

 while (1)
      {
       PORTA.7=~read_adc(2);      
      }
}

II. ADC to control permanent magnet DC motor rotation.

#include    
#include

#define ADC_VREF_TYPE 0x00
#define ENA     PORTD.5

// Read the AD conversion result
unsigned int read_adc(unsigned char adc_input)
{
 ADMUX=adc_input | (ADC_VREF_TYPE & 0xff);
 delay_us(10);                   // untuk stabilisasi tegangan input ADC         
 ADCSRA|=0x40;                   // Start the AD conversion 
 while ((ADCSRA & 0x10)==0);     // Wait for the AD conversion to complete
 ADCSRA|=0x10;
 return ADCW;
}

void main(void)
{
 DDRA=0xF3;
 DDRB=0xFF;
 DDRC=0xFF;
 DDRD=0x3F; 

 ADMUX=ADC_VREF_TYPE;
 ADCSRA=0x85;

 while (1)
      {
       PORTD.4=1;
       PORTD.3=0;
       ENA=read_adc(2);
      }
}

To practice, you need a microcontroller kit.

Hardware:
Software:

DC motor driver for DCMP | DCSV | DCSTP (AVR-008)








On this page I will provide tutorials that can help to start learning a microcontroller. In this tutorial, I will give examples of the application microcontroller programming using C language.

Good! ... Let's start learning.

Now we will learn to use a microcontroller to control a DC motor (permanent magnet DC, DC servo, stepper and DC). In this project we will use microcontroller AVR-008 from Circuits-Home. Because it can be used to control the 3 types of DC motors, the AVR-008 is often called the 3in1 driver motor kit.   

 
 AVR-008 microcontroller kit (www.circuits-home.com)

 

The AVR-008 microcontroler kit schematic

Before creating the program, the first job we have to do is understand about the hardware specs.

A. AVR-008 Kit Specifications:
MCU                  : AVR ATmega8535 (compatible with series MEGA16 and MEGA32)
Crystal              : 8 MHz
Pin Description   :
• Porta = connect with DC stepper motor drivers.
• PORTB = path to programming microcontrollers (MISO, MISO, SCK).
• PORTC = connect with Permanent Magnet DC motor driver
• PORTD = connect with DC servo motor driver and 4 units of tag-switch.
Power: About 5 volts DC.

Once we know the specification of hardware, now let us work on our project.

B. Running Programs CodeVision-AVR:
Step 1 = Run the CodeVisionAVR IDE software.
Step 2 = Make a new project with CodeWizard
Step 3 = Type the code on the text editor That show after you choose "File>> Generate, save, and exit".

C. Example C program:
Next, I provide an example program (in C) controlling the DC motor (Permanent Magnet, servo, and stepper) using AVR-008 kit. Here's the program.

I. Permanent magnet DC motor
DC motor drivers on the AVR-008 kit is to use the IC L298 associated with PORTC, namely PORTC.0,PORTC.1, PORTC.2, and PORTC.3 whereas activation pin L298 connect with PORTC.3 (Enable-A) and PORTC .4 (Enable-A).

Example-1 program:

#include

#define input1 PORTC.0
#define input2 PORTC.1
#define input3 PORTC.2
#define input4 PORTC.3
#define ENA PORTC.4
#define ENB PORTC.5

void main(void)
{

DDRA=0xFF;DDRB=0xFF;
DDRC=0xFF;DDRD=0xF0;

while (1)
      {
       PORTB=0xFF;
       ENA=1;ENB=1;
      
       input1=0;input2=1;
       input3=1;input4=0;
      }
}

II. DC Stepper Motor
Hardware to control DC stepper motor is IC ULN2003. On the AVR-008 kit, this tool connects with PORTA. How activation of DC stepper motor has two working mode, ie a full rotation mode (see table 1) and half-rotation mode (see table 2).

Table 1. Activation of DC stepper motor (full rotation mode)
 

Table 2. DC stepper motor activation (half rotation mode)

Example-2 programs: full rotation mode

#include
#include

void main(void)
{
DDRA=0xFF;
DDRB=0xFF;
DDRC=0xFF;
DDRD=0xF0;

while (1)
      {
       PORTD=0b00000001;              //CW
       delay_ms(500);
       PORTD=0b00000010;
       delay_ms(500);
       PORTD=0b00000100;
       delay_ms(500);
       PORTD=0b00001000;
       delay_ms(500);  
      };
}

III.
DC Servo Motor
DC servo motor installation easier than the permanent magnet DC motors and DC stepper motor. In servo DC motor, the motor control devices have been integrated in the motor body, so to be able to control it simply by connecting the DC servo motor with a microcontroller. Here is a picture of DC servo motor and its wiring.

 


DC servo motor & its wiring


Examples of programs-2: For this type DC servo motors 'continuous' (360o)

#include
#include

#define servo   PORTD.7
void main(void)
{
 int i;
      
 DDRA=0xFF;
 DDRB=0xFF; 
 DDRC=0xFF;
 DDRD=0xF0;

while (1)
      {
       for(i=0;i<200;i++)   //0 derajat
       {     
        servo=1;
        delay_us(1100);
        servo=0;
        delay_us(18900);
       }        
      delay_ms(1000);
     
       for(i=0;i<200;i++)     //90 derajat
       {     
        servo=1;
        delay_us(1500);
        servo=0;
        delay_us(18500);
       }       
      delay_ms(1000); 
       
      for(i=0;i<200;i++)     //180 derajat
      {             
        servo=1;
        delay_us(1900);
        servo=0;
        delay_us(18100);  
      }       
      delay_ms(1000);
      };
}

To practice, you need a microcontroller kit.

Hardware:
Software: