hi can anyone help me i need to calculate the time between 2 rising edge of square wave signal the first signal is relayed with pc10 the second with pc11
that is the schematic :
s14.postimg.org/.../counter1.png
Before you can calculate anything you're going to first have to measure, against some other timebase you have running at some known rate.
Most micro's with timer peripherals do have documentation and manuals for the express purpose of explaining how the hardware works, but you have to read it.
i try with this code but it does not work can anyone help me uint8_t ch[10000]; double timerValue; if (GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_10)==1) { do { timerValue = TIM_GetCounter(TIM2);
} while(GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_11)!=1) ;
} sprintf(ch,"%lf seconde", (double)timerValue); LCD_SetTextColor(LCD_COLOR_WHITE); LCD_SetBackColor(LCD_COLOR_BLACK); LCD_DisplayStringLine(LINE(9),ch);
Why should it work?
You show no code that detect the leading edge.
And you show no code actually starting the timer. Unless you start the timer on the leading edge, the length of the pulse would be (t1 - t0) where you obviously have to take into account t0 which is the timer value at the start of the pulse...
Another thing - haven't you looked into your processors ability to start, stop or snapshort a timer when an input signal changes? That allows you to measure signas with much higher timing resolution. And you can even keep down the power consumption by not wildly busy-looping while you measure. Or spend the CPU capacity doing something else. Why not consider elegance instead of brute force?
Just a footnote - exactly how big is your LCD, when you feel you need a ten thousand character long text buffer for your text lines? It must be a mighty impressive display.
But the rest of the world would probably consider a variable named "ch" to represent a single character - sneaky of you to use that name for a huge buffer.
so can u help me plz to modify the code
I did.
thank u bro but can u write it
And you're using what processor?
Not sure if the GPIO method is particularly effective. But you'd want to get a time stamp for the first edge, and then get a time stamp for the second edge. If you know the time of each, you can calculate the difference between them.
wait while PC10 high wait while PC10 low get time stamp t1 ; PC10 now high wait while PC11 low get time stamp t2 ; PC11 now high delta = t2 - t1
Remember to use PRE tags when posting source, make sure you post enough code to see what you're actually doing/configuring.
"thank u bro but can u write it"
Yes, I can.
tks u bro for reply...... hight means 1 and low means 0 or it is false to use 1 and 0 as edge detector ????? other question i do it like that is that correct ???
uint8_t ch[10000]; double timerValue1,timerValue2 ,delta;
do { timerValue1 = TIM_GetCounter(TIM2);
} while(GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_10)!=1) ; do { timerValue2 = TIM_GetCounter(TIM4);
} while(GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_10)!=1) ; delta= timerValue2- timerValue1;
} sprintf(ch,"%lf seconde", (double)delta); LCD_SetTextColor(LCD_COLOR_WHITE); LCD_SetBackColor(LCD_COLOR_BLACK); LCD_DisplayStringLine(LINE(9),ch);
What does the documentation for the library say? You've been asked several times about what you're using, I only know what limited context you've provided in the thread.
TIM2/TIM4 why different timers?
http://www.keil.com/forum/tips.asp
the first timer is used to calculate the first rising edge the other timer used to calculate the second rising edge but it does not work because it calculate only the first do{} while ;
You are aware that a single chronograph can be used to take quite a number of intermediate times when you have a runner doing a 10000m run?
It's just that you don't seem to have considered yet what it means to either start/stop a timer. Or to have a free-running timer and just take multiple snapshots and compute the difference between the snapshots. So start thinking about how you could use a single clock to both measure the total time that runner needs for 10 km running. And how you can manage to figure out each individual lap time. Or maybe each individual 1km section time.
You will fail again and again until you stop playing around and start to think about what the timer actually does. Stop thinking that the timer magically starts being in existence the moment you start to sample values. And by the way - you don't even need to capture values continuously within the loop, since it's enough to capture the value directly after you found the condition change that means you want to exit.
In the end, trial and error really is not a good route since it's so very slow. That's basically what evolution does. So trying millions of small biological changes over hundreds of generations to try to figure out if some changes might lead to an improvement or not. It's just that trial and error (in science also sometimes discussed as Monte Carlo methods) means you need a huge number of dices to be able to test enough random solutions concurrently - just to get some decent progress.
Keil continues to run this forum like fools. I can't use the word "s t o p w a t c h" without getting error 500 when trying to post. Just as this forum constantly fails to accept posts relating to "w a t c h d o g". Who thinks it's clever to filter these words on a forum specifically related to embedded development??? I have also notified their support but they don't seem to be able to figure out why anyone might want to legimitely want to use the word "w a t c h" without intending it as spam.
How old are you?
How many w atches would you need to time your trip between your home and the closest town?
What processor and board are you using?
watch