Go Down

Topic: Changing ISR's return address to a function's memory location? (Read 3719 times) previous topic - next topic


At 60 Hz there are 16,666 microseconds in an AC cycle.

Another way of looking at this is to wonder why one Arduino wouldn't be plenty fast enough to read voltage and current with successive analogRead()s.

Two or three hours spent thinking and reading documentation solves most programming problems.


May 05, 2014, 11:45 pm Last Edit: May 05, 2014, 11:48 pm by tmd3 Reason: 1
I see this as a solution to the problem of synchronizing ADC readings.  I admit, though, that my understanding of the OP's goal is kind of fuzzy.

  • Set the ADC to auto-trigger on external interrupt 0

  • Set a timer to run at the appropriate frequency

  • Set that timer to deliver a PWM output

  • Connect that PWM pin to external interrupt 0 on both Arduinos

The datasheet says that the ADC prescaler is reset when the ADC is auto-triggered by an event, to assure a fixed delay from the trigger event to the start of conversion.  That will ensure that the samples taken by the two Arduinos are in sync to within what I'd expect to be a couple of system clock cycles, without intervention from the program.  Without some kind of active synchronization of ADC readings, they'll drift apart quite quickly, due to the difference in the frequencies of the two ceramic oscillators.

If the intent is to make power measurements on a single-phase circuit, I think that taking readings of current and voltage alternately on a single Arduino would be accurate enough.  Fiddling with a unity power factor calculation, close to full scale, in Excel, I get an error of about 0.1% by reacting alternate readings as if they were taken simultaneously.  Interpolating one set, I get about the same results.  That seems to be plenty accurate for a metering application, but there's no guarantee that's what the OP is up to.

Go Up