How to Counting Pulses - 31250Hz

I’ve been playing with a AS3935 Franklin Lightning Sensor IC and having some success, but one challenge remains and that is to tune the capacitors which is rather simple in that you try a setting and then count the pulses on the IRQ pin. The target however is 31250Hz which adds to the challenge, I’ve tried doing a digitalInput on the pin but I fear that .NetMF (using a Spider, might have to switch to Raptor?) is a tad slow for counting that fast (can hardly wait for AOT compiles), so I tried a PulseCounter where I connected the pin of interest to the A and added a ground wire, however this didn’t seem to count anything. I looked a PulseInOut module but I’m not sure its fast enough either. Any suggestions or comments on what I could be doing wrong?


OK I’m an idiot and must have had it wired wrong as the PulseCounter is now working. I guess that is what happens when you turn a software dude loose on hardware, but I’m getting better at hardware, thanks Gadgeteer.

1 Like

I had to go look at the AS3935 data sheet, I believe you are trying to tune the loop antenna, by dividing the 500Khz resonance frequency by 16 and driving the IRQ pin with the divider’s output.

The Pulse Counter module should handle the task, are you setting non-quadrature mode in the MDR0 bit 1 and 0 set to zero. This will configure A as the pulse input and should be connected to the IRQ pin. The B terminal should be left unconnected (is pulled up on the PCB) to place the counter in count up mode. The CNT_EN pin will enable the counter to count up, so this signal could be controlled by a I/O pin on the .NETMF module, so to reduce the error of timing on this signal one could enable the counter for 10 or more seconds and divide OTR register by this value to obtain an average count. With the counter configured as a 32 bit counter this timing to the counter enable pin should be quite relaxed. (I calculated about 137438 seconds, but this would depend a bit on how far off the loop resonance frequency is off.

I have no direct experience with the AS3935 or the LS7633R device. If description matches what you tried then possibly we could go into more details on the actual register programmed values.

After see the weather reports in Alberta, I understand the need for this project.


1 Like

Glad to see you got it sorted, good luck with the rest of your project.


Time to invest in a scope?

@ ianlee74 - How about a Grid Dip Meter? Mine was cheaper then a scope.

@ PHITEK - That is pretty much what I was trying to do, but apparently my test lead wasn’t connected properly so it was coming up with nothing. This is a test that really only needs to be run once as once I have the TUN_CAP setting (in my case 7 is pretty much dead on) it should be reasonably static and I can include setting it in my initialisation routines. Of course now that I have an optimized lighting detector running, the storms have run off, but I’m sure I’ll get some more chances to test it soon.

@ Ian while I would love a scope, but my Scottish nature just can’t cough up the money, especially when I can make my own test devices with Gadgeteer.

My Scottish bones (from a looooong way back) also say the same, but Rigol DS1054z is an awesome buy for a 4-channel scope.

That would certainly work for this case but overall its a less useful tool from what I know of it. I picked up my Rigol DS1052E for ~$300 a few years ago. No 2nd mortgage on the home required!

@ ianlee74 - The other reality is I’m not sure where I would put a scope as between computer monitors and Gadgeteer projects I’m pretty much out of any desk space for a scope, as it is people are scared to walk into my office as there is stuff all over the place or maybe its that canister of weapons grade plutonium that is lurking somewhere in here, damned if I can remember where I put it. International travel is always fun as my laptop bag always freaks out customs agents as pretty much every sensor they have goes off. That reminds me one of the projects I want to do is a radiation detector, been thinking of using one from MightyOhm ( Geiger Counter | MightyOhm ) or from Sparkfun ( can detect Alpha radiation as well).

@ ianlee74 - Your right a scope would be a good choice at that price, I was not aware of the Rigol line of scopes. Most of my equipment if from ebay after dot com crash, or I borrow it from work.

@ Duke Nukem - O’scopes look cool. There’s always a good place to put one :wink:

You might watch Electronics Goldmine. They send me regular sales on cheap Geiger tubes.