Need help with timer code

Hi, guys!
My story…: need to generate and count constant timer Ticks (>1MHz) between digital signals high, signal duration 100us from a IC and its period(high to high) vary every time - than I will to analyse and integre data(counted ticks) I get, but it is not a main problem at the moment … I am a novice with c# and microcontrollers programming. I have lot of literature, but it will cost many days, before I get an information I need…
thanks before!
Have a nice day!

Generating and reading pulses is very simple but has real time requirements. We have SignalGenerator in premium libs to generate pulses but this is still not suited for high frequencies, 1Mhz for example.

Now, any little 8bit micro can do this very easily as the micro will do nothing but generate these pulses to count pulses. But doing this on a high end system like NETMF is not ideal. You need the right tool to do the job.

Which board do you have?

And welcome to the community.

Thanks, Gus!

…that was extremely fast!!!
I have Cerberus, I found it perfect to my project, but maybe I m wrong… so what are U saying about premium libs, and what is its range of preferable frequency …
maybe U know better idea, how to detect and measure something like rpm change wiht clasical trigger wheel, like on car engine…
And yes 1MHz is to mutch for my current project :slight_smile: but in future projects it will be just in time.

You can use RLP lite to do all this but it is advanced. Are you good with c and micro controllers?

:frowning: I m learning right now… and doing my best, but it is better to ask for some specific microcontrollers info, to guys who do codes every day, is`t it? :slight_smile:
any info is wolcome, and big thanks from me!

Maybe start with c# and generate/read simple waveforms at slow rates, like 1khz.

That is why I made this topic… Any ideas about code for 1KHz ticks counting at the 100us long digital in signal rising?

For slow clocks, and testing purposes, use a thread that toggles the pin. To read, use interrupt port class.

Note that because of the GC, you won’t get a perfect waveform.

If all you are doing is a loop to generate clock then GC should never run.

It’s fairly unlikely that an entire ARM MCU is being used as a simple 1KHz clock generator…

I’m not saying it can’t be done, just that it’s important to be aware that if you’re trying to generate a clock signal, you need to make sure that the GC isn’t triggered.

I found this one → , who can tell me, is it somethink I need, and how to do this one on cerberus.
if I make my project without RLP, and make task little bit slower → countig pulsees in time, like tachometers counting frequency?

@ triangle - I see no reason why you cannot do the same thing on the Cerberus, the registers etc. will differ but conceptually it should be the same. The only caveat that I can think of is that at one point when I was scanning the code I noticed the STM32 firmware uses cascaded timers to overcome the timer resolution issue so I am not sure which timer will be available, always safest to use the last timer so if there are 4 timers (0 - 3) use timer number 3.

Not to sound self promotional (too late?), you might consider using a DL40 for this, I put up a firmware and the corresponding managed driver code for the DL40 which can amongst other things perform pulse counting.

The current release is on codeshare which include the compiled firmware

Going forward you will also be able to get the latest code from Codeplex

The potential advantage with this, is that this portion of your code will be independent of the main board, so the code you use on the Cerb can work on a Hydra or the next .NETMF board. Whereas using RLP/RLPLite or Register class ties your code to the target CPU. (Make no mistake I am a huge RLP fan, just trying to think practically here).

@ taylorza
Thanks for advice. DL sounds good, I will think about it it, and it is not to late, because, I am still at the same place, where I was month ago. RLP is is bit advanced for me. If U promise help to me with DL, I will try it!! :slight_smile:

@ triangle - I will gladly help with the DL40 and I am sure where I can’t one of the many knowledgeable community members will jump in.

1 Like

@ taylorza what stable working frequency of DL40 we are talking about?

@ triangle - The firmware as it stands has two counters
[ol]Interrupt Based counter - This counter can be used on any of the available pins - Max attained frequency ~150kHz
Timer capture counter - This counter uses one of the 4 timers to count pulsed, it is limited to specific pins on the chip but has a frequency peak of ~12MHz[/ol]

Those peaks are not very scientific, I do not have all the right equipment to test, but they give an indication of the upper limit.

The codeshare usage example for version 6. shows a simple Capture Counter that is polled every second to get the current count value. Basically the steps are as follows

 // Create a Capture Pin using Timer 0, which is a 16 bit timer capturing pin 0.2
_counter = _io.CreateCapturePin(CaptureSource.Capture16_0_2,

 // Create an instance of the DLIOModule attached to Gadgeteer Socket 7
_io = new DLIOModule(4);

 // Read the counter value
ulong reading = _counter.ReadCounter();

finally I have DL40, I try to do some examples, but have some problems with understanding of principles.
Can U (or somebody else) please, explain me step by step, how to do thinks with dl40 if I have cerberus, how to advance samples for my task?
And is it possible to do bool at cerberus with other conetcted modules after I get results of fast counter at dl40 and other conetcted modules to cerberus?

@ triangle - In your profile you said you had basic software experience. I would suggest you get familiar with C# programming and >NET Microframe Work before you start with DL40 programming.

for me it is easier to learn on examples, I have one project, it is out of date now, but I will finish it anyway and learn something more with every project, cause it is not my speciality, but I wish to do things with .NET Gadgetters . Without system I will learn simple tasks all my life, but ther is no guarantee I can finish complete project! In different fields of my interests its works good, hoope it still works…