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.
View all questions in Keil forum