Chat freely about anything...

User avatar
By jdarling
#34227 I've had a NodeMCU lying around for a while now and haven't done anything with it. I have need to build a web connected high speed (well micro-second resolution) differential timer to track gravity powered racers (Soap Box Derby Cars, garage monsters, trikes, etc). This is on a two lane setup, both lanes should start at the same time, but there could be a minor difference between the two.

Ideally there are 6 things that should be identifiable:
1) Total time from start to finish in Lane 1
2) Total time from start to finish in Lane 2
3) Differential of start times
4) Differential of finish times
5) Who won by crossing finish line first
6) Who won taking differential of starts into consideration

Raw numbers would then be delivered to some type of web API. Probably a REST over HTTP endpoint via a JSON POST. Something like:

{
lane1Start: 0.000, // First lane to start would always be 0.000
lane2Start: 0.001, // Lane 2 started 1 micro-second after Lane 1
lane1Finish: 30.034, // Lane 1 took 30.034 seconds to move from 0.000 to finish
lane2Finish: 30.025 // Lane 2 took 30.025 seconds to move from 0.000 to finish
}

So, I'm curious, does anyone think that the ESP8266 has a high enough resolution timer to do this? Considering its really just recording 4 points in time and then delivering them back to a host.

Two points are an absolute must (finish line differential between the two).

Could there be more than 4 points sampled?

Would I need to use assembly/C or could it be done in Lua?

I'm guessing some type of interrupt would need to be used. Each signal running one of the input pins, trigger on those signals going high/low.

Could I measure the amount of time the signal was high/low? Would be really cool since from that you can calculate rough speed (length of car is ~6ft, so amount of time 6ft took to cross sense should give rough idea of speed).

Any help greatly appreciated,
- Jeremy
User avatar
By dkinzer
#34245 [quote="jdarling"the ESP8266 has a high enough resolution timer to do this?[/quote]The free-running RTC Timer2 (FRC2) has a resolution of 200 ns. Timer2's counter is 32 bits wide giving it a span of about 859 seconds. For intervals less than that span, subtracting an initial sample of the timer from a later sample of the timer will give an accurate representation of the elapsed time (even if the counter wraps between the two samples).

If that doesn't meet your needs, you could opt for using RTC Timer1. Although it is only a 23-bit timer you can set the prescaler on it to get a larger range and lower resolution. This timer is used for PWM so the two uses are mutually exclusive.

Both RTC timers are accessed using RTC_REG_READ() and RTC_REG_WRITE().