Go Down

Topic: TPIC6B595 no dimmer with PWM (Read 442 times) previous topic - next topic

amjlopez

Hello:

I am using Arduino Mega with TPIC6B595 the leds are working perfectly but I have connected the pin 9 (OE and this with ground) to pin 12 Arduino to get less brightness but the led bright full.
 I am using Monitor Serial to send a number.

can you tell me what I am doing wrong please?
many thanks.
Code: [Select]


long i=0;


//Pin to clear the register
const int clearPin = 7;
//Pin connected to latch pin (RCK) of TPIC6B595
const int latchPin = 8;
//Pin connected to clock pin (SRCK) of TPIC6B595
const int clockPin = 6;
////Pin connected to Data in (SER IN) of TPIC6B595
const int dataPin = 9;

const int notG = 12; //not G PWM DIMMER

void setup() {
 //set pins to output because they are addressed in the main loop
 pinMode(clearPin, OUTPUT);
 pinMode(latchPin, OUTPUT);
 pinMode(dataPin, OUTPUT); 
 pinMode(clockPin, OUTPUT);
  pinMode(notG, OUTPUT);
 
 Serial.begin(9600);
 Serial.setTimeout(10);
 Serial.println("*");

 // Always start by setting SRCLR high
 digitalWrite( clearPin, HIGH);

 // delay a little and then set
 delay(100);
}

void loop() {
 

while (Serial.available()==0){}
    i=Serial.parseInt();
     Serial.println(i);

 analogWrite(notG, 10);
 // write to the shift register with the correct bit set high:
 registerWrite(i, HIGH);
 delay( 1000 );
 

}

// This method sends bits to the shift register:

void registerWrite(int whichPin, int whichState) {
 Serial.println(whichPin);
   
 // the bits you want to send
 byte bitsToSend = 0;
 // write number as bits
 bitWrite(bitsToSend, whichPin, whichState);

 // turn off the output so the pins don't light up
 // while you're shifting bits:
 digitalWrite(latchPin, LOW);
 Serial.println(bitsToSend);
 Serial.println("_");
 
 // shift the bits out
 shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend);

 // turn on the output so the LEDs can light up:
 digitalWrite(latchPin, HIGH);
}




Grumpy_Mike

Well it is not the best way of doing a serial input, as soon as one byte arrives in the buffer you immediately try and convert the single byte into an integer. Leaving the next byte of the one input.

Read up on how to handle serial inputs.

Also try a analogue write of a much bigger number like 128, for a start.

amjlopez

I have used all numbers from 0 to 255 and the leds bright the same

Grumpy_Mike

Then you haven't wired it up right.

amjlopez

cathode to Drain0
cathode to Drain1...
all anodes to resistor then to 5V.

When I send the number by serial to light every led is OK but no dimmer it

Grumpy_Mike

Quote
When I send the number by serial to light every led is OK but no dimmer it
OK so the LEDs are wired up correctly.

Quote
I have used all numbers from 0 to 255 and the leds bright the same
That means the signal is not getting to the ~OE pin of the chip, because a HIGH value (PWM 255) would turn off the LEDs and it clearly dosn't.

amjlopez

This is my schema.

I have not draw the SRCLR because there no space, but it is.

Grumpy_Mike

#7
Aug 11, 2018, 11:17 am Last Edit: Aug 11, 2018, 11:19 am by Grumpy_Mike
That is not a schematic it is a physical layout diagram, what is known here as Fritzing crap.

However I can see you have the LEDs wired wrong. Each LED should have its own resistor not one resistor for all LEDs. You also don't seem to have any decoupling capacitors. Also it seems you have shorted pin 12 to ground, so how can it ever go high?

We also need to see how you have wired it, so a photograph will tell us if the schematic ( when you post it ) matches what you have done.

amjlopez

I only need one resistor because I am using one led at a time, no two or more light on at the same time.

About the capacitor I didn't know that I need it. Where to put and what value?

and about shorted pin 12 to Ground is beacuse If I connect only the OE pin no light comes on, but when I connect to ground it works.
thank you

Paul__B

I only need one resistor because I am using one led at a time, no two or more light on at the same time.
Actually, your Fritzing diagram and photo show that you have no resistor in series with the LEDs.  No wonder you are having problems!




Grumpy_Mike

Quote
I only need one resistor because I am using one led at a time, no two or more light on at the same time.
OK but information that should have been in the first post.
Also if you take just a tiny bit more care with placing the wires you can obscure where all of them go not just most of them. Think about it could you follow the wiring from that photograph?  The Fitzing crap shows you short out the resistor you think you have in the LEDs.

Quote
About the capacitor I didn't know that I need it. Where to put and what value?
0.1uF ceramic between the power pin and ground of the chip.

Quote
and about shorted pin 12 to Ground is beacuse If I connect only the OE pin no light comes on, but when I connect to ground it works.
So you ruin any chance of it working and perhaps damage the Arduino pin by putting a short circuit on it.

Try this:-
Remove the wire to pin 12
Output an LED so it is lit.
Remove the short, to the OE, the light should go out, if not connect it to 5V. So basically the LED is lit when the OE is connected to ground and not lit when it is open or connected to 5V.

Then remove the wire from the OE and connect up the wire to in 12, make sure you set the analogWrite to 128. If nothing happens then you have blown your Arduino pin. Try another PWM capable pin, remember to change your code accordingly.

amjlopez

Yes, you are reason. I made the image with Photoshop, no Fritzing (I don't know it), sorry.

Quote
The Fitzing crap shows you short out the resistor you think you have in the LEDs.
the resistor is not well placed? please, can you tell how to put it?


Quote
Output an LED so it is lit.
From where to where do I must put the led?

thanks

Paul__B

the resistor is not well placed? please, can you tell how to put it?
Well, you have to put it in series with the LEDs.

From where to where do I must put the led?
Once you have the resistor in series with the LEDs, write code to set the output of the TPIC6B595 to one of the LEDs you already have, active.

amjlopez

I have put all anodes together and one resistor for all them. As I said before, I only lit one led at a time.
Is this not the correct way to do it?
If not, please can you tell me how to connect them?
thanks

Grumpy_Mike

#14
Aug 11, 2018, 02:40 pm Last Edit: Aug 11, 2018, 02:41 pm by Grumpy_Mike
Quote
I have put all anodes together and one resistor for all them.
You have not got ANY resistor in series with the LEDs, you short out that resistor with the power track on your solderless breadboard.

Go Up