# First real circuit, timecode reader

**URL:** <https://forum.arduino.cc/t/first-real-circuit-timecode-reader/285148>\
**Category:** General Electronics\
**Created:** [January 26, 2015, 7:31pm UTC](https://forum.arduino.cc/t/first-real-circuit-timecode-reader/285148 "2015-01-26T19:31:41Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jaredcrogers](https://avatars.discourse-cdn.com/v4/letter/j/ac8455/32.png) [@jaredcrogers](https://forum.arduino.cc/u/jaredcrogers)\
**Post date:** [January 26, 2015, 7:31pm UTC](https://forum.arduino.cc/t/first-real-circuit-timecode-reader/285148/1 "2015-01-26T19:31:41Z")

</div>

Hello,  
I wanted to post a picture of my first circuit, thanks to @dfraser 's project [here](http://forum.arduino.cc/index.php/topic,8237.0.html).

This is the diagram I referenced, my circuit, and the sketch below.

![](https://europe1.discourse-cdn.com/arduino/original/4X/2/f/8/2f845dea64382b46d35905b2b8e891befa08dfb5.jpeg)

```plaintext
#define icpPin 8 // ICP input pin on arduino
#define one_time_max 475 // these values are setup for NTSC video
#define one_time_min 300 // PAL would be around 1000 for 0 and 500 for 1
#define zero_time_max 875 // 80bits times 29.97 frames per sec
#define zero_time_min 700 // equals 833 (divide by 8 clock pulses)
                                  
#define end_data_position 63
#define end_sync_position 77
#define end_smpte_position 80

volatile unsigned int bit_time;
volatile boolean valid_tc_word;
volatile boolean ones_bit_count;
volatile boolean tc_sync;
volatile boolean write_tc_out;
volatile boolean drop_frame_flag;

volatile byte total_bits;
volatile byte current_bit;
volatile byte sync_count;

volatile byte tc[8];
volatile char timeCode[11];

/* ICR interrupt vector */
ISR(TIMER1_CAPT_vect)
{
 //toggleCaptureEdge
 TCCR1B ^= _BV(ICES1);

 bit_time = ICR1;
 
 //resetTimer1 
 TCNT1 = 0;

 if ((bit_time < one_time_min) || (bit_time > zero_time_max)) // get rid of anything way outside the norm
 {
   //Serial.println(bit_time, DEC);
   total_bits = 0;
 }
 else
 {
   if (ones_bit_count == true) // only count the second ones pluse
     ones_bit_count = false;
   else
   {    
     if (bit_time > zero_time_min)
     {
       current_bit = 0;
       sync_count = 0;
     }
     else //if (bit_time < one_time_max)
     {
       ones_bit_count = true;
       current_bit = 1;
       sync_count++;
       if (sync_count == 12) // part of the last two bytes of a timecode word
       {
         sync_count = 0;
         tc_sync = true;
         total_bits = end_sync_position;
       }
     }

     if (total_bits <= end_data_position) // timecode runs least to most so we need
     { // to shift things around
       tc[0] = tc[0] >> 1;
 
       for(int n=1;n<8;n++)
       {
         if(tc[n] & 1)
           tc[n-1] |= 0x80;
       
         tc[n] = tc[n] >> 1;
       }
 
       if(current_bit == 1)
         tc[7] |= 0x80;
     }
     total_bits++;
   }

   if (total_bits == end_smpte_position) // we have the 80th bit
   {
     total_bits = 0;
     if (tc_sync)
     {
       tc_sync = false;
       valid_tc_word = true;
     }
   }
   
   if (valid_tc_word)
   {
     valid_tc_word = false;

     timeCode[10] = (tc[0]&0x0F)+0x30; // frames
     timeCode[9] = (tc[1]&0x03)+0x30; // 10's of frames
     timeCode[8] = '.';
     timeCode[7] = (tc[2]&0x0F)+0x30; // seconds
     timeCode[6] = (tc[3]&0x07)+0x30; // 10's of seconds
     timeCode[5] = ':';
     timeCode[4] = (tc[4]&0x0F)+0x30; // minutes
     timeCode[3] = (tc[5]&0x07)+0x30; // 10's of minutes
     timeCode[2] = ':';
     timeCode[1] = (tc[6]&0x0F)+0x30; // hours
     timeCode[0] = (tc[7]&0x03)+0x30; // 10's of hours
     
   drop_frame_flag = (tc[1]&0x04)!=0;

     write_tc_out = true;
   }
 }
}

void setup()
{
Serial.begin(115200);
 pinMode(icpPin, INPUT); // ICP pin (digital pin 8 on arduino) as input

 bit_time = 0;
 valid_tc_word = false;
 ones_bit_count = false;
 tc_sync = false;
 write_tc_out = false;
 drop_frame_flag = false;
 total_bits = 0;
 current_bit = 0;
 sync_count = 0;

 //Serial.println("Finished setup ");
 //delay (1000);

 TCCR1A = B00000000; // clear all
 TCCR1B = B11000010; // ICNC1 noise reduction + ICES1 start on rising edge + CS11 divide by 8
 TCCR1C = B00000000; // clear all
 TIMSK1 = B00100000; // ICIE1 enable the icp

 TCNT1 = 0; // clear timer1
}

void loop()
{
   if (write_tc_out)
   {
     write_tc_out = false;
     if (drop_frame_flag)
       Serial.print("TC-[df] ");
     else
       Serial.print("TC-[nd] ");
     Serial.print((char*)timeCode);
     Serial.print("\r");
   }
}

```

So far I have not been able to get anything to show up on Serial Monitor, and since I'm a total beginner, I'm not sure how to check whether it's a problem with my circuit, the code, or something else.

Any ideas? Thanks so much!

---

<div class="post-metadata">

**Author:** ![MarkT](https://avatars.discourse-cdn.com/v4/letter/m/c89c15/32.png) [@MarkT](https://forum.arduino.cc/u/MarkT)\
**Post date:** [January 26, 2015, 7:50pm UTC](https://forum.arduino.cc/t/first-real-circuit-timecode-reader/285148/2 "2015-01-26T19:50:35Z")

</div>

Have you tried substituting a push-button to ground in place of the transistor for  
testing that pin8 is being noticed?

Have you measured the voltages at base and collector of your transistor?

---

<div class="post-metadata">

**Author:** ![jaredcrogers](https://avatars.discourse-cdn.com/v4/letter/j/ac8455/32.png) [@jaredcrogers](https://forum.arduino.cc/u/jaredcrogers)\
**Post date:** [January 26, 2015, 8:26pm UTC](https://forum.arduino.cc/t/first-real-circuit-timecode-reader/285148/3 "2015-01-26T20:26:55Z")

</div>

Thanks for the troubleshooting tips, MarkT!

I'll go pick up a pushbotton, (and a meter for that matter).

Stupid question: would there be a simple way I could also route the input to the LED on pin13 to visually see whether the timecode is reaching the board?

Thanks!

---

<div class="post-metadata">

**Author:** ![jaredcrogers](https://avatars.discourse-cdn.com/v4/letter/j/ac8455/32.png) [@jaredcrogers](https://forum.arduino.cc/u/jaredcrogers)\
**Post date:** [January 26, 2015, 10:18pm UTC](https://forum.arduino.cc/t/first-real-circuit-timecode-reader/285148/4 "2015-01-26T22:18:17Z")

</div>

Okay, so I got ~.15V on the base of the transistor, 4.5V at the collector.

.003V - .005V is all I'm seeing coming from the phone (my timecode generator), that's with the volume all the way up.

Does that sound right?

So far I don't read anything off pin8 but I'll try again with a pushbutton instead of the transistor.

---

<div class="post-metadata">

**Author:** ![Kristian0](https://avatars.discourse-cdn.com/v4/letter/k/dfb087/32.png) [@Kristian0](https://forum.arduino.cc/u/Kristian0)\
**Post date:** [April 18, 2018, 5:29pm UTC](https://forum.arduino.cc/t/first-real-circuit-timecode-reader/285148/5 "2018-04-18T17:29:24Z")

</div>

Hello.

Do you solve the problem with the monitor serial?

I want buy a LCD visor, if you want we can work together in this.

---

<div class="post-metadata">

**Author:** ![Riva](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/riva/32/1013044_2.png) [@Riva](https://forum.arduino.cc/u/Riva)\
**Post date:** [April 19, 2018, 10:54am UTC](https://forum.arduino.cc/t/first-real-circuit-timecode-reader/285148/6 "2018-04-19T10:54:18Z")

</div>

Maybe look at [this](https://forum.arduino.cc/index.php?topic=349447.0) thread that is a bit newer than the OP linked thread.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 6, 2021, 1:41am UTC](https://forum.arduino.cc/t/first-real-circuit-timecode-reader/285148/7 "2021-05-06T01:41:01Z")

</div>

Closed on May 6, 2021, 1:41am UTC


