CrazyEngineers Forum

******************************************
Welcome To CrazyEngineers (CE) – an online community of engineers from all over the world! With the younger CEan at 84 and the youngest at 16, CE boasts of professional engineers, students, professors, entrepreneurs, CEOs, geeks & nerds. We exchange innovative ideas, share knowledge, help each other and expand our worldwide network of engineers! You need not have a formal degree in engineering to be a part of CrazyEngineers! Need we say more?
Join CE! | Be a CE Ambassador! | Forgot password? | Sponsor CE | Contact Us
Navigation
Go Back   CrazyEngineers Forum > CE : Technical Discussions > Computer Science & IT Engineering
Reply

  #1 (permalink)
Old 26th August 2008, 07:02 AM
CE - Newbie
 
I'm a Crazy Electronics Engineer
Join Date: 26th August 2008
Posts: 2
Exclamation Need assistance in PIC using C programming!!!

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);
}
}
keigo911 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored links
  #2 (permalink)
Old 26th August 2008, 05:21 PM
CE - Regular Member
 
I'm a Crazy Electronics and Communication Engineer
Join Date: 19th March 2007
Location: Jeddah, Saudi Arabia
Posts: 72
Send a message via AIM to bayazidahmed Send a message via MSN to bayazidahmed Send a message via Yahoo to bayazidahmed
Default Re: Need assistance in PIC using C programming!!!

I couldnt understand when do you want to turn it CW and when CCW?

As far as my understanding goes your while part can be modified to give a simple solution as follows

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)

{
delay_ms(3000);


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)

{
motor_motion(MOTOR_1_CW); //or CCW if you want
}

}
}
bayazidahmed is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)
Old 27th August 2008, 07:38 AM
ash
Moderator
 
ash's Avatar
 
I'm a Crazy Communications Engineer
Join Date: 12th July 2007
Location: IIUM, Malaysia
Posts: 1,506
Default Re: Need assistance in PIC using C programming!!!

Ahmed, doesnt your solution mean it'll check twice: the second time AFTER a delay of 3 seconds? The condition stated in the problem is that the IR is received for a continuous 3 seconds before the motor will move. If you just delay it, you wouldn't know whether there was an interruption during the delay.

I think better we try adding a timer counter within a while loop, so when the timer reaches 3 seconds, we switch on the motor. Maybe we can take advantage of the TMR function of the PIC? When the conditions are met, run the timer, and check timer again continously. If there is an elapsed time of at least 3 seconds, then run the motor.

Of course, timing is based on the clock frequency you are using Keigo, can you tell us more about the PIC you are using, and at which clock speed?
__________________
Keep it simple. Keep it real.
| New to CE? Click here! | Join our CE Bot project! | Problems? Questions? PM or mail me at ash{at]crazyengineers{dot]com |
ash is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)
Old 27th August 2008, 09:58 PM
CE - Newbie
 
I'm a Crazy Electronics Engineer
Join Date: 26th August 2008
Posts: 2
Default Re: Need assistance in PIC using C programming!!!

ya ash, it is actually exactly what u r saying.... this is the prob i encountered and the code is just able to delay, but not continue....

btw i am using PIC16F877A with the DC clock speed of 20Mhz as usual...

if u have the idea on how to do it, would u mind to edit the code given to me so i can test it on my Proteus ISIS 7 Pro simulator..... I am using CCS C Compiler for the code compilation

thank you!
hope to get your reply soon as it is an urgent project.....
keigo911 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored links
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +5.5. The time now is 11:58 PM.
Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0
Member comments are owned by the poster. Copyright © 2005-2008 CrazyEngineers.com. All rights reserved.Ad Management by RedTyger