FAQFAQ   GalleryGallery   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in   Forum RSS Feed   Hacked Gadgets Main Site 

Need assistance in PIC using C programming!!!

 
Post new topic   Reply to topic    Hacked Gadgets Forum Index -> Electronic Help
View previous topic :: View next topic  
Author Message
keigo911
Newbie


Joined: 25 Aug 2008
Posts: 1

PostPosted: Mon Aug 25, 2008 5:25 pm    Post subject: Need assistance in PIC using C programming!!! Reply with quote

Hello guys, i am newbie here, was doing a project regarding infrared sensor autogate...

what i wish to ask is how to write the command for the situation stated below?

When a IR receiver received a signal from IR transmitter for more than 3 sec, only the DC motor will move CW or CCW? else, the motor will be remained stationary, even there is something pass by between.... the concept is some sort like a level sensor, to sense the container volume, which the IR receiver was triggered when the container full....

I have try the delay command be4, but it does not work.... it just delay the time of the motor to move, even the IR receiver just get the signal.... so what i wish is to make sure that when the object is stick stationary for more than 3 sec only the motor will be triggered...

thanks very much! hope some1 to help out......URGENT PROJECT!!!


to let all more understand about the code, i hereby posted up the program to emphasize the prob i encounter now...



#define IN1 PIN_B0
#define IN2 PIN_B1
#define IN3 PIN_B2
#define IN4 PIN_B3

#define MOTOR_1_CW 1
#define MOTOR_1_CCW 2
#define MOTOR_1_STOP 3
#define MOTOR_2_CW 4
#define MOTOR_2_CCW 5
#define MOTOR_2_STOP 6

#define OFF 1 //IR receiver open circuited
#define ON 0 //IR receiver connected to ground

void motor_motion(unsigned int motion);

void main()
{

// setup_adc_ports(ALL_ANALOG);
// setup_adc(ADC_CLOCK_INTERNAL);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);

SET_TRIS_B(0x00);
SET_TRIS_A(0xFF);

motor_motion(MOTOR_1_STOP);
motor_motion(MOTOR_2_STOP);

while(1){
if(input_state(PIN_A0) == ON
|| input_state(PIN_A1) == ON
|| input_state(PIN_A2) == ON
|| input_state(PIN_A3) == ON
|| input_state(PIN_A5) == ON){

int i;
i = 1;
if(i < delay_ms(1000)){
motor_motion(MOTOR_1_STOP);
}
motor_motion(MOTOR_1_CCW);
}
else motor_motion(MOTOR_1_STOP);

>>> Here is the condition to make my situation proved, i nid some1 help here, my program ady written as, but it only works as stated above<<<

}

}

void motor_motion(unsigned int command){
if(command == MOTOR_1_CW){
output_high(IN1);
output_low(IN2);
}
else if(command == MOTOR_1_CCW){
output_high(IN2);
output_low(IN1);
}
else if(command == MOTOR_1_STOP){
output_low(IN1);
output_low(IN2);
}
}
Back to top
View user's profile Send private message

Alan
Site Admin


Joined: 29 Jan 2006
Posts: 1399
Location: Winnipeg, MB

PostPosted: Mon Aug 25, 2008 10:49 pm    Post subject: Reply with quote

I don't quite understand what the system should do. Your main condition looks like it treats all of the IR sensors the same and that any of them will make the condition true.

What is your variable i for?

Under what condition should the motor run CCW or CW?
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    Hacked Gadgets Forum Index -> Electronic Help All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



Powered by phpBB © 2001, 2005 phpBB Group