CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

how times it takes

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
mortaurat



Joined: 23 Jul 2009
Posts: 14

View user's profile Send private message

how times it takes
PostPosted: Sun Oct 18, 2009 11:42 am     Reply with quote

Hello,
I wrote a part of code and I don't know how many times it takes.
I cannot use a timer because I want to use this function while 10 seconds, then I use an another function.
Code:

#include "16F628A.h"
#use delay(clock=20000000)
#define  BP PIN_A0
#define  LED PIN_B0
#define  injecteur1_in PIN_A1 
#define  injecteur2_in PIN_A2
#define  injecteur3_in PIN_A3
#define  injecteur4_in PIN_A4
#define  injecteur1_out PIN_B1
#define  injecteur2_out PIN_B2
#define  injecteur3_out PIN_B3
#define  injecteur4_out PIN_B4

void pilotage_injection_demarage()
{
//------------declaration variables------------
unsigned int32 retard1=0, retard2=0, retard3=0, retard4=0,temp=0 ;
int decrement=2; //1/2 = 50% d'enrichissement

while(temp<60000){
//------------si l'injecteur est piloté (etat bas) on incremente--------
if(input(injecteur1_in)==0)
{
   retard1++;
   output_low(injecteur1_out);
}
if(input(injecteur2_in)==0)
{
   retard2++;
   output_low(injecteur2_out);
}
if(input(injecteur3_in)==0)
{
   retard3++;
   output_low(injecteur3_out);
}
if(input(injecteur4_in)==0)
{
   retard4++;
   output_low(injecteur4_out);
}

//--------------si le pilotage est arreté, mais que retard > 0
if(input(injecteur1_in)==1 && retard1>0)
{
   retard1=retard1-decrement;
   output_low(injecteur1_out);
}
if(input(injecteur2_in)==1 && retard2>0)
{
   retard2=retard2-decrement;
   output_low(injecteur2_out);
}
if(input(injecteur3_in)==1 && retard3>0)
{
   retard3=retard3-decrement;
   output_low(injecteur3_out);
}
if(input(injecteur4_in)==1 && retard4>0)
{
   retard4=retard4-decrement;
   output_low(injecteur4_out);
}

//------------si pilotage arreté et que retard <=0
if(input(injecteur1_in)==1 && retard1<=0)
{
   output_high(injecteur1_out);
}
if(input(injecteur2_in)==1 && retard2<=0)
{
   output_high(injecteur2_out);
}
if(input(injecteur3_in)==1 && retard3<=0)
{
   output_high(injecteur3_out);
}
if(input(injecteur4_in)==1 && retard4<=0)
{
   output_high(injecteur4_out);
}
}
temp++;
}

The principle is to increase a duty by 50% while ten seconds, then it's increased by 20%.
In order to do this, I increment a variable when the signal is at the low state, then, when the signal is at the high state, I decrease the variable until it reach 0.
Next the output is at the state high.
If I increment by 1 and decrement by 2 I will have an increase of 50%.
If I increment by 1 and decrement by 5 I will have an increase of 20%.
etc....
So my question is what's the value (of temp) that corresponds to a time of 10sec ?

Thanks a lot
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Oct 18, 2009 2:39 pm     Reply with quote

See this thread on measuring the execution time of a routine or program:
http://www.ccsinfo.com/forum/viewtopic.php?t=40457
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon Oct 19, 2009 2:56 am     Reply with quote

Spotted a bug:
Code:
if(input(injecteur1_in)==1 && retard1<=0)
retard1 (and the others) are declared as unsigned integers so can never become negative. Solve it by declaring the retardx variables as signed.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion 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