RA8876

pd0lew

Well-known member
Dear all,

I am strugeling with the backlight PWM of my RA8876 display, using pin 14 to 3.3 V than it works that the simple way.

I removed R27 and short R28 as given in documentation the thing is I like to controll the backlight intensity via code.

I tried this already

Code:
  tft.begin(46000000);
  tft.backlight(true);
  tft.pwm0_Duty(0xFFFF);

But the display stays dead I mean dark.
Is there a solution for this or is it not possible?

Best,
Johan
 
Not sure which driver or Teensy you are using and whether you are using an SPI or 8080 parallel interface. My drivers never did actually use the internal PWM. Here is part of the setup that we tested:
Code:
  //I'm guessing most copies of this display are using external PWM
  //backlight control instead of the internal RA8876 PWM.
  //Connect a Teensy pin to pin 14 on the display.
  //Can use analogWrite() but I suggest you increase the PWM frequency first so it doesn't sing.
  #define BACKLITE 5 <----- PWM pin 5
  pinMode(BACKLITE, OUTPUT); <----- Setup as a discrete output 
  digitalWrite(BACKLITE, HIGH);   <----- Turns back light on

I never did play with PWM. Others that were involved with the project may have played with it. It's been a long time and I am really not sure:unsure:

The drivers can be found here:
https://github.com/wwatson4506/TeensyRA8876-GFX-Common - This is the mandatory common library.
In addition to this you will need one of the following companion libraries based on whether you are using an SPI or 8080 parallel interface.
https://github.com/wwatson4506/TeensyRA8876-8080 - The 8080 parallel interface.
https://github.com/wwatson4506/TeensyRA8876-SPI - the SPI interface.

I will be curious to see what you come up with...
 
On page 14 of my copy of the the ER-TFTM070-6_Datasheet it says this:

1778477494115.png

After much trial and error and reading of the RA8876 documentation, I was able to get PWM'able backlight working by adding the following code:
Code:
static constexpr uint16_t BACKLIGHT_LOGICAL_RANGE = 1000;
inline void backlightOn() const {
#if defined(RA8876_BACKLIGHT_PWM)
    if (tft)    tft->pwm0_ClocksPerPeriod(BACKLIGHT_LOGICAL_RANGE);
    if (tft)    tft->backlight(true);
#else
    digitalWriteFast(RA8876_BACKLIGHT_PIN, HIGH);
#endif
}
inline void backlightOff() const {
#if defined(RA8876_BACKLIGHT_PWM)
    if (tft)    tft->backlight(false);
#else
    digitalWriteFast(RA8876_BACKLIGHT_PIN, LOW);
#endif
}
/**
 * Sets the backlight intensity to bk of range. bk must be between 0.0 and 1.0 inclusive
 */
inline void backlightPercent(float bk) const {
    // ensure the requested backlight percent is a valid value
    bk = etl::clamp(bk, 0.01f, 1.0f);    // Don't ever set it to 0 else the display can appear "bricked"
#if defined(RA8876_BACKLIGHT_PWM)
    if (tft)    tft->pwm0_Duty(BACKLIGHT_LOGICAL_RANGE*bk);
#else
#endif
}
Hope this helps
 
Hi all,

My library, I use is the Ra8876LiteTeensy-master and a Teensy 4.0 , tested the code above but no luck and errors.

Do we have still any ideas to test?

Best and thanks,
Johan




Building in release mode
Compiling .pio\build\T40\src\main.cpp.o
src\main.cpp:1123:27: error: non-member function 'void backlightOn()' cannot have cv-qualifier
1123 | inline void backlightOn() const {
| ^~~~~
src\main.cpp:1131:28: error: non-member function 'void backlightOff()' cannot have cv-qualifier
1131 | inline void backlightOff() const {
| ^~~~~
src\main.cpp:1141:40: error: non-member function 'void backlightPercent(float)' cannot have cv-qualifier
1141 | inline void backlightPercent(float bk) const {
| ^~~~~
src\main.cpp: In function 'void backlightPercent(float)':
src\main.cpp:1143:10: error: 'etl' has not been declared
1143 | bk = etl::clamp(bk, 0.01f, 1.0f); // Don't ever set it to 0 else the display can appear "bricked"
| ^~~
*** [.pio\build\T40\src\main.cpp.o] Error 1
 
@pd0lew - Have never used platform IO so I cannot be of much help there. But:
Code:
etl::clamp(bk, 0.01f, 1.0f)
____________________________________________________________________________________________________
clamp
Clamps a value between two limits.

template <typename T, typename TCompare>
ETL_CONSTEXPR const T& clamp(const T& value, const T& low, const T& high, TCompare compare)
_____________________________________________________________________________________________
template <typename T>
ETL_CONSTEXPR const T& clamp(const T& value, const T& low, const T& high )
________________________________________________________________________________________________
Is part of a template library found here. @thebigg probably knows more about that...
 
That make not much differences T. we have still a Setup and a Loop not that much different.

But if you must do it in Arduino how you do it then ?

Best,
Johan
 
Sorry. I realise that I was not explicit in stating that the code I posted was not meant to be cut and pasted into an arduino window. I was just trying to show the sequence of calls.

Try this

Code:
tft.begin(46000000);
tft.pwm0_ClocksPerPeriod(1000);
tft.backlight(true);
tft.pwm0_Duty(1000);        // backlight is 100%
delay(10);
tft.pwm0_Duty(500);            // backlight is 50%
delay(10);
tft.pwm0_Duty(10);            // backlight is 1%

I chose a rather low number (1000) for the PWM period as I found that using 0xffff resulted in a visible flicker. Even 0x8fff has a flicker on a video recording of the screen.
 
@pd0lew - Have never used platform IO so I cannot be of much help there. But:
Code:
etl::clamp(bk, 0.01f, 1.0f)
____________________________________________________________________________________________________
clamp
Clamps a value between two limits.

template <typename T, typename TCompare>
ETL_CONSTEXPR const T& clamp(const T& value, const T& low, const T& high, TCompare compare)
_____________________________________________________________________________________________
template <typename T>
ETL_CONSTEXPR const T& clamp(const T& value, const T& low, const T& high )
________________________________________________________________________________________________
Is part of a template library found here. @thebigg probably knows more about that...
etl::clamp is just another (better) implementation of the arduino function constrain().

Sorry for the confusion
 
Back
Top