Page 1 of 1

PWM hardware for dimming LCD

Posted: Sat Jul 14, 2018 2:26 am
by snazzify
I'm using the pigpio pwm hardware on gpio18 of a Raspberry Pi 3 to adjust the brightness of an LCD with a FAN5333 chip. I tested some software pwm code but dimming is unstable so im trying pwm hardware.

Bash command:

Code: Select all

pigs hp 19 1000 500000
C program:

Code: Select all

#include <stdio.h>
#include <stdint.h>

#include <pigpio.h>

int main(int argc, char *argv[])
{
   if (gpioInitialise() < 0) return 1;

   printf("start piscope\n");
   printf("press return to continue\n");
   getchar();

   gpioHardwarePWM(18, 1000, 500000);

   printf("STOP piscope\n");
   printf("press return to continue\n");
   getchar();

   gpioHardwarePWM(18, 0, 0);

   gpioTerminate();

   return 0;
}
Both the bash command and c program seems to work well and very stable. But my Raspberry Pi 3 B starts to crash and the lcd flickering when playing a game with RetroPie.

Re: PWM hardware for dimming LCD

Posted: Sat Jul 14, 2018 11:11 pm
by drgeoff
Inadequate PSU whose voltage falls too much when RPi begins working harder and drawing more current?

Re: PWM hardware for dimming LCD

Posted: Mon Jul 16, 2018 4:57 am
by Pekka
The HW PWM and 3.5 mm audio jack share the same hardware and cannot both operate at the same time. So if the game generates audio on the jack, this is the cause of screen flickering.

Re: PWM hardware for dimming LCD

Posted: Mon Jul 16, 2018 6:58 am
by joan
Pekka wrote:
Mon Jul 16, 2018 4:57 am
The HW PWM and 3.5 mm audio jack share the same hardware and cannot both operate at the same time. So if the game generates audio on the jack, this is the cause of screen flickering.
That sounds the likely problem.

I suggest using http://abyz.me.uk/rpi/pigpio/cif.html#gpioPWM rather than gpioHardwarePWM. It is not as flexible but is more than good enough for dimming LEDs etc., and will not conflict with PWM audio.