mrrwa/NmraDcc

[Question] About interrupts on an ATMega328

mijnmodelbaan opened this issue · 5 comments

Hi,

Great library you all created. Thanks!

My question is, can I use other pins than the 'standard' one (D2 on the Arduino) for inputting a DCC signal. F.i. the ATMega328P has a max of 23 programmable I/O pins all with the possibility of making them generate an interrupt. Say I want to use PD6 as input; this pin generates PCINT22 which would generate a jump to the PCI2 vector (and back). Is this already implemented in the library?

Thanks for reading/answering this,
Willem.

Hi Alex,

Thanks for the reply. I've been working on a bare version of the library (so only for ATMega328) and got it working to my needs, so with the PinChangeInterrupt implemented.

Now I'm working on another version with the complete library as it is now. See if I can get that working, too. Will be a little different from the above version as I don't want to introduce a lot of extra stuff, keep it as close to the original as possible.

Willem.

Hi Alex,

Finished the version mentioned in my previous post, the one with the complete library.
You can find the .h file here and the .cpp file here.
I want/need to do more testing. I only used one of your examples for testing and I've no idea what the effect is on the timing etc.

The files should work as they are, one only has to put the correct pin number in the calling program; #define DCC_PIN x
It should work with all the available I/O pins on an ATMega328P, digital and analog.

I've ordered some components and when they arrive I'll do some more testing and try to find out about the timing.

Willem.

Hi Willem,
where do you see a big advantage if the lib is able to use PinChange interrupts?

Pin 2 has no special features apart from generating Int0. So everything that you connect to pin 2 could also be connected to any other pin. Therefore it should be always possible to use pin 2 as DCC input. AtMega328 is by far the slowest of the supported processors. The PinChange interrupts always create an interrupt on every edge of the DCC signal. This is twice as much than necessary and even if the ISR at the 'wronge' edge is fairly short - you have the ISR overhead and this puts unnecessary load on the processor. Therefore the timing is much more critcal with PinChange interrupts. In my opinion without any real advantage.

Franz-Peter

Hi Willem,
Have you made any more progress with testing your proposed changes? If yes then reopen this issue