We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hello,
I am using ADUC842.
Continuous pulse is being fed at port P2.6
I need to calculate rising edges of the pulse for 10ms time interval..
how should i proceed?
pls help.
Regards Mayuri
Now the scenario is different..
I have continuous train of pulses wherein pulse of 14 ms duration is always repetitive..
Its like if there are X number of highs in 14ms repetitive duration then the module is detected if not den it is not detected.. so now i need to count number of highs.....
Here is the code i have written
TMOD = 0x10;//CONFIGURING 14 ms TIMER TH1 = 0xFA;//CONFIGURING 14 ms TIMER
TL1 = 0x89;//CONFIGURING 14 ms TIMER
while (1) //IN CONTINUOUS LOOP { do { TR = 1; //START TIMER if (P1 == 1) //checking for high { count++; //if there is a high den increase the count } if(count == 5) //checking for count { display(); //module is detected and hence display } while (TF1 == 0); TR1 = 0;//stop timer TF1 = 0;
}
Is this logic fine?
Your logic don't even seem to agree with your english text.
You say a pulse is 14ms "pulse of 14 ms duration is always repetitive". But then you seem to want to write code that counts number of pulses within a single 14ms period.
Was it hurtful to follow the instructions how to post source code?
Your loop don't contain any clear of a variable so your count value will just go up and up and up and up - what logic is that?
Checking if a signal is high isn't the same as knowing there have been a pulse.
Next thing - high or low flank doesn't matter. Any sequence of many pulses must still have multiple flanks of each type. Why don't you want to let the hardware count flanks?
"Is this logic fine?" What does the debugger tell you?
pulse of 14 ms is repetitive means i m getting continuous signal of 14ms duration which has a unique pattern...
I am planning to use ISR...
Sorry - you are still not clear.
On one hand, you talk about "pulse" (that seems to be 14ms long). Then you talk about "continuous signal". Then you say these 14ms have a "unique pattern".
So you have a single pulse 14ms long? Or a time window of 14ms with either zero or one pulse? Or a time window of 14ms with zero or many short pulses? Or either "silence" or a continuous sequence of 14ms long pulses? Or something else???
Slow down, and write enough text that we can understand you. Or graph it. Below would be an example of an "unique pattern" within a 14ms window:
+--+ +--+ +--+ +--+ | | | | | | | | -+ +--+ +--------+ +--+ +------------------- |---------- 14 ms----------|
ya r8..this is the pattern i m getting...this pattern is repeting again and again
TMOD = 0x05; // TIMER 0 , MODE 1 SELECTED TL0 = 0x89; // 14 ms timer TH0 = 0xFA; // 14 ms timer
while(1) { do { TR0 = 1;
P1 = TLO;//reading the count in port } while(TF0 == 0); TR0 = 0; TF0 = 0; } } I am using timer as counter for counting pulses.... Is this logic fine?
I guess you just refuses to read up on how to post source code on this forum.
So we better refuse to read what you post too.
Didn't you notice the different look in my post?
#include <stdio.h> void main(void) { printf("Hello world!\n"); for (;;) ; }
And by the way - why don't you test your code instead of asking "is this logic fine"? Code having so few lines really do not take too long to test. You just can't develop applications without debugging.
Most probably not. Two pulses a pause and two pulses within a 14ms window? Most probably not.
But more importantly - you still haven't described the difference between the two states you want to detect. 1) what the signal looks like when the module is active 2) what the signal looks like when the module is not active 3) how short time the module may be active as shortest 4) how short time the module may be inactive as shortest 5) how fast you need to be able to detect when it gets activated 6) how fast you need to be able to detect when it gets deactivated 7) if there can be glitches in the signal, requiring any form of filtering of the signal (sw/hw) 8) if there is a silent phase where it matters if the signal stays high or low
In short - you have given us zero information about exactly what a program should look for. Zero as in: no information anyone who reads this thread can use. Because the facts you have given are mismatching.
You sometimes talks about a measurement window of 10 ms. Then you suddenly talk about 14 ms. You sometimes talks about pulses being 14ms long. Then suddenly about having multiple pulses within 14 ms. You sometimes talks about _needing_ rising edges to be processed. Then suddenly claims a scenario where it doesn't matter if you look for rising or falling edges. You sometimes talks about a continuous pulse train and then suddenly claims you see a specific pattern.
Do walk through the 8 bullets above, and give specific and carefully worded answers to each and every one of them. If not for us, but at least for yourself. It's impossible to implement a program without a specification. If you don't know what problem to solve, you can't develop an algorithm that solves the problem. And you can't do any testing of the written code since you have no metric to measure if the code is correct or not.
Why would you think the logic is fine?
You can make it a two timer/counter solution or a one timer/counter solution.
______ _______ | | | | | | | | __| ________| |
0110011 is the pattern i am getting which is having total duration of 14 ms.. The above mentioned pattern is repeating again and again..
Hardware working:
If the module is able to sense above signal then module has detected the probe from where above signal comes.
If module is able to sense some other pattern then module has not detected the probe...
So for module to sense this signal,i am counting number of pulses using timer as counter.
I am srry... i cudnt draw the waveform properly.. pls pardon
And you didn't notice the different color around my waveform, and then suspected that maybe I had used some special tags? So no reason to look at the posting instructions directly above the message input box to see what tags they mention there?
By the way - counting edges only tells us how many edges you will see. It doesn't tell you what pattern. And since you still haven't told us the answer to my questions, we still don't know if there could be other patterns with similar number of pulses.
Another thing - when using a 14ms measurement window, that window may not be perfectly aligned with the pattern. So sometimes you may start the window at a zero. Sometimes at a one. Sometimes just at a flank. If the pattern is "exactly" 14ms and your timer code takes "exactly" 14ms, then you can get the wrong count because the 14ms are never really _exactly_ 14ms. The side generating the pulses have a limited precision to the time-generating hardware. So have your processor. And there are latencies and jitter in the code execution.
How that affects your code is still unknown - without full answers to all questions, there are no proper specification available to know exactly what the full requirements are. All we know is that counting flanks does not detect a specific pattern. It can be enough to decide that the correct pattern is there if it is known that there can't be any other pattern that gives similar edge counts. But that is not covered by your descriptions of your problem.
How fast do you think this project will progress, if you can't manage to give a proper - and complete enough - description of the problem? Did you find my itemized questions unreasonable? Can you then explain why you think they are unreasonable?
i cudnt draw the waveform properly..
That really is not your issue. Your problem is your not understanding what you want to achieve. From what you had just described, it sounded like you wanted to recognize some certain patterns (but then it is not certain what you meant exactly by that).
If that is true, counting the rising edges does not help you, as Per indicated. Again, if you just want to detect pattern (a 10000000001 is the same as 101 for example), you will need to detect both rising edge (indicating 1) and falling edge (indicating 0).
An external interrupt will do it. But a simple solution will go like this:
set up the timer for desired duration; while (time is not up yet) { if (rising edge) {set bit 0, and shift left} if (falling edge) {clear bit 0, and shift left} }
Something like that will count the last n pulses within a given period of time, n=8 if you used "char", or n=16 if you used "short", ... So a pulse train of 0110110101 within 14 ms will be read as 10110101 for a "char" type.
The advantage of this approach is that you can easily compare the "pattern" afterwards. Its disadvantage is obvious, however. But without knowing your application, it is hard to tell if it will not work for you.
0110011 is the pattern i m getting ... i just want to count number of highs...
I have fed this signal to timer0 pin of micro controller
I want to use timer as a counter..
only high to low transitions are taken as 1 by timer..
in my case ,my counter should count 2...
That statement directly contradicts what you wrote earlier.
Before you move forward, you will have to make up your mind as to what you are trying to do.
Without knowing what you are trying to do with that piece of code, there is no way to know if the logic is fine.
Per is absolutely correct about this: you need to read and comprehend what others are telling you.
i need to count high to low transitions from my signal...
in my case it is two.....
#include <stdio.h> #include <math.h> #include <aduc842.h> sbit Tone = P3^5; void sendmoduleinit(void); void main() { PLLCON = 0x00; EA = 1; ES = 1; T3CON = 0x86; T3FD = 0x2D; SCON = 0x50; Tone = 1; TMOD = 0x50; TH1 = 0; TL1 = 0; while(1) { do { TR1 = 1; sendmoduleinit(); } while(TF1 == 0); TR1 = 0; TF1 = 0; } } void sendmoduleinit(void) { SBUF = TL1; while (TI == 0) { } TI = 0; }