Backlight driver code is done and ready to implement

But just for testing purposes, it might work fine as is, or it might jitter a little and constantly turn the brightness up and down, i havent yet implemented anything for stabilizing the output.

right now this code doesnt adjust the output at all, ill edit it later though so it does. But it is both reading and writing PWM signals, all that needs to be done is some quick math to set the output brightness value (0-1024)  to the PWM percentage of that, and do this only once every few seconds, furthermore, to ignore slight shifts in the brightness, or some other method for stabilizing the output.

 

//



#include "wirish.h"

 int fade = 200;
 int increment = 20;
 volatile int cnt = 0;
 int cnt2 = 0;
int its = 0;




//interrupt stuff
volatile int pwm_value = 0;
volatile int prev_time = 0;
volatile int rise = 0;
volatile int period =0;


int incomingByte = 0;   // for incoming serial data


void rising() {
  attachInterrupt(PB9, falling, FALLING);
  prev_time = micros();
 period = micros() - rise; //measures the period, a single reccuring stage during the wave, which in this case is at the rise, the point the pin goes from low to high
 rise = micros(); // sets the rise time as now, next cycle it will be the same and can be used to measure the period.
}
 
void falling() {
  attachInterrupt(PB9, rising, RISING); 
  pwm_value = micros()-prev_time; // this is the time the pin remained high. this is the effective "on" duty cycle. dividing this by the period gives a percentage "on" time
cnt=cnt+1; //cnt is counter, its measuring how many CPU cycles have passed. this counter value is used to average out the PWM because they fluctuate too much 
its=its+pwm_value; //its is iteration, as of writing this, its will add pwm value to itself 1000 times, then it will be divided by 1000 to get the average over 1000 cpu cycles

  
  //Serial.println(pwm_value);
}

//------


 
void pwmSetClock(int pin, int duty_bits) {
  uint32 cfgr;
 
  timer_dev *timerDevice  = PIN_MAP[pin].timer_device;
  uint8 timerChannel      = PIN_MAP[pin].timer_channel;
  pinMode(pin,PWM);
  timer_pause(timerDevice);
 
  timer_set_reload(timerDevice, (1 << duty_bits)-1);
  timer_set_prescaler(timerDevice,timerChannel);
  timer_set_compare(timerDevice, timerChannel, (1 << duty_bits)-1);
  timer_resume(timerDevice);
}
void setup (){
pwmSetClock(PB8, 10); //was 10 for 17khz, // PB8 will be outputting PWM, you cannot use many other pins as PWM outputs, see the pinout for your given microcontroller to find out which pens you can use as PWM output pins
//range is 2^15 for 15. 32768
pwmWrite(PB8,750); //values between 0-1023 at 10/17khz, 32768 at 15, which is 550hz

//pwm has been set to 10, so, 17khz so this code is ready for immediate implementation right now.
//for debugging, connect pins 8 and 9 with a 1K resistor and set the clock divisor to 15 to set the frequency to 550hz, so that the stm32 can read itself.

//PB8 should be wired up to the mosfet LED PWM controllers.

//interrupt stuff

  Serial.begin(115200);
  // when pin D2 goes high, call the rising function
  attachInterrupt(PB9, rising, RISING); //PB9 is designated as the pwm input pin, change this to something else if you want to use a different pin
//delay(3000);
  //Serial.print("driver has started");
 
}

void loop() {

  

if(cnt>=1000){ //when counter reaches 1K
its=its/1000; //its = its / 1000, so, averages out the high time over the last 1000 cpu cycles
Serial.print("high time");
Serial.println(its);
its=its/(0.01*period); //arduino needs different variable types for decimal values so i shortened its / period *100, to its/(period/100), which gives the same value without its ever going decimal
Serial.print("percentage");
Serial.println(its);
Serial.print("period");
Serial.println(period);
Serial.println("-");


//Serial.println(prev_time);
its=0; ///its and cnt are now set to zero 
cnt=0;
  
}


//for debugging purposes, this code here lets you type a number into the serial monitor in arduino IDE and it will set duty cycle to that.
//at the time of writing this annotation i had pins 8 and 9 electrically connected so that i could test the drivers ability to read PWM without putting it in the cintiq

 // send data only when you receive data:
        if (Serial.available() > 0) {
                // read the incoming byte:
                incomingByte = Serial.parseInt();
                fade = incomingByte;
                pwmWrite(PB8, fade);

                // say what you got:
                Serial.print("I received: ");
                Serial.println(incomingByte, DEC);
              //  Serial.println(incomingByte);
              
                
        }








/* 
if(fade<=30 || fade>=950){
 increment= increment*(-1);
}
fade = increment + fade;
pwmWrite(PB8,fade);
delay(25);
*/

  //Serial.print("driver has started");
 // delay(1000);

}

Heres a pic of what its doing atm

8 thoughts on “Backlight driver code is done and ready to implement”

  1. Normally I don’t learn article on blogs, however I wish to say that this write-up very forced me to take a look at and do it! Your writing taste has been surprised me. Thank you, quite nice post.

  2. Hi, I’d love to know some additional information on this as well. I have a 24HD that I’ve been sitting on for about 3 years, after it died this exact same, pathetic death right after the warranty expired. This seems to be my only hope as I’d rather not give Wacom any more money, ever, specifically for their lack of support and sub-par products. Is this solution something that’s provably workable? I’ll dig right in if you have successfully fixed your model.
    Thank you for doing this and posting your research.

    1. ive mentioned this numerous times now but my 24HD is my primary monitor, so yes, it is a viable long term solution.
      It works fully, i finished an intermediary electrophysics course in my engineering degree just recently now, which incidentally taught me exactly what i was missing, to finish the backlight driver confidently (voltage division, turning a negative voltage signal into a positive biased one just using 2 specific value resistors so its safe for the arduino to read, arduino cant read negative voltage usually)

  3. Hi
    Love your project and site – it’s inspired me to tackle the repair of my cintiq 27QHD with a broken screen and was wondering if you had any idea where you can buy the parts for the repair? Any help would be greatly appreciated. Thanks!

    1. replacement parts cannot be bought, i looked into this, wacom will charge you for a repair but they refuse to sell the parts for self installation.
      Thats why i started the backlight driver project, the only option was to invent a whole new driver.

  4. I am trying to use your implementation to replace my Cintiq 27QHD backlight with led. I am following your guide to the letter. Anything else you think I should know?

    1. I have heard some of the boards inside may be different but, ultimately its not a critical issue what wires you use to access the 24v, most everything should be the same.

Leave a Reply

Your email address will not be published.