aknalemdar
Newbie level 6
- Joined
- Sep 2, 2021
- Messages
- 13
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 108
#include <main.h>
#define LCD_ENABLE_PIN PIN_E0
#define LCD_RS_PIN PIN_E1
#define LCD_RW_PIN PIN_E2
#define LCD_DATA4 PIN_D4
#define LCD_DATA5 PIN_D5
#define LCD_DATA6 PIN_D6
#define LCD_DATA7 PIN_D7
#include <lcd.c>
unsigned int16 sayac=0;
void main()
{
lcd_init();
setup_timer_1(T1_FOSC | T1_DIV_BY_1);
while(TRUE)
{
set_timer1(0);
delay_us(1000);
sayac=get_timer1();
lcd_gotoxy(1,1);
printf(lcd_putc,"SAYAC = %lu",sayac);
}
}
I have a measurement interval of one millisecond. In this measurement range, a pulse may come while my signal is low for 1 millisecond. This pulse can be 1 microsecond or 900 microsecond. There may even be a pulse down to nanoseconds. I want to count with this pulse timer. So my goal is to use high speed and increase resolution and accuracy at the same time.Please explain the purpose of doing this. I ask because counting alone is pointless, presumably you want to use the number you re counting for some purpose and the extra code needed to achieve that could very significantly slow things down. For example, I think the code you show is to 'snapshot' the timer value once per millisecond but the routines to display the value could well take longer than that.
Brian.
re zamanlaması için
I have developed such a code block. Doing these operations with while inside the interrupt? Or do it all with separate cuts? When you calculate the command time, it's like they both come to the same time...In that case the best strategy would be to feed your pulse into one of the timers as an external source and create a time window to capture in using one of the other timers using the internal source. For example, use timer 0 to create the 1mS window and route the incoming pulse to timer 1. Use interrupts for the window timing, they will be far more accurate than a software delay.
Brian.
#INT_TIMER1
void TIMER(void)
{
disable_interrupts(INT_TIMER1);
while(input(pin_c0));
set_timer1(0);
while(!input(pin_c0));
x=get_timer1();
set_timer1(0);
while(input(pin_c0));
cap=get_timer1();
set_timer1(0);
while(!input(pin_c0));
y=get_timer1();
}
That was pretty contradictory. Make up your mind: is your shortest pulse 1 microsecond, or nanoseconds? Are you trying to count pulses or pulse width? It’s unclear. if you’re only trying to count pulses, it doesn’t matter if it’s 1 microsecond or 900 microseconds wide. (1 nanosecond might be a problem).
Mandallı 2 harici cihazları, ekran kartınızı seçiminiz için işleyin ve bitti.
İlk zamanlayıcıyı 1mS'de taşınacak şekilde ay
Now I am doing this process with PIC18F47Q43. But my system's internal oscillator speed is 64 MHz. For the timer I could probably pulse 64 MHz max. How can I count this at higher speeds? I am counting more than 60 thousand in 1 millisecond right now. How can I achieve higher count values? I don't want to struggle to be my FPGA knowledge.Do it in assembler code. You add extra delays by writing it in C. It isn't complicated and you can incorporate a block of assembly language inside the C code if you wish.
1. Set up the first timer to overflow in 1mS.
2. Set up the second timer to count mode.
3. Clear the count in the second timer.
4. Enable the first timer interrupts.
5. In the ISR, read the second timer, it will hold the number of pulses in the 1mS window.
6. After using the data, reload the first timer to overflow in 1mS again then go to step 3.
Brian.
This is still stupendously unclear. Whats your timescale? WHAT is “this 1ms”? The full display? The time between the two pulse-pairs? We have no way of knowing. WHAT pulse width are you trying to measure, I see 2 different positive pulses. If you need to count more than 60000, use a larger variable, or simply increment a second variable when the first one overflows. If you take a high frequency (300MHz) and then divide it, you now have a lower frequency; what do you think this is going to gain you?I have developed such a code block. Doing these operations with while inside the interrupt? Or do it all with separate cuts? When you calculate the command time, it's like they both come to the same time...
Code:#INT_TIMER1 void TIMER(void) { disable_interrupts(INT_TIMER1); while(input(pin_c0)); set_timer1(0); while(!input(pin_c0)); x=get_timer1(); set_timer1(0); while(input(pin_c0)); cap=get_timer1(); set_timer1(0); while(!input(pin_c0)); y=get_timer1(); }
--- Updated ---
View attachment 178467View attachment 178468View attachment 178469
I'm sending you a signal sample. The pulse duration within this 1 ms is variable. I am trying to measure this time.
View attachment 178470
Can there be more than 1 pulse in the mS window ? What is absolute accuracy neededThere may even be a pulse down to nanoseconds.
Do it in assembler code. You add extra delays by writing it in C.
I have to disagree to this "general" statement.That used to be true, but recently, the C/C++ compilers are so efficient that there is no
difference at all.
Or I'll use a nice digital filter. When I count 1 millisecond or microsecond in the processor itself, I always get the same result. But when I apply an external signal I see changes in the count. How can I prevent this?Hi,
I have to disagree to this "general" statement.
It extremely depends on what you and how you do.
My recommendation:
If you have timing critical situations: always do a timing check on the real part.
It may be as simple as
* set pin before a critical function
* clear the pin afterwards
* check the pin with a scope (best a digital scope with infinite view of the pulses)
(mind: any function may take longer time than usual when interrrupts cause additional delay)
Klaus
Explains video signal interaction more clearly.
I actually have a fixed frequency signal.
Or I'll use a nice digital filter. When I count 1 millisecond or microsecond in the processor itself, I always get the same result. But when I apply an external signal I see changes in the count. How can I prevent this?
I have to disagree to this "general" statement.
* set pin before a critical function
* clear the pin afterwards
* check the pin with a scope (best a digital scope with infinite view of the pulses)
Since the topic is " timing related with microcontrollers" .. I think the ASM/C/... speed discussion isn´t off topic.Calling a function is indeed longer because an extra jump is needed, and also a few push / pop
depending on the parameters. But the time again is exactly the same.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?