Timer example
Timer example
Is there any simple example code for a single timer of simple start and stop in Arduino other than which are given in its documentation? I just want to start and count when the process gets a start then when the process gets end i want to stop the timer.Kindly post the code if you have.
Re: Timer example
Mod Note: Moved to Arduino sub-forum
@arkayabt
Could you be more specific as to what timer you're talking about, and what you mean by a "process getting a start"? For example, are you expecting to use a software timer or a hardware timer? What order of precision do you need for this timer (e.g. milliseconds or microseconds).
If you simply want to time the duration of a piece of code, you can call xthal_get_ccount() to get the current CPU clock count at the start and end your code, then divide the difference in clock count by your CPU frequency to get the elapsed time.
@arkayabt
Could you be more specific as to what timer you're talking about, and what you mean by a "process getting a start"? For example, are you expecting to use a software timer or a hardware timer? What order of precision do you need for this timer (e.g. milliseconds or microseconds).
If you simply want to time the duration of a piece of code, you can call xthal_get_ccount() to get the current CPU clock count at the start and end your code, then divide the difference in clock count by your CPU frequency to get the elapsed time.
Re: Timer example
Hi ESP_Dazz,
I want to convert below code to esp32 arduino code using timer to find remote control key value without using any library and rmt. When i press the key of remote timer starts counting when it detects low and high pulses means timer count pulse duration of high and low pulses and store in to an array.
Snippet of code:
Here no_pulse, total_pulse, and time_over value is for enter the loop when key of remote press.
I want to convert below code to esp32 arduino code using timer to find remote control key value without using any library and rmt. When i press the key of remote timer starts counting when it detects low and high pulses means timer count pulse duration of high and low pulses and store in to an array.
Snippet of code:
Here no_pulse, total_pulse, and time_over value is for enter the loop when key of remote press.
Code: Select all
while((no_pulse < total_pulse)&& (time_over == 0))
{
while((IR_IN == 1) && (time_over == 0) );
TON_bit = 0;
TON_bit = 1;
TMR1 = 0;
while((IR_IN == 0)&& (time_over ==0));
irdata[no_pulse++] = (TMR1>>8)&0xff;
irdata[no_pulse++] = TMR1&0xff;
TON_bit = 0;
TON_bit = 1;
TMR1 = 0;
while((IR_IN == 1)&& (time_over ==0));
irdata[no_pulse++] = (TMR1>>8)&0xff;
irdata[no_pulse++] = TMR1&0xff;
}
-
- Posts: 9730
- Joined: Thu Nov 26, 2015 4:08 am
Re: Timer example
I don't understand, where is the problem exactly, are you having issues with the xthal_get_ccount() call my colleague told you about? Also, what is the reason you don't want to use RMT?
Re: Timer example
Hi ESP_Sprite,
Thanks for the reply. I don't have any knowledge about xthal_get_ccount() and i am not able to find any arduino code using xthal_get_ccount() which i can understand and built code. And as i am new to esp32 so i want to read remote control signal using this way because i want to read any type of remote key value and then store it into an array. As per i read rmt library not all types of remote protocol. For knowledge purpose i want to know that using rmt will i be able to store all types of remote key values and generate the same signal frequency in the blaster circuit? If yes,is there any code in arduino which help me with this? And if possible guide me in reading remote key value using timer only because in future if any new remote protocol may come there is no need to do any modification in this.I want to do in this way because as per my limited knowledge i find this way is the simplest way to read remote control value.
Thanks for the reply. I don't have any knowledge about xthal_get_ccount() and i am not able to find any arduino code using xthal_get_ccount() which i can understand and built code. And as i am new to esp32 so i want to read remote control signal using this way because i want to read any type of remote key value and then store it into an array. As per i read rmt library not all types of remote protocol. For knowledge purpose i want to know that using rmt will i be able to store all types of remote key values and generate the same signal frequency in the blaster circuit? If yes,is there any code in arduino which help me with this? And if possible guide me in reading remote key value using timer only because in future if any new remote protocol may come there is no need to do any modification in this.I want to do in this way because as per my limited knowledge i find this way is the simplest way to read remote control value.
-
- Posts: 9730
- Joined: Thu Nov 26, 2015 4:08 am
Re: Timer example
Ah, gotcha. That call indeed is not Arduino-specific, even if you can still use it. Arduino has call that is more specific to it, namely micros().
Re: Timer example
If this is the case then how do i reset micros() between each pulse interval? I was not able to reset micros() when i used it.
-
- Posts: 9730
- Joined: Thu Nov 26, 2015 4:08 am
Re: Timer example
No need. You store micros() at the start of whatever you're doing, wait for the pulse, then take the difference between the current value of micros() and what you stored at the start, and you get your value.
Re: Timer example
I have used micros() the same way as you suggest but I am not getting the same value each time for certain key.
-
- Posts: 9730
- Joined: Thu Nov 26, 2015 4:08 am
Re: Timer example
Yeah, there's likely some jitter in the remote control and receiver. Last time I checked the periods could easily be off by 10% or so. It shouldn't matter; most remote control protocols use a huge time difference of 300% or so between transmitted one an zero symbols.
Who is online
Users browsing this forum: No registered users and 35 guests