Hi Martin,
I got the PWM routine working fine on Zero with your help (Changing Arduino Zero PWM Frequency - #193 by MartinL - Arduino Zero - Arduino Forum ). But I now need to synchronize my ADC measurements with PWM signal. As a reminder, I have the PWM directed to the PA08:
PORT->Group[PORTA].PINCFG[8].bit.PMUXEN = 1;
PORT->Group[PORTA].PMUX[8 >> 1].reg |= PORT_PMUX_PMUXE_F;
For synchronization I'm trying to do direct read of the bit 08 of the PA register, something like:
PwmOut = REG_PORT_OUT0 & (1 << 8 );
But I'm getting only constant values, 0 or 1 depending on how I set the port values in the setup(). The PWM routine does not seem to affect the state of the REG_PORT_OUT0 register, although I can clearly see the PWM squarewave signal on the PA08 pin, so I guess the MUX connects the PA8 to the timer output instead of the port register?
So how do I read the state of the PA08 pin when it's driven by timer in the PWM mode?
I wanted to try the simplest method first (which is just polling the PA08 register bit in a while loop) but I know that there are other ways to do that which are a bit more complicated and have other consequences:
- I can connect PA08 electrically to some other pin and do digital read, but for that I will need to modify the board.
- I can trigger ADC read by an interrupt from the counter overflow, this will slightly increase the execution time (every us counts in my application)
Your help is much appreciated!