LCD Top Row Displaying Black Boxes

Hey Guys,

I was running this code with no issues to generate a PWM signal that would output the duty cycle to my LCD:

#include <LiquidCrystal.h>; // includes the LCD library code

LiquidCrystal lcd(13, 12, 8, 7, 4, 2); // initializes the library with the corresponding interface pins (2, 4, 7, 8 @ 4-bit)

const int ledPin1 = 5; // LED connected to digital pin 5 @ fast-pwm 980 Hz
const int ledPin2 = 6; // LED connected to digital pin 6 @ fast-pwm 980 Hz
const int ledPin3 = 11; // LED connected to digital pin 11 @ phase-pwm 980 Hz

const int analogPin1 = 1; // POT connected to analog pin 1
const int analogPin2 = 2; // POT connected to analog pin 2
const int analogPin3 = 3; // POT connected to analog pin 3

int val1 = 0; // variable to store analog pin 1 data
int val2 = 0; // variable to store analog pin 2 data
int val3 = 0; // variable to store analog pin 3 data

void setup() {
  lcd.begin(16, 2); // sets up the LCD columns and rows

  pinMode(ledPin1, OUTPUT); // sets pin 5 as output (Timer0, 8-bit)
  pinMode(ledPin2, OUTPUT); // sets pin 6 as output (Timer0, 8-bit)
  pinMode(ledPin3, OUTPUT); // sets pin 9 as output (Timer2, 8-bit)

  TCCR2A = _BV(WGM21) | _BV(WGM20); // changes from phase-pwm (default) to fast-pwm
  TCCR2B = _BV(CS22); // changes prescalar from 128 (default) to 64

  lcd.setCursor(1, 0); // sets the cursor to column 1, line 0
  lcd.print("CH1:"); // prints a message to the LCD
  lcd.setCursor(4, 1); // sets the cursor to column 4, line 1
  lcd.print("%"); // prints the % symbol for ledPin1

  lcd.setCursor(6, 0); // sets the cursor to column 6, line 0
  lcd.print("CH2:"); // prints a message to the LCD
  lcd.setCursor(9, 1); // sets the cursor to column 9, line 1
  lcd.print("%"); // prints the % symbol for ledPin2

  lcd.setCursor(11, 0); // sets the cursor to column 11, line 0
  lcd.print("CH3:"); // prints a message to the LCD
  lcd.setCursor(14, 1); // sets the cursor to column 14, line 1
  lcd.print("%"); // prints the % symbol for ledPin3
}

void loop() {
  val1 = analogRead(analogPin1); // reads the analog pin 1
  analogWrite(ledPin1, val1 / 4); // analogRead values go from 0 to 1023, analogWrite values from 0 to 255
  val2 = analogRead(analogPin2); // reads the analog pin 2
  analogWrite(ledPin2, val2 / 4); // analogRead values go from 0 to 1023, analogWrite values from 0 to 255
  val3 = analogRead(analogPin3); // reads the analog pin 3
  analogWrite(ledPin3, val3 / 4); // analogRead values go from 0 to 1023, analogWrite values from 0 to 255

  lcd.setCursor(1, 1); // sets the cursor to column 1, line 1
   int dutyCycle1 = ((val1 / 4) * 100 / 255); // defines dutyCycle1 variable
   if (dutyCycle1 < 100) {
    lcd.print(' '); // clears extra zeros
   }
   if (dutyCycle1 < 10) {
    lcd.print(' '); // clears extra zeros
   }
  lcd.print(dutyCycle1); // prints the dutyCycle1 value

  lcd.setCursor(6, 1); // sets the cursor to column 6, line 1
   int dutyCycle2 = ((val2 / 4) * 100 / 255); // defines dutyCycle2 variable
   if (dutyCycle2 < 100) {
    lcd.print(' '); // clears extra zeros
   }
   if (dutyCycle2 < 10) {
    lcd.print(' '); // clears extra zeros
   }
  lcd.print(dutyCycle2); // prints the dutyCycle2 value

  lcd.setCursor(11, 1); // sets the cursor to column 11, line 1
   int dutyCycle3 = ((val3 / 4) * 100 / 255); // defines dutyCycle3 variable
   if (dutyCycle3 < 100) {
    lcd.print(' '); // clears extra zeros
   }
   if (dutyCycle3 < 10) {
    lcd.print(' '); // clears extra zeros
   }
  lcd.print(dutyCycle3); // prints the dutyCycle3 value
}

Once I connected the PWM output to a p-Channel MOSFET, & accidentally fried the MOSFET, my LCD screen shows a top row full of black boxes & won’t work like it originally had.

Is it possible that I damaged anything on the Arduino board? I’m running the Uno Rev.3.

Thanks.

Mightbe yes - depends on what exactly happened to the MOSFET when it was fried. Do you have another Uno to test the same configuration - then you will definitely know what device is ok and what not.

Unfortunately, I do not have another Uno to test with. But if it is a realistic possibility that I damaged the one I have, I'd be open to ordering another to test with.

I also tried removing the LCD & running a basic PWM output script -- didn't work. So I'm guessing the Uno itself is damaged then.

Could I prevent this in the future by putting a diode on the output?

Not a diode, but a resistor. Even something like 500ohms. It will still drive the gate properly, but greatly limit fault current.