I'm struggling with interrupts. My code is basicaly written to measure time between 2 falling edges and then based on that time i can calculate current power consumption. The problems starts when i try to measure time between falling edges on 2 pins at the same time, my code basicaly breaks and noone of measurments are correct.
So if only one(no matter which one) interrupt handler is attached everything works just fine and measurements are correct but if both are attached code breaks and everything is wrong.
Well they are not running exactly at the same time, interrupts cannot nest and they are assigned to different pins so in theory there is no corelation between them. By at the same time i meant that they both are turned on and they break code that is working separately. I jsut can't find what's really breaking it and how to prevent it
After fixing a typo and declaring variables as volatile the problem still exists, it looks like these interrupts somewhow messes up with elapsedMillis and it's systick interrupt
akimata:
After fixing a typo and declaring variables as volatile the problem still exists, it looks like these interrupts somewhow messes up with elapsedMillis and it's systick interrupt
Unlikely. If you look at the the applicable source code, you'll see it's just a wrapper for the standard millis()-based timing techniques. But, if in doubt, you can just implement those techniques yourself (per @cattledog).
Regardless, your code has other problems:
'solarPowerTimer' and 'homePowerTimer' are accessed in both ISR and non-ISR code. Why didn't you make them volatile?
On the other hand, 'currentSolarPower' and 'currentHomePower' are only accessed in non-ISR code. Why DID you make them volatile?
Also accesses to 'solarPowerTimer' and 'homePowerTimer' are really accesses to 4-byte values. These will be non-atomic on an 8-bit AVR. When you access them in non-ISR code, you need to protect those accesses with Critical Sections.