Main Site Documentation

Project - DL40 - I/O Module Firmware


#1

DL40 - I/O Module Firmware

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

  1. Pulse Counter which uses interrupts to count pin pulses - Peaks around 150kHz (150,000 pulses per second)
  2. 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
Edge High
Edgle Low
Both Edges
Level High
Level Low

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.


#2

Another fantastic contribution. Thanks.


#3

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 :slight_smile: ), but it will take a little longer to complete than the typical 1 or 2 day projects I have been doing.


#4

Very useful!


#5

Outstanding!

I vote that this becomes the default driver for the DL40. Maybe add a few PWM pins?


#6

I just noticed that the code share zip viewer does not show the full content of the zip file. Is there a structural limitation in terms of the folder depth ?

I will definitely add PWM support and I also want to add Analog support.


#7

+1


#8

Just a quick update, the DLIO demo now includes support for controlling the resistor mode of each pin.


#9

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.


#10

@ 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.


#11

your the best @ taylorza!
Thanks again


#12

I have just uploaded an update which supports Pulse Counting on the pins. This does not use the timers for counting, for two reasons

  1. Only a subset of the pins can be used as counter triggers on the timers
  2. I am saving the timers for the PWM implementation

The new interface is IPulseCounterPin which has a method ReadCounter() which will read the current pulse count.


#13

What kind of frequency do you think we’ll see it keep up with?


#14

I have not tested the throughput at all, so I honestly do not have a clue. But I will setup a PWM source and see how far I can push it and let you know the results.


#15

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.
[/em]


#16

The firmware and driver now support pin capture using the timer. This allows a capture of frequencies up to 12Mhz. There are four capture sources made up of 2 16bit and 2 32bit counters.


#17

Outstanding!


#18

Thank you, it has been fun. Next up PWM, and after that Analog inputs, then I think I am done with this driver.


#19

Very nice!

I took quick look at your example to see how to use it. It looks like it just continues to accumulate the sum until…? How do you reset the total? What’s the max it can accumulate?


#20

@ 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.