Pulse counting

I couldn’t find any specs on the pulse width or frequencies at which the imp could operate, so I did some simple experiments. I used a HP 33120A programmable function generator to input 3V pulses at a 20% duty cycle, and a 1 second gate time on the imp.

`function measure()
local count = hardware.pin1.read();

hardware.pin1.configure(PULSE_COUNTER, 1.0, 1);

If you need detailed specs of hardware capabilities, the STM32F205RG datasheet might be useful. Some features might be hidden by the imp’s firmware, but the datasheet still gives you the bottom line of what you can and can’t do.

True, the datasheet will give you the maximum hardware limits, but considering that the imp is running an rtos, which in turn is running the squirrel interpreter, those limits are unlikely to be reached. For example, the datasheet specifies 128k of RAM, but in reality, we only have around 50k available for user programs.

That’s true for the RAM, of course, but for almost all the rest of it the imp fairly transparently offers to Squirrel what the hardware provides. If you want to know how fast or slow the UARTs can go, or how much current the GPIOs can source, or exactly what the CLOCK_xxx options on the SPI do, then the datasheet (and the “reference guide”) are your best recourse. The only caveat is that sometimes it might be hard to work out what hardware facility a certain Squirrel facility uses: for instance, the pulse-counter is done by putting one STM32 timer in pulse-count mode and then gating it with a second timer. Its accuracy is thus as good as any bare-metal code on the same hardware could do: in your case there seems to be a very consistent 411ppm difference between the imp’s timebase and your signal generator’s timebase, but the results are otherwise impressively dead-on accurate.

We read all 1,300 pages of the STM32 reference guide PDF so that you don’t have to!


Yes, I have to admit I was impressed with the results. My function generator was last calibrated in 2009, but I’m more inclined to believe the inaccuracy is the imp’s clock. Even so, it’s still impressive.