#Is it possible to use a hardware timer?

1 messages · Page 1 of 1 (latest)

arctic siren
#

I need a timer with microsecond precision. Is it possible to use a hardware timer for this?

pliant quarry
#

Hardware timers are not available in C# API. if you really need you have to code in C possibly using interoper and then expose whatever it makes sense to your C# application

arctic siren
pliant quarry
#

Please note that I'm not saying that it can not be done or that it doesn't make sense. I don't know the details of your requirements, but the common usage of timers in these situations are very specific to the use case, and a general API will be missing something. Therefore the suggestion to use Interop and code the time sensitive code in C/C++ where you can fine control over the hardware and perform the computation heavy and time sensitive parts of the code.

arctic siren
#

Thank you for your reply. I think I have found the direction. I am a C# software engineer and I have only recently started working on embedded development and nanoframework. I think I still need to study some specific examples of nanoframework. Especially the use of Interop in the nanoframwork. 👍

pliant quarry
#

Good to know. Keep asking questions, you'll find a very friendly and helpfull community here. And have fun with C# and nanoFramework. 😉

tulip urchin
#

And to add: there are things like RMT or PWM that uses precise timers and can be used rather than traditional interrupt as they already provide (like for RMT) the decoding part in just 1 call! Check it, there are quite some samples like decoding remote controls protocols.

radiant fossil
#

I am sorry if I did not get it correctly, but for the Esp32 there's a solution: HighResolutionTimer - isn't that what OP was asking? it's built on to of the ESP32 hardware timers, if I understand it correctly, yet still there's some problems with microsecond handling in the nF (see related thread)

arctic siren
# radiant fossil I am sorry if I did not get it correctly, but for the Esp32 there's a solution: ...

Usually, hardware timers have a sequence number. However, from its constructor, it does not have a specified sequence number. I suspect that it is not a pure hardware timer; it might be a software timer based on a hardware timer or a software timer provided by FreeRTOS. I glanced at HighResTimer.cs. It calls the internal NativeEspTimerCreate function. I haven't fully mastered the nanoframework CLR yet, so I'm not quite sure what NativeEspTimerCreate does.😅