You can see the timing I'm using in the defines at the top of the code... some may need tweaking...
Test!!! Code!!!

Code:
#include <TimerOne.h>
#define CYCLE_TIME 1662 // 0.0015625 Seconds @ 640 PPS // added 100 to 1562 to make is closer to 640pps //
#define TX_PULSE 100 //(100µs) 100µs
#define PULSE_1_DELAY 20 //( 20µs) Delay before Sample Pulse 1
#define PULSE_1 45 //( 45µs) Sample 1 Pulse Duration
#define PULSE_2_DELAY 100 //( 100µs) Delay between Sample Pulse 1 and Pulse 2
#define PULSE_2 45 //( 45µs) Sample 2 Pulse Duration 45µs
/*
Total Pulses Time 310
-----------------------------
Cycle Time 1562
Pulse Times -310
Delay till next cycle 1252
Actual cycle time is 1/1562 µs = ~640
*/
volatile bool in_long_isr = false; // True if in long interrupt
int cnt = 0;
void setup()
{
pinMode (A0, OUTPUT);
pinMode (A1, OUTPUT);
pinMode (A2, OUTPUT);
digitalWrite (A0, LOW);
digitalWrite (A1, LOW);
digitalWrite (A2, LOW);
Serial.begin(9600);
Timer1.initialize(CYCLE_TIME);
Timer1.attachInterrupt(do_isr);
}
void loop()
{
Serial.println(cnt++);
delay(100);
}
void do_isr()
{
if (in_long_isr)
{
return;
}
in_long_isr = true;
cli () ;
PINC = 0x01;
delayMicroseconds(TX_PULSE);
PINC = 0x01;
delayMicroseconds(PULSE_1_DELAY);
PINC = 0x02;
delayMicroseconds(PULSE_1) ;
PINC = 0x02;
delayMicroseconds(PULSE_2_DELAY);
PINC = 0x04;
delayMicroseconds(PULSE_2);
PINC = 0x04;
sei () ;
in_long_isr = false;
}
You may note I'm using the analogue pins, that's because I've used all of the others for the Keys and LCD...
As usual, if you find any error please be polite when posting...

I've tested and scoped the pulses and everything look good, next to get the keys and LCD up and running...
Mike



Leave a comment: