0% found this document useful (0 votes)
11 views7 pages

LR 11

microprocessor lab report 11

Uploaded by

ahmad hassaan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views7 pages

LR 11

microprocessor lab report 11

Uploaded by

ahmad hassaan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

COMSATS UNIVERSITY

MP

Lab # 10
Ahmad Hassaan
Name

FA18-BEE-230
Registration Number

Instructor’s Name Adeel Iqbal


In Lab:
Task 1:
The expected input signal is a periodic pulse train. The task is to find the frequency/time period and
duty cycle of this signal. The frequency of this signal is expected to be less than 4 KHz. The given
code configures Atmega328P interrupt subsystem to work with external interrupts and input
capture of Timer1. It also performs the necessary calculations to find the frequency and duty cycle
of the input signal and displays it on a terminal. You will have to understand the code and then
configure Timer1 for input capture.
Code:
/*
* lab_10.c
*
* Created: 12/12/2020 5:41:19 pm
* Author: Junaid Computers
*/

#include <avr/io.h>
#include <inttypes.h>
#include <stdlib.h>
#include <avr/interrupt.h>
#define F_CPU 16000000UL
#include <util/delay.h>
#include <string.h>
#include <math.h>

#include "debug_prints.c"
#define BAUD0 9600
#define MYUBRR (F_CPU/8/BAUD0-1)

unsigned char icp_low=0;


unsigned char icp_high=0;
unsigned int input_capt_counter=0;

unsigned int rising1=0;


unsigned int rising2=0;
unsigned int falling1=0;
unsigned char capture_complete=0;
float sig_freq=0;
float sig_dc=0;

#define TRUE 1
#define FALSE 0

void timer_init(void);
void display_counter_values(void);
void calculate_signal_param(void);
void display_signal_parameters(void);

int main(void)
{
DDRB &=(1<<PB0);
PORTB|=(1<<PB0);
UART0_init(MYUBRR);
printSerialInt(MYUBRR);
printSerialStrln("");
printSerialStr("F_CPU=");
printSerialInt((int)(F_CPU/1000000));
printSerialStrln("MHZ");
printSerialStrln("lab 10=input capture");
timer_init();
EICRA|=(1<<ISC01);
EIMSK|=(1<<INT0);
SREG=(1<<7);
int i=0;
while(1)
{ if (capture_complete == TRUE)
display_signal_parameters();
capture_complete = FALSE;
for (i=0;i<8;i++)
{
_delay_ms(250);
printSerialStrln("press the button..");
}

}
}
void_timer_init(void)
{

ACSR &=~(1<<ACIC);
TCCR1A=0x00;
TCCR1B|=(1<<ICES1);
TCCR1B|=(1<<CS11);
TCNT1L=0;
TCNT1H=0;
TIMSK1|=(1<<ICIE1);
}
ISR(INT0_vect)
{
//printSerialStrln("Processing External Interrupt 0: ");
rising1=0;
rising2=0;
falling1=0;
capture_complete - FALSE;
input_capt_counter=0;
sig_freq=0;
sig_dc=0;
TCCR1B|=(1<<ICES1);
TCNT1=0;
TIMSK1|= (1<<ICIE1);
}
ISR(TIMER1_CAPT_vect)
{
printSerialStrln("Processing Timer Interrupt: ");
icp_low=ICR1L;
icp_high=ICR1H;
input_capt_counter ++;
printSerialInt((int)input_capt_counter);
printSerialStrln("");
if (input_capt_counter==2)
{
rising2=(ICR1H<<8)|(ICR1L);
}
if (input_capt_counter==3)
{
rising2=(ICR1H<<8)|(ICR1L);
TCCR1B&=~(1<<ICES1);
TIFR1=(1<<ICF1);
}
if (input_capt_counter==4)
{
falling1=(ICR1H<<8)|(ICR1L);
TIMSK1&=~(ICIE1);
capture_complete=TRUE;
calculate_signal_param();
}
}
void display_counter_values()
{
printSerialStr("Rising 1: ");
printSerialLong((long int) rising1);
printSerialStrln("");
printSerialStr("Rising 2: ");
printSerialLong((long int) rising2);
printSerialStrln("");
printSerialStr("Falling 1: ");
printSerialLong((long int) falling1);
printSerialStrln("");
}
void display_signal_parameters(void)
{
printSerialStr("Frequency = ");
printSerialFloat(sig_freq);
printSerialStrln(" Hz");
printSerialStr("Duty Cycle = ");
printSerialFloat(sig_dc);
printSerialStrln(" %");
}
void calculate_signal_param()
{
printSerialStrln("Calculating Signal Parameters ... ");
if((rising2-rising1) !=0)
{
sig_freq=F_CPU/(8*(float)(rising2-rising1));
sig_dc=100.0*((float)(falling1-rising2)/(float)(rising2-rising1));
}
else
{
sig_dc=0;
sig_freq=0;

}
display_counter_values();
display_signal_parameters();
}
Proteus simulation:

Post lab:
Find out how input capture feature of microcontrollers can be used to
record a signal from a TV remote control. Submit a report of your
findings
Answer:

Firstly we will need a suitable IR receiver module designed for


remote control applications. Its carrier frequency range needs to
be compatible with your You probably want hardware assistance
for capturing the bitstream transitions so should connect it to a
pin that can be used for a CCP module input or maybe an
external interrupt input if you are simply going to sample at a
fixed rate once any transition is detected.
You then need code to store the bitstream - in RAM initially as
you probably cant write to EEPROM fast enough. You also
need playback code.
The IR LED will need a driver circuit as its usual operating
current is far more than a PIC can output.

Critical Analysis:
We have learnt how to capture periodic signal using our microcontroller
and have later learnt how to simulate them on proteus design tool.

You might also like