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
"thank u bro but can u write it"
Yes, I can.
View all questions in Keil forum