Using SMPTE to control digital outputs.
i've built smpte reader that's been done few people on here, need develop little further in order control old reel reel tape machine. modifying code appreciated!
i need to:
ground pin @ timecode, wait 2 minutes or so, ground different pin.
ground pin when audio input not being received.
i need to:
ground pin @ timecode, wait 2 minutes or so, ground different pin.
ground pin when audio input not being received.
code: [select]
//
//
// include library code:
#include <liquidcrystal.h>
// initialize library numbers of interface pins
liquidcrystal lcd(12, 11, 5, 4, 3, 2);
#define one_time_max 588 //
#define one_time_min 422 //
#define zero_time_max 1080 //
#define zero_time_min 922 //
#define icppin 8 // icp input pin on arduino
//#define one_time_max 475 // these values setup ntsc video
//#define one_time_min 300 // pal around 1000 0 , 500 1
//#define zero_time_max 875 // 80bits times 29.97 frames per sec
//#define zero_time_min 700 // equals 833 (divide 8 clock pulses)
#define end_data_position 63
#define end_sync_position 77
#define end_smpte_position 80
volatile unsigned int pin = 13;
volatile unsigned int bit_time; // volatile instructs variable stored in ram
volatile boolean valid_tc_word; // booleon can either of 2 values true or false
volatile boolean ones_bit_count; // booleon can either of 2 values true or false
volatile boolean tc_sync; // booleon can either of 2 values true or false
volatile boolean write_tc_out; // booleon can either of 2 values true or false
volatile boolean drop_frame_flag; // booleon can either of 2 values true or false
volatile byte total_bits; //this stores 8-bit unsigned number
volatile byte current_bit; //this stores 8-bit unsigned number
volatile byte sync_count; //this stores 8-bit unsigned number
volatile byte tc[8]; //this stores 8-bit unsigned number
volatile char timecode[11]; //this stores 8-bit unsigned number
/* icr interrupt vector */
isr(timer1_capt_vect) //isr=interrupt service routine, , timer1 capture event
{
//togglecaptureedge
tccr1b ^= _bv(ices1); //toggles edge triggers handler duration of both high , low pulses measured.
bit_time = icr1; //this value timer generates
//resettimer1
tcnt1 = 0;
if ((bit_time < one_time_min) || (bit_time > zero_time_max)) // gets rid of that's not we're looking for
{
total_bits = 0;
}
else
{
if (ones_bit_count == true) // count 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 last 2 bytes of timecode word
{
sync_count = 0;
tc_sync = true;
total_bits = end_sync_position;
}
}
if (total_bits <= end_data_position) // timecode runs least need
{ // shift things around
tc[0] = tc[0] >> 1;
for(int n=1;n<8;n++) //creates tc[1-8]
{
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) // have 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 converst binary decimal giving last digit
timecode[9] = (tc[1]&0x03)+0x30; // 10's of frames converst binary decimal giving first digit
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 = bit_is_set(tc[1], 2); //detects whether theree drop frame bit.
write_tc_out = true;
}
}
}
void setup()
{
lcd.begin (16, 2);
pinmode(icppin, input); // icp pin (digital pin 8 on arduino) 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;
lcd.print("finished setup");
delay (1000);
tccr1a = b00000000; // clear all
tccr1b = b11000010; // icnc1 noise reduction + ices1 start on rising edge + cs11 divide 8
tccr1c = b00000000; // clear all
timsk1 = b00100000; // icie1 enable icp
tcnt1 = 0; // clear timer1
}
void loop()
{
if (write_tc_out)
{
write_tc_out = false;
if (drop_frame_flag)
lcd.print("tc-[df] ");
else
lcd.print("tc-no drop frame");
lcd.setcursor(0, 1);
lcd.print((char*)timecode);
lcd.print("\r");
lcd.setcursor(11, 1);
lcd.print("......");
delay (40);
lcd.clear(); } }
quote
i need to:
ground pin @ timecode, wait 2 minutes or so, ground different pin.
ground pin when audio input not being received.
so, problem?
Arduino Forum > Using Arduino > Programming Questions > Using SMPTE to control digital outputs.
arduino
Comments
Post a Comment