Showing posts with label HT1632C. Show all posts
Showing posts with label HT1632C. Show all posts

Sunday, July 24, 2016

Countdown timer for a PhotoBox

One day a colleague from our Laser department (YES we have Lasers!) stood next to my desk and started to ask some suspicious questions about 7-Segment displays and how to control them with an Arduino.

In general its not a problem, I like to share my knowledge about electronics and programming etc., but I hate it to answer questions without knowing the circumstances. So I asked him what the target of the project would be and he said he wanted to program a countdown timer and that he also has not really the time to do it. He also told ne that the project is not for him, its for Murat (Also a guy from the Laser department).

Later that day I went to Murat and asked him about the details of the project and what the main goal would be. He told me that he want to build a PhotoBox for his sisters wedding. I told him that if it is for his sisters wedding it should not only be some 7-Segment displays. He would need something which looks much fancier with more animation and special effects than a 7-Segment display is able to provide, and I showed him my work that I have done with the 3208 lattice clock and that something similar could be done for a countdown display.

He said he would like to have something that does the following:

  • Push a button
  • Countdown starts
  • End of the countdown a Relay is triggered
On that evening I went home and started to dig out my spare 3208 Lattice Clock module and a relay board. I soldered some connectors for power supply, relay output and programming to the board, and started to play with it. After some hours I came up with the following animation:


In the video itself it is not very clear, but the sequence is as follows:
  • Press RESET or reconnect the power to start
  • Dim up the first number in the middle of the screen
  • Shift the number out to the left while the new number comes from the right
  • When the 0 is reached then dim it out
  • Actuate the relay output for one second
  • Wait in idle until RESET or re-power
The complete code including the control for the HT1632C is in one single Arduino sketch with less than 300 lines of code. I apologize for the German comments in the code But it was quick and dirty written. The code can be found in my GitHub repository

So far my work was done for this project. Murat also sent me some pictures of the finished project where he put it all together into a nice box with a tablet as picture preview.
Sadly Instagram changed their logo recently.










Monday, December 23, 2013

3208Clock Part 4: Get started with the HT1632C display driver

There are several ways to get started with the HT1632C display driver. One attempt, and this was also my first step, is to check on Google if someone has already written a driver or a library for the HT1632C. And yes, there are a lot of them.

At first I was playing around with the Arduino library from Adafruit. After some modifications I was able to write something to the display.

A Picture from one my first tests with the Adafruit lib

I also figured out that an update of the complete display (from the frame buffer into the HT1632C display driver) took 8.3ms and was only done with a clock speed of approx 35kHz. Please keep in mind that the ATmega8 of the 3208Clock is running at only 8MHz.

Yellow: Chip Select (CS)
Blue: Clock (WR)

A closer look also showed that the duration of the clock cycles is not equal during the transmission. The frequency of the clock is increasing which means that the time for one period of the clock cycle decreases during the transmission of a 16bit value from 33.6µs to 24.8µs.

Yellow: Chip Select (CS)
Blue: Clock (WR)
Yellow: Chip Select (CS)
Blue: Clock (WR)

At this point I wanted to know 2 things.
  1. Why is the duration of the clock cycles not constant during the transmission?
  2. Why is there only a clock frequency of approx 35 kHz (Datasheet says on page 4 1MHz is ok) which causes a update time for the entire display of 8.3ms?

Investigations and benchmarks

At first I figured out that HT1632::writeScreen() and HT1632::writedata(uint16_t d, uint8_t bits) are the functions of the Adafruit library which take care for the transmission. To have something which makes it easier to investigate I have prepared some small Arduino sketches where I only implemented the corresponding functions.

writedata(uint16_t d, uint8_t bits)

In this function the bit banging except the selection of the chip (CS) is done.

void writedata(uint16_t d, uint8_t bits)
{
  pinMode(_data, OUTPUT);
  for (uint8_t i=bits; i > 0; i--) {
    digitalWrite(_wr, LOW);
    if (d & _BV(i-1)) { digitalWrite(_data, HIGH); }
    else { digitalWrite(_data, LOW); }
    digitalWrite(_wr, HIGH);
  }
  pinMode(_data, INPUT);
}

 Answer for Question No 1

In the line "if (d & _BV(i-1))" happens the magic which causes that the clock cycles are varying during the transmission.

_BV(i-1) is the same like (1<<(i-1)), i is the iterator of the for-loop which is initialized with the number of bits. In the worst case the the iterator i is initialized with 16 which causes that in the check for the if-statement a "left shift operation" is executed 15 times. Because that i gets smaller every bit it has to do less and less shift operations to check the if-statement. And this causes that the clock cycle is not equal over the transmission of multiple bits.

I have fixed the problem with the clock speed by the following code modification:


void writedata(uint16_t d, uint8_t bits)
{
  uint16_t compareBit = 0;
  // 0x8000 -> set MSB
  compareBit = bits == 16 ? 0x8000 : compareBit |= (1<<(bits-1)); 
  
  pinMode(_data, OUTPUT);
  for (uint8_t i=bits; i > 0; i--)
  {
    digitalWrite(_wr, LOW);
    if (d & compareBit) { digitalWrite(_data, HIGH); } // 1
    else { digitalWrite(_data, LOW); } // 0
    compareBit = compareBit >> 1;
    digitalWrite(_wr, HIGH);
  }
  pinMode(_data, INPUT);
}

At the beginning of the function I have made a new variable for the comparison if the DATA pin has to be set. These are some lines more code but in this case the bit shift is only executed once in the for-loop. I also set the compareBit variable in a clever way because the most data packages are 16bit in this case the variable is preset with 0x8000 which is nothing else than setting the MSB true. Otherwise we have a repetitive shift operation for the amount of bits that have to be sent.


After this modification the frequency of the clock has been increased to approx 41.5kHz and the duration for a complete screen refresh is now 6.9ms this is 83% of the time it took before the modification.


Yellow: Chip Select (CS)
Blue: Clock (WR)
 

Yellow: Chip Select (CS)
Blue: Clock (WR)


Answer for Question No 2

After the initial improvement of the clock speed to 41.5kHz it still felt to slow for me. So I have removed all the Arduino specific stuff from the corresponding functions and replaced it by native "avr gcc" code.


void writedata(uint16_t d, uint8_t bits)
{
  uint16_t compareBit = 0;
  // 0x8000 -> set MSB
  compareBit = bits == 16 ? 0x8000 : compareBit |= (1<<(bits-1));
  
  DDRB |= (1<<DATA);
  for (uint8_t i=bits; i > 0; i--)
  {
    PORTB &= ~(1<<WR);
    if (d & compareBit) { PORTB |= (1<<DATA); } // 1
    else { PORTB &= ~(1<<DATA); } // 0
    compareBit = compareBit >> 1;
    PORTB |= (1<<WR);
  }
  DDRB &= ~(1<<DATA);
}


I was not aware that the speed improvement would be factor 10!


Yellow: Chip Select (CS)
Blue: Clock (WR)

Yellow: Chip Select (CS)
Blue: Clock (WR)

All three sketches can be downloaded from my GitHub repository.
Slow is the original code, medium is the code with the bugfix for the varying clock cycle and fast is the code for with all improvements.

Tuesday, August 13, 2013

The modified 3208Clock Part 1 the beginning

I stumbled upon this lattice clock while I was surfing through the products of one of this Chinese Internet sellers with worldwide free shipping. I thought "OK, 12$ (~9,0 EUR) what can I loose?" So I've ordered one of this devices.

I have stolen this Picture from www.FastTech.com

After only four weeks the package has arrived. My first thought was to quickly unwrap it and connect it to power to see what it is doing...

...BÄÄM! INSTANT KILL!
It took me $12.30 and a lot of patience (waiting for delivery) to learn that this device can not be powered directly by 12V DC. After the magic smoke has disappeared and I have turned the PCB I have seen that this device is labeled with DC 5V

From this setback, I did not let me discourage and I ordered a new unit. During the delivery time for the new device I had some time to do some reverse engineering. So I unmounted all the parts which hide the direct view to the PCB.

The contents of the 3208Clock

This device consists of an ATmega8L which is the brain of the Clock and a Holtec HT1632C Display controller paired with four 8x8 LED segments.

Optional components

During my investigation I have discovered that the PCB was in general developed in a very clever way. The following parts can be retrofitted to the board.
  • Mini USB port
  • TSOP infrared receiver
  • DS18x20 1-Wire temperature sensor / LM35 temperature sensor
  • Bi-color LED (color changing by reversing polarity)
  • 6-Pin ICSP header to reprogram the ATmega8L
  • Buzzer/Speaker (can not be mounted if ICSP header is mounted)
  • On the backside is a place to mount a RTC IC and a coin cell battery to power the clock IC if the main power is not connected.
But due to the Problem that the ATmega8L has only 8KB of program space I'm not sure if all of the above components can be implemented into the software.

PCB Overview

The most interesting part seems to be the right part of the front side. Here are a lot of footprints of the unpopulated optional parts which can be used to interact with the real world.



I have prepared a picture which shows which pins of the ATmega8L are connected to the footprints. The numbers are the Arduino pin numbers. I was to lazy to also write the original port pin numbers like "PB3" to the Picture. But here you can see a very good pinout diagram made by Pighixxx. I know its for a ATmega168 but the Pinout is more or less compatible.


Here is a picture of the backside of the PCB. We see here that three ICs can be mounted to the board. From left to right we have at first the footprint for the ATmega8L with its TQFP32 package. The next ones are the footprint for a battery and a SO16 IC where a RTC can be mounted.
The last one is the Footprint 52 pin QFP footprint for the Holtec HT1632C driver IC for the 8x8 LED displays.


I also have made a picture with some additional descriptions for some pins. During my reverse engineering I also painted some pads red to make it easier for me to track the +5V line. Also take a look at the top left of the picture there is a very important information written which I have ignored at my first try.



My actual setup

The only parts from the optional components which I have installed are the ICSP header for programming the device and a bi-color LED which was laying around for debugging purposes.


With the Setup in the picture above I'm now able to send a zero terminated string to the device over Bluetooth which will then scroll through the display. Here is a short video which I have made.


The next steps

In the next posts I will show a more insight view about the single steps which I have made to get this device up and running with the Arduino IDE and a couple of libraries. I also want to upload a well commented version the code to GitHub so that everyone can get started with playing around with this cheap and versatile device.

I'm not sure which topic the next posts will have but they will be more or less related to the 3208Clock device. It is also possible to post requests for additional informations of specific parts of this device or the procedure of hacking it to the comments.