a. Write an algorithum for this system. b. Translate the algorithum to a C progr
ID: 3828573 • Letter: A
Question
a. Write an algorithum for this system.
b. Translate the algorithum to a C program.
You are in charge of designing a device to measure the height of crops in a field and control fertilization sprayers. This measurement allows farmers to spray the right amount of fertilizer according to the height of the crop. You decided to use a Microchip microcontroller and a laser finder with an appropriate circuit that provides a voltage value proportional to the height of the crops (voltage height/10). The device controls 1 sprayer through PORTD pin RDO. This control is such that if the height is less than 20cm S is open for 40sec (voltage less or equal to 2V) the height is between 20cm and 40cm S is open for 25sec (voltage between 2V and 4V) the height is more than 40cm, S is open for 10sec (voltage more than 4V and less than 5V). We assume a PIC18F4520 running at a frequency of 10MHz.Explanation / Answer
(a) Algorithm:
1. Get voltage value for the crop with the micro-controller
with getVoltage()
2. Height = Voltage 'V' * 10
3. Action for sprayer (pin RD0):
if(height < 20) openSpray(40 sec)
if(height >= 20 && height <= 40) openSpray(25 sec)
if(height > 40) openSpray(10 sec)
(b) Program:
#include<stdio.h>
int getVoltage(string crop){
int voltage;
//micro-controller calculates voltage
//with circuit and laser, returns voltage
return voltage;
}
void openSpray(int time){
//micro-controller opens spray for
//time amount of seconds through PORTD pin RD0.
}
int main() {
int height, spray_time, voltage;
string crop;
//Get the crop for which height needs to be calculated
scanf("%s",&crop);
voltage = getVoltage(crop);
height = voltage*10;
if(height < 20)
openSpray(40);
if(height >= 20 && height <= 40)
openSpray(25);
if(height > 40)
openSpray(10);
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.