Hello,
I am using hardware PWM on NRF52832 in order to drive a MOS. I found something unexpected with the rates. i understand the PWM rate is determined by the clock divider and the counterTop value, which can be considered as the resoution in bit. So i generated a table of all available rates from DIV1 to DIV128 and from 15 bit to 4 bit resolution :
15 14 13 12 11 10 9 8 7 6 5 4
DIV_128 61 122 244 488 976 1953 3906 7812 15625 31250 62500 125000
DIV_64 69 139 279 558 1116 2232 4464 8928 17857 35714 71428 142857
DIV_32 81 162 325 651 1302 2604 5208 10416 20833 41666 83333 166666
DIV_16 97 195 390 781 1562 3125 6250 12500 25000 50000 100000 200000
DIV_8 122 244 488 976 1953 3906 7812 15625 31250 62500 125000 250000
DIV_4 162 325 651 1302 2604 5208 10416 20833 41666 83333 166666 333333
DIV_2 244 488 976 1953 3906 7812 15625 31250 62500 125000 250000 500000
DIV_1 488 976 1953 3906 7812 15625 31250 62500 125000 250000 500000 1000000
But the table doesnt match with actual measured values, here are few rates i measured:
div128, 15bit = 3.78 Hz
div16, 15bit = 30.2 Hz
div1, 15bit = 483 Hz
While it it close in the whole range for DIV_1, it really doesnt match-up for DIV_16 and DIV_128, so i wonder what is the reason for this and how to calculate properly the PWM rates? here is what i used:
f = ((16000000 / divider ) / maxValueForResolution(bitResolution))
Thanks