Rabu, 07 Desember 2016

Resistor Tester/Ohm Meter AVR 7 Segment

Salam elektro, bertemu lagi dengan saya, sebenarnya ini project yang yang lama dan baru bisa saya tulis sekarang, yaa mudah mudahan bisa bermanfaat untuk para pembaca, pada kesempatan kali ini saya akan memberi tutorial cara membuat resistor tester/ohm meter dengan menggunakan avr dengan tampilan 7 segment dengan menggunakan software codevision avr

TOLONG BACA DENGAN DETAIL !

Siapkan alat dan bahan :
  • Minimum sytem atmega 8535
  • Transistor BC547
  • 7 Segment common anode (6)
  • Resistor 220 ohm (6)
  • Resistor 1k
  • Kabel jumper disesuaikan
  • Breadboard
  • Kabel usb
  • Laptop
  • Software codevision avr 
1. Sambungkan semua komponen sesuai dengan gambar atau bisa kalian coba dulu pada software proteus isis


CATATAN !
a. Pastikan wiring sudah benar 
b. Pastikan common 7 segment adalah common anode
c. Pastikan settingan crystal menggunakan 12 Mhz

2. Buat program seperti dibawah ini pada software codevisionavr,apabila ada yang belum tau cara menggunakan software codevision avr bisa baca disini 
/*****************************************************
This program was produced by the
CodeWizardAVR V2.05.3 Standard
Automatic Program Generator
© Copyright 1998-2011 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com

Project : 
Version : 
Date    : 10/20/2016
Author  : Fickry Muhammad
Company : PT Len
Comments: 


Chip type               : ATmega8535
Program type            : Application
AVR Core Clock frequency: 12.000000 MHz
Memory model            : Small
External RAM size       : 0
Data Stack size         : 128
*****************************************************/

#include <mega8535.h>

#include <delay.h>

// Standard Input/Output functions
#include <stdio.h>

// Declare your global variables here
char segment[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; 
long int satuan,puluhan,ratusan,ribuan,jutaan,data_seg,scan,send,send_int;
float result_adc, Rtester, Rreference = 1000;

// Timer1 overflow interrupt service routine
interrupt [TIM1_OVF] void timer1_ovf_isr(void)
{
// Reinitialize Timer1 value
TCNT1H=0xD23A >> 8;
TCNT1L=0xD23A & 0xff;
// Place your code here
// Send data to uart
send=send+1;
if (send >= 2)
{
    send = 0;
}
}

#define ADC_VREF_TYPE 0x40

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

void take_data()
{
data_seg = Rtester;
satuan   = data_seg%10;
puluhan  = (data_seg/10)%10; 
ratusan  = (data_seg/100)%10; 
ribuan   = (data_seg/1000)%10;
jutaan   = (data_seg/10000)%10;           
}

void display()
{
PORTD = 0b10000000;
if(Rtester >= 999)
{
    PORTB=0x8d;
}
else
{
    PORTB=0xce;
}
delay_ms(1);
           
PORTD = 0b01000000;
PORTB=segment[satuan];
delay_ms(1);

PORTD = 0b00100000;
PORTB=segment[puluhan];
delay_ms(1);
           
PORTD = 0b00010000;
PORTB=segment[ratusan];
delay_ms(1);

PORTD = 0b00001000;
PORTB=segment[ribuan];
delay_ms(1);

PORTD = 0b00000100;
PORTB=segment[jutaan];
delay_ms(1);
}

void main(void)
{
// Declare your local variables here

// Input/Output Ports initialization
// Port A initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T 
PORTA=0x00;
DDRA=0x00;

// Port B initialization
// Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out 
// State7=0 State6=0 State5=0 State4=0 State3=0 State2=0 State1=0 State0=0 
PORTB=0x00;
DDRB=0xFF;

// Port C initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T 
PORTC=0x00;
DDRC=0x00;

// Port D initialization
// Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out 
// State7=0 State6=0 State5=0 State4=0 State3=0 State2=0 State1=0 State0=0 
PORTD=0x00;
DDRD=0xFF;

// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=0xFF
// OC0 output: Disconnected
TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;

// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: 11.719 kHz
// Mode: Normal top=0xFFFF
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer1 Overflow Interrupt: On
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x05;
TCNT1H=0xD2;
TCNT1L=0x3A;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;

// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer2 Stopped
// Mode: Normal top=0xFF
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;

// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// INT2: Off
MCUCR=0x00;
MCUCSR=0x00;

// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x04;

// USART initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART Receiver: On
// USART Transmitter: On
// USART Mode: Asynchronous
// USART Baud Rate: 9600
UCSRA=0x00;
UCSRB=0x18;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x4D;

// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;

// ADC initialization
// ADC Clock frequency: 750.000 kHz
// ADC Voltage Reference: AVCC pin
// ADC High Speed Mode: Off
// ADC Auto Trigger Source: ADC Stopped
ADMUX=ADC_VREF_TYPE & 0xff;
ADCSRA=0x84;
SFIOR&=0xEF;

// SPI initialization
// SPI disabled
SPCR=0x00;

// TWI initialization
// TWI disabled
TWCR=0x00;

// Global enable interrupts
#asm("sei")

while (1)
      {
      // Place your code here 
      // Read adc and convert to ohm (formula)   
      result_adc = read_adc(0);
      result_adc = result_adc * (5.0 / 1023.0);
      Rtester = (5 - result_adc) * Rreference / result_adc;   
       
      // Send data to uart (every 1 second)
      if (send == 1)
      {  
        send_int = (int)Rtester;
        printf("Rtest = %d\t",send_int);   
        printf("\t");
      }   
      
      // Scanning mode  
      for(scan=0;scan<100;scan++)   
        {        
            take_data();
            display();  
        } 
      }
}

3. Compile project pada software cvavr,apabila tidak terjadi error lanjut dengan proses upload atau build all project files 

4. Download program .hex (hasil compile) pada minimum sistem menggunakan usb asp baca disini,bila menggunakan simulasi tinggal kalian masukan file .hexnya ke dalam ic baca disini

Instruction 
Coba kalian coba tap sembarang resistor pada pin yang sudah disediakan, coba lihat data yang keluar pada display 7 segment 


Share:

0 comments:

Posting Komentar

Copyright © FILAB | Powered by FILAB
Design by Fickry Muhammad | Technology by Filab.id