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

counter loop

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



Joined: 05 Jan 2011
Posts: 10

View user's profile Send private message

counter loop
PostPosted: Tue Jan 18, 2011 7:48 am     Reply with quote

Hi all, below is a picture that explains how my PIC16f877a is going to work. As you can see from the picture, that the input signal are 10 pulse in a sequence of 1-3-4-2 will be repeating forever. What I'm going to do is I want my pic16f877a to read the pulse, and on at every of the #5 pulse. I know the code will something to do with counter loop, but I'm just don't know how to write the code, anyone could please give me some idea. Thanks alot.



Uploaded with ImageShack.us
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Tue Jan 18, 2011 2:17 pm     Reply with quote

Timing is the only challenge here. Write a routine I'll call getpulse() that waits for the middle of the pulse and checks if the line is 0 or 1, then returns either when it pulse ends if it is a 1, or when it would end if it is a 0. This way it will re-sync itself on every 1.
Call getpulse() repeatedly till you get a 1 followed by a bunch of 0s, followed by 3 1's and more 0s. Then trigger your output on the next rising edge for a certain time, then start all over again.

Tell us more about your application and we can do more.
_________________
The search for better is endless. Instead simply find very good and get the job done.


Last edited by SherpaDoug on Tue Jan 18, 2011 6:10 pm; edited 1 time in total
dxdxdx



Joined: 05 Jan 2011
Posts: 10

View user's profile Send private message

PostPosted: Tue Jan 18, 2011 3:12 pm     Reply with quote

thanks SherpaDoug for the reply,

i have checked in the ccs manual, but i dont get the "getpulse()" syntax, what is this syntax function for? and how to use this function?
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Tue Jan 18, 2011 6:08 pm     Reply with quote

getpulse() would be a function you would write. Basically it would work like this:

1) Wait half a pulse length. - This is so we check the pulse in the middle.
2) Check if the input is 1 or 0.
If it is a 0 wait the other half a pulse length and exit the function returning 0.
If it is a 1 wait for it to go to 0 and exit the function returning 1.

Since I don't know how fast these pulses are or or what your clock speed and accuracy are, or what else the PIC may have to do at the same time, I can't give much more detail.
_________________
The search for better is endless. Instead simply find very good and get the job done.
dxdxdx



Joined: 05 Jan 2011
Posts: 10

View user's profile Send private message

PostPosted: Wed Jan 19, 2011 1:00 pm     Reply with quote

My input signal will be roughly like this :
Code:

while(TRUE)
{
//stroke 1
    output_high(PIN_B0);delay_us(2000);output_low(PIN_B0);delay_us(58000);

    //stroke 3
    output_high(PIN_B0);delay_us(2000);output_low(PIN_B0);delay_us(2000);
    output_high(PIN_B0);delay_us(2000);output_low(PIN_B0);delay_us(2000);
    output_high(PIN_B0);delay_us(2000);output_low(PIN_B0);delay_us(50000);

    //stroke 4
    output_high(PIN_B0);delay_us(2000);output_low(PIN_B0);delay_us(2000);
    output_high(PIN_B0);delay_us(2000);output_low(PIN_B0);delay_us(2000);
    output_high(PIN_B0);delay_us(2000);output_low(PIN_B0);delay_us(2000);
    output_high(PIN_B0);delay_us(2000);output_low(PIN_B0);delay_us(46000);

    //stroke 2
    output_high(PIN_B0);delay_us(2000);output_low(PIN_B0);delay_us(2000);
    output_high(PIN_B0);delay_us(2000);output_low(PIN_B0);delay_us(54000);
}


Then how should I write the getpulse() coding to detect when to on/off as my PIC output? Thanks alot.
dxdxdx



Joined: 05 Jan 2011
Posts: 10

View user's profile Send private message

PostPosted: Sun Jan 23, 2011 3:26 am     Reply with quote

Hello, is there anyone else who knows how to write this coding to detect number of pulse and generate an output at the pic? Greatly appreciated.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jan 24, 2011 2:09 pm     Reply with quote

Tell us the manufacturer and part number of the chip that produces these
signals. Tells us what product the chip is used in. Tell us the purpose of
all of this.
dxdxdx



Joined: 05 Jan 2011
Posts: 10

View user's profile Send private message

PostPosted: Tue Jan 25, 2011 3:53 am     Reply with quote

dear PCM programmer,

Actually this is part of my project. My project is regarding to design an engine control unit (ECU). Before I'm going to test the circuit on a real engine, my lecturer requested me to simulate an input signal first. So I will design my input signal for another PIC to process the input signal and generate an output. My input signal is in pulse form (1-3-4-2) as shown. So my PIC will going to control 4 fuel injector and turned on every time at the #5 pulse. This is roughly what is my purpose.

In reality, the signal is produced from engine sensor, I'm not sure about its manufacturer and part number. Hope this will make you clear. Thanks for your time.
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