Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

i want a change in this source code writen on mplab

Status
Not open for further replies.

Zohaibmaroof

Member level 2
Joined
Oct 10, 2010
Messages
50
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,832
source code is made for a project which uses ultrasonic range finders SRF04 that sense any obstacle come in front of them and vibrates vibration motors but constant vibration,i want to make the duty cycle of motors according to the distance between the obstacle and sensor that vibration becomes inversely proportional to the distance between the sensor & obstacle also i have a question that this source code is made for PIC16F877 which is controlling 4 sensors ,4 vibration motors so i want to ask where there all 4 sensor,motor pairs works separately or they work by 1 at time , here is the source code

#include <16F877.h> //standard includes
#include <stdio.h>
#use delay(clock=20000000) // 20 MHz clock
#define TOP_THRESHOLD 120 //define a threshold to determine near vs far, ie,
object or no object, for the top sensor
#define MID_THRESHOLD 140 //define a threshold to determine near vs far, ie,
object or no object, for the middle sensors
#define BOT_THRESHOLD 160 //define a threshold to determine near vs far, ie,
object or no object, for the bottom sensor
#define TIME_DELAY 30 //define a delay to wait while counting in order to
undersample
int time; //initliaze a variable to act as a counter
//code to deliver trigger pulse to sensors
void trigger() {
output_high(PIN_B2);
delay_us(12);
output_low(PIN_B2);
}
void main() {
while(true) {
//PIN_A1
time=0; //(re)set time to 0
trigger();
while(!input(PIN_A1)); //wait while the output of this sensor is low
//then when it goes high, count how many cycles it is high for
while(input(PIN_A1)) {
delay_us(TIME_DELAY);
time++;
}
//check time and take appropriate action, that is, vibrate or not
if (time<=TOP_THRESHOLD) {
output_high(PIN_C1);
}
else {
output_low(PIN_C1);
}
//repeat for the other 3 sensors:
//PIN_A2
time=0;
trigger();
while(!input(PIN_A2));
while(input(PIN_A2)) {
delay_us(TIME_DELAY);
time++;
}
if (time<=MID_THRESHOLD) {
output_high(PIN_C2);
}
else {
output_low(PIN_C2);
}
//PIN_A3
time=0;
trigger();
while(!input(PIN_A3));
while(input(PIN_A3)) {
delay_us(TIME_DELAY);
time++;
}
if (time<=MID_THRESHOLD) {
output_high(PIN_C3);
}
else {
output_low(PIN_C3);
}
//PIN_A4
time=0;
trigger();
while(!input(PIN_A4));
while(input(PIN_A4)) {
delay_us(TIME_DELAY);
time++;
}
if (time<=BOT_THRESHOLD) {
output_high(PIN_D0);
}
else {
output_low(PIN_D0);
}
delay_ms(3);
}
}
 

PIN_A1, A2, A3, A4 is sensors input. C1,C2,C3 and D0 is the vibration motor controls.
 

hey john are u asking me? or telling me about the pin configuration?
 

telling you. I hope thats what you are asking for?
 

man m not asking that..
i was asking for changing the source code in such a way that vibrations in VIBRATION motors becomes inversley proportional to the distance(means duty cycle of vibration motors becomes inversley proportional to distance,greater the distance less vibration,, shorter the distance the more vibration ) hope u got my point
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top