forager440
Member
I have a project originally written for the 3.2 that I'm trying to port to the 4.0. I have pretty much all functionality working exactly as original but I'm seeing strange behavior related to interrupts.
Here is the attach interrupt in void setup():
And the interrupt method:
This is exactly the same code as with the 3.2 but it's producing wildly different results. On the 3.2, accurlim outputs a steady value (eg. 12). On the 4.0, that same value is still the value that occurs most frequently but it also makes huge fluctuations, up to >1,000 and down to 0 for brief periods.
This code is for handling the J1772 EV charge protocol for automatic current limiting, where IN4 sees a 1khz square wave with the duty cycle used to communicate the current limit from the offboard charger.
The way IN4 is handled on the hardware side is the same so it's unlikely it's that. The only thing I can think of that could be causing this is that the 4.0 is so much faster than the 3.2 that isrCP is executing in a way that occasionally creates wildly inaccurate readings.
Any thoughts/ideas/solutions? Thanks!
Here is the attach interrupt in void setup():
attachInterrupt(IN4, isrCP, CHANGE);
And the interrupt method:
void isrCP() {
if (digitalRead(IN4) == LOW) {
duration = micros() - pilottimer;
pilottimer = micros();
} else {
accurlim = ((duration - (micros() - pilottimer + 70)) * 60) / duration; //pilottimer + "xx" optocoupler decade ms
}
}
This is exactly the same code as with the 3.2 but it's producing wildly different results. On the 3.2, accurlim outputs a steady value (eg. 12). On the 4.0, that same value is still the value that occurs most frequently but it also makes huge fluctuations, up to >1,000 and down to 0 for brief periods.
This code is for handling the J1772 EV charge protocol for automatic current limiting, where IN4 sees a 1khz square wave with the duty cycle used to communicate the current limit from the offboard charger.
The way IN4 is handled on the hardware side is the same so it's unlikely it's that. The only thing I can think of that could be causing this is that the 4.0 is so much faster than the 3.2 that isrCP is executing in a way that occasionally creates wildly inaccurate readings.
Any thoughts/ideas/solutions? Thanks!