On Wed, 6 Aug 1997 20:54:26 -0400 Brian Kraut writes: >Help! I need help with the firmware to make an LED dimmer with a >12C509 PIC >running off the internal oscillator. I have been able to read a pot >and dim >the LED with PWM, but my source code does not run fast enough to keep >the >LEDs from flickering(They are multiplexed 7 segment displays run off >another >PIC). It is almost essential to synchronize the dimming PWM with the multiplexing rate. Otherwise the two will beat together and cause flicker, even if the dimming PWM is seemingly fast (it needs to be very much faster than the display multiplex if not synchronized). If synchronization is done, the PWM period could be as slow as the time each digit is selected (or an integer submultiple thereof) Ideally, the dimming function would be included in the other PIC. A way around this might be to filter the dimmer PWM so the voltage applied to the display is DC. This could get unpredictable at low brightnesses, since a low DC value may not be enough to turn the LEDs on at all. If the input is a pot controleld by the user, they would notice that and just turn it up until something is visible. There is really no need for a PIC/PWM at all in this case, just connect the pot to a transistor current amplifier and let it control the display voltage directly. I would like to do the PWM at about 1KHz. That doesn't leave a >lot of >time to read the pot, etc. The code also needs to check an input pin >and >output a pulse on another pin if a switch is closed for more than 2 >seconds. > The resolution doesn't have to be real high and the duty cycle >doesn't have >to be a full 0 to 100%, but the closer I can get the better. I >appreciate >any help anyone can give me. I am not good with real time >programming. The way I usually approach problems such as this is first to rethink the whole situation. It seems in your case that both of these functions could be done with rather simple analog circuits, or modifications to the program in the other PIC. If still using a PIC, I usually write the program as a loop that always takes the same number of cycles, thus it executes at a constant rate. Allowing 32 instructions in the loop and 16 levels of PWM will give a 1.95 KHz PWM frequency with a 4 MHz clock. Again, it won't work very well without synchronizing it somehow the the digit drive outputs of the other PIC.