The following is a reasonably extensive demo project which could potentially be quite useful. The firmware allows you to configure any or all the available pins on the DL40 as either input, output or interrupt pins.
From the mainboard you can use the managed driver to configure the module pins and then react to interrupts, read or write the state of the pin etc.
This sample demonstrates reading multibyte registers and handling interrupts raised via the DaisyLink protocol.
The interface to the module contains the following
DLIOModule - Managed driver used to communicate with the DL40 module(s)
IInputPin - Interface for working with input pins
IOutputPin - Interface for working with output pins
IInterruptPin - Interface for working with interrupt enabled pins
IPulseCounterPin - Interface for working with pins that count the pulses
IAnalogInputPin - Interface for working with analog inputs (thanks to contribution from jernejk)
IPWMOutputPin - Interface for working with PWM outputs
There is support for two types of pulse counter pins
Pulse Counter which uses interrupts to count pin pulses - Peaks around 150kHz (150,000 pulses per second)
Capture Counter which uses the timer capture - Limited to 4 specific pins but has a peak of over 12Mhz (12,000,000 pulses per second)
Interrupt and pulse counter pins currently support interrupting/counting on the following states
Note: Capture pins only support Edge Low and Edge High
Input and Interrupt pins can have their pull-up/pull-down resistors configured. See the usage example.
I have not yet implemented glitch filtering. I will be adding these shortly.
The zip package includes a pre-compiled binary of the DL40 firmware for this sample.
Thank you Gus. I really enjoy working with the DL40, I think it has huge untapped potential. I have something very exciting planned (at least exciting for me ), but it will take a little longer to complete than the typical 1 or 2 day projects I have been doing.
great work @ taylorza!
Does this / Can this include the pulse counter example you did a while back?
Also if you could add debounce to it it would be perfict.
Thanks again for all the additions to the community.
@ MikeCormier - Pulse counter is a good idea, I did not think of that one. So you could configure a pin as a pulse counter pin and then when you read the value it gives the count, the configuration of the pin can dictate if it resets on read etc.
Consider it done, but you will have to wait for the weekend, that is the only time I get to actually work on this stuff.
Debounce is something I will tackle, easy enough for the interrupt input, but I am not sure about the pulse counter mode I will need to get stuck into the datasheet to check that, maybe the hysteresis will do the trick for that.
Update: Setting a few compiler optimization this jumped to 58kHz, so I am reasonably confident that optimizing the interrupt handlers will make a difference as well. Update 2: Further compiler optimizations has bumped this to 150kHz.
This should be significantly improved if I add support for pulse counting using the counter mode of the timers.
[em]Out dated info: This is here just as a record of where this started
With the current interrupt handling the pulse counter is maxing out at just a pinch below 48kHz. I do not know if that is the limit of the interrupt rate of the LPC1113, so baring that, the interrupt handling code can definitely be improved which might take this a little higher.
@ ianlee74 - The counter is passed between the DL40 and the mainboard as an UInt32 so the max value is 4,294,967,295, the 16 bit counters are limited to 65535 so they will not go beyond that.
I do not have a reset, it is quite easy to add if required, however it is probably quicker to store the last value you read and subtract that from the new value than to reset which will incur the latency of an extra DaisyLink messages being sent to the board. But like I say, it is easy to add if that is more convenient and I would be happy to do it.