You are on page 1of 2

[Type text]

Test – 2 (Sem1/2016) Microprocessor Applications (EE313)


Solution
Total time: 40 mins Total Marks: 15

Q-1 What is PWM? How does it use in motor control driving? Give two applications of this 03
technique in microcontroller based system?
• PWM: It’s technique in which we change the pulse width to get the desired duty
cycle
• Microcontroller is used effectively to control speed via Pulse-Width-Modulation
(PWM)
• Square wave signal is described by three parameters, Amplitude, Frequency and
Duty cycle
• Term "duty cycle" describes the ratio of the ON state of the signal to the period of
that signal,
i.e. Duty = TON/ T = TON/( TON+TOFF)
• Duty cycle has no unit, its represented by percentage with 100% describing the fully
ON state and 0% describing the fully OFF state
---1M
• Idea of speed control is to switch the motor ON and OFF at varying speeds
• Say, a 12V DC motor we applied a constant 12V signal to that motor, the motor
would run in its full power (full speed)
• Assume, a 50% duty cycle (at several KHz frequency), the motor will turn ON and
OFF continuously and the effective voltage applied to the motor is 6V, this would
decrease the motor speed by the half, and the motor would be running at 50% of
it's full power
• Varying the duty cycle of the applied signal would cause the speed to vary, a 0%
duty cycle signal would turn OFF the motor, and a 100% one would run the motor at
it's full speed.
-- Example: DC motor speed control, Servo motor position control.
-- 2M
Q-2 Write program logics to detect a key input from external. Use interrupt feature to implement 06
this application. A lamp (40W) is required to switch ON from OFF whenever the key is
pressed. After 5 sec, the lamp switches OFF automatically.
1. Draw a basic circuit diagram to interface this application via switch input and lamp to
drive through output pin.
2. Write instruction codes/program in PIC C logic with comment.
Given maximum crystal frequency = 20 MHz.

PIC18F

RBO/ RBO
INT Pin

RD1

3M
#int_ext //Set external interrupt on pin RB0
void int_isr() // program automatically jump on ISR when overflow
occured
{
disable_interrupts(GLOBAL); //disable interrupt temper.
output_high(PIN_D1); //indicate interrupt via LED port A_3
delay_ms(5000); //wait to display number to notify
enable_interrupts(GLOBAL);
}
[Type text]
main() {
output_b(0x00); //clear port B
set_tris_b(0x01); // Set RB0 to input, RB1-7 output
PORT_B_PULLUPS(0); //disable internal pull-ups
ext_int_edge(L_TO_H);
// init interrupt triggering for button press
enable_interrupts(INT_EXT); //enable external interrupt
enable_interrupts(GLOBAL); //enable global interrupt

while(true){ output_low(PIN_D1); };
} //end of the program -------------------------------------3M
Q-3 Ram Sami chicken egg poultry farm has a temperature controlled using PIC18FXX, driver 06
circuit and sensor is given in Figure below. Write a programming logic so that the
temperature inside the closed area is maintained around equal to 26 oC (deg Celsius).
Coolar is used to decrease the temperature and a blower is used to remove bad smell
quickly. A current temperature is measured using a sensor LM 35DZ which is interfaced with
one of the analog channel of the microcontroller.
Ans: Assume pins are used as below:
Port B_0 – connected with driver circuit for cooler
Port B_1 – connected with driver circuit for blower
ADC pin Channel #0 – connected output from LM35. --- 1M
//Temperature controlling system -- Sensor - LM35 With PIC
#include <18F8722.h> //
int16 digital_reading; // ADC resolution is 10Bit, an 8Bit integer is not enough to
hold the reading float temp;
main() {
/* ADC Initialization */
setup_adc(ADC_CLOCK_INTERNAL); // initialize ADC setup_adc_ports(
ALL_ANALOG );
set_adc_channel(1); // point ADC to channel 1 for ADC reading
delay_ms(1); // ADC module is slow, needs some time to adjust.
output_low(PIN_B1);// ON the blower , keep it on always ---2M
while(1) // infinite loop
{
digital_reading = read_adc(); // capture current temperature reading
delay_us(100); // 0.1ms delay for ADC stabilization
temp = digital_reading * 0.4883; // convert reading to Celsius
if(temp==26)
{ output_low(PIN_B0);// off the cooler
}
else if(temp<26)
{ output_high(PIN_B0);// OFF the cooler to increase the temperature
}
else if(temp>26)
{ output_low(PIN_B0);// ON the cooler to decrease the temperature
}
} //end while loop -------------------------3M
}// end of program

……

You might also like