We want the duty cycle of the pwm out to be proportional to the delay in timing of both square signals, if its leading it will output on one ocr pin if it is lagging, it goes to the other, based on which value comes first. Also we have to wait for the program to change both values of the signals, PORTA and PORTB, to compare the delay, which i think its not doing correctly. for testing purposes we're inputting 1 hz square waves so we can see the output, but for the real deal it should be 40khz square waves, but its not working, and I am also not great with arduino (my first time) I am not sure why our code isn't working properly. Is there another way to do this or what should we try and change? Thanks!
You should be aware that not all the pins on a Port are available to you. Some of the pins have special functions and you should take care not to change them.
If you use the digitalWriteFast library it is almost as fast as port manipulation and it makes code a lot easier to understand.
PORTA and PORTB are complete 8-bit registers, handling multiple ports.
I suppose you are interested in reading only two specific pins, so you have to look into reading those specific bits.
I changed those to regular variables as well, but the timers still don't sync, so the comparison is always off for the time delay we need as the pwm duty cycle