I have my Uno connected to a TW523 compliant device and a handy O-scope. I seem to be getting a 60Hz square wave of 5V as expected but, it doesn't seem to satisfy the waitForZeroCross routine below. I've checked to ensure my ZeroCross pin is correct. I am using pin 9. I am curious how the routine detects a transition on pin 9 without a digitalRead command. I am still in the beginning phases of learning C++ based code.
void x10::waitForZeroCross(int pin, int howManyTimes) {
unsigned long cycleTime = 0;
// cache the port and bit of the pin in order to speed up the
// pulse width measuring loop and achieve finer resolution. calling
// digitalRead() instead yields much coarser resolution.
uint8_t bit = digitalPinToBitMask(pin);
uint8_t port = digitalPinToPort(pin);
for (int i = 0; i < howManyTimes; i++) {
// wait for pin to change:
if((*portInputRegister(port) & bit))
while((*portInputRegister(port) & bit)) {
cycleTime++;
// Yield to prevent WDT reset
delay(0);
}
else
while(!(*portInputRegister(port) & bit)) {
cycleTime++;
// Yield to prevent WDT reset
delay(0);
}
}
}