It is very interesting, as I unpacked the original board and put it on the table, it no longer had that issue.
And after I packed the new board into small enclosure, it started to have exactly the same issue!
I added some checks to code and here is what I've found.
I'm using ADC to get the input from the keys.
ADC IN is tied to VDD via +10K resistor, and there are two buttons, one pulls that IN to GND, another also pulls to GND, but via another 10K resistor.
So when no button is pressed, ADC input reads 255. When 1st button is pressed - it is 0, and when 2nd button is pressed, it is about 127. (My code checks it to be above 100 and below 140)
So, what happens? When I have PWM with duty cycle less than 170 (assuming HPWM 1,170,2000), the ADC input sporadically starts to read as 127, instead of 255! The lower PWM duty cycle is, often that happens.
But this only happens when there are some wires connected to ADC input (even short ones, about 10cm). So I guess, this is an hardware issue, and adding 0.1uf capacitor to ADC IN should help?
Bookmarks