8-bit PWM Scaling Values

I’m having trouble getting PWM 0 (8-bit) to produce output with certain scaling values. I am using the Arduino environment, but I suspect this is not an Arduino-specific issue.

Here’s an example:

uint8_t scale = 0x8; // this will work if set to 7
uint8_t frequency = 880;
uint8_t period = (uint8_t) ((F_CPU >> scale) / frequency);  // F_CPU is 16000000 (clk set to 16MHz)
GPIO_REG(GPIO_IOF_SEL) |= 2;  //hifive1 pin 9, or pwm0_cmp1
PWM_REG(PWM_CMP0) = period;
PWM_REG(PWM_CMP1) = period >> 1; // 50% duty

It looks like scaling values at and above 8 work. I get a 50% duty square wave at approximately the desired frequency. However, values 7 and below result in a bad output, even if I adjust the frequency to ensure the comparator can hold the threshold value.

I do not have this issue with PWMs 1 and 2 (16-bit PWMs), and I don’t see anything in the E300 or HiFive1 docs or repositories that would explain this behavior.

Any thoughts?

I have the exact opposite problem. On my HiFive1 Rev B, I use 200MHz system clock and I am not able to get any output from PWM0 using scaling values 8 and above. Scaling values [0-7] seem to be working fine and I couldn’t find anything in the docs that explains this behavior. As you said, PWM1 and PWM2 are working as expected. Have you been able to find any solutions?