View previous topic :: View next topic |
Author |
Message |
dxdxdx
Joined: 05 Jan 2011 Posts: 10
|
counter loop |
Posted: Tue Jan 18, 2011 7:48 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Tue Jan 18, 2011 2:17 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
dxdxdx
Joined: 05 Jan 2011 Posts: 10
|
|
Posted: Tue Jan 18, 2011 3:12 pm |
|
|
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? |
|
![](templates/subSilver/images/spacer.gif) |
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Tue Jan 18, 2011 6:08 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
dxdxdx
Joined: 05 Jan 2011 Posts: 10
|
|
Posted: Wed Jan 19, 2011 1:00 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
dxdxdx
Joined: 05 Jan 2011 Posts: 10
|
|
Posted: Sun Jan 23, 2011 3:26 am |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jan 24, 2011 2:09 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
dxdxdx
Joined: 05 Jan 2011 Posts: 10
|
|
Posted: Tue Jan 25, 2011 3:53 am |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
|