Hi,
I'm trying to make a numitron (IV-9) clock using a barebone Atmega328P and four 74HC595N shift registers. Everything worked great until I tried to adjust the brightness by applying a PWM signal on the output enable pin of the shift registers.
Below a minimal version of the code that results in the error.
#define latch_pin 2
#define blank_pin 5
#define data_pin 3
#define clock_pin 4
byte num_table[11] = {0b00001000, 0b00111110, 0b01010000, 0b00010010, 0b00100110, 0b10000010, 0b10000000, 0b00011110, 0b00000000, 0b00000010};
void setup() {
pinMode(latch_pin, OUTPUT);
pinMode(data_pin, OUTPUT);
pinMode(clock_pin, OUTPUT);
analogWrite(blank_pin, 100);
digitalWrite(latch_pin, LOW);
}
void loop() {
for(int k=0; k<10; k++){
output(k*11, k*11);
delay(500);
}
}
void output(byte hr, byte m){
digitalWrite(latch_pin, LOW);
shiftOut(data_pin, clock_pin, LSBFIRST, num_table[m%10]);
shiftOut(data_pin, clock_pin, LSBFIRST, num_table[m/10]);
shiftOut(data_pin, clock_pin, LSBFIRST, num_table[hr%10]);
shiftOut(data_pin, clock_pin, LSBFIRST, num_table[hr/10]);
digitalWrite(latch_pin, HIGH);
}
This code loops through the digits 0-9 on all four numitrons. This works fine when I use digitalWrite(blank_pin, LOW);
instead of the analogWrite. Using the PWM signal results in the numitrons being stuck at a certain digit while occasionally jumping to a different random digit or just complete gibberish.
Below you can find my schematic (yes, I know it's made in Fritzing but I hope it's still readable).
To me it seems as if there is interference between the output enable pin and the latch pin. I would greatly appreciate your opinion on this and, if there is indeed interference, how I would go about resolving this issue.
Some notes and things I've already tried:
- Yes, I'm using a capacitor between the latch pin and ground as is stated in the arduino shift register tutorial and I know this tutorial isn't correct but when I remove this capacitor nothing works at all.
- I've tried setting the output enable pin to high while shifting out the data but this has no noticeable effect.
- Apart from what is shown in my schematic, I've also got a RTC ds1307 module and some capacitive touch sensors connected to the Atmega. I think these aren't the source of the problem as it still occurs when I disable them.
- I have some experience with shift registers and barebone Atmega chips from previous projects but I have never experienced anything like this problem before.