Not that this would fix your issue, but you have:
In this case I would have used:Code:DIMMER: 'auto dim routine IF Z2=06 THEN HPWM 2,150,2000 IF Z2=08 THEN HPWM 2,200,2000 IF Z2=10 THEN HPWM 2,255,2000
What happens if Z2 = 07? Maybe use:Code:Dimmer: IF Z2 = 06 THEN HPWM 2,150,2000 ELSEIF Z2 = 08 THEN...
Code:IF Z2 <= 06 THEN HPWM 2,150,2000 ELSEIF Z2 <= 08 THEN...
Well, there is no GOTO there is GOSUB, this was just a literal description of how it works.
16F887 has two PWM modules, which can be output at 4 different channels, read the datasheet. You can adjust duty cycle individually, just frequency will be the same.
From datasheet: - 10-bit PWM with 1, 2 or 4 output channels, programmable “dead time”, max. frequency 20 kHz.
IF Z2=07 then nothing should happen and nothing happens
For the cleanliness of experiment, I've built a completely new PCB today, and will check code for it at weekend.
apologies so it does16F887 has two PWM modules
Warning I'm not a teacher
Well, the different build has no such issue, but while using same code, it also uses different pinout (ADC input is PORTE.2 instead of PORTA.0), so in next days I will try to check existing build for issues.
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?
Obviously this is an EMI problem. Somewhere your circuits acts like a transmitter (PWM sharp signals are what it needs to do so).
Maybe a wrong trace, maybe a cable that is in different place, who knows?
Can you post pictures of both PCB sides and cabling? Sure big caps will help. Better find the source of the problem.
Ioannis
Bookmarks