mborgerson
Well-known member
I'm working on a document describing a satellite ELINT system from the 1970's (That's old enough that I can actually find declassified technical information.) I want to simulate the display the ground station operators would see if they were receiving two channels of data from each of two satellites. The timing of the intercepted radar pulses could be used with Differential Time Of Arrival (DTOA) techniques to locate the emitting radars. When I set up T4.1 with 4 PWM outputs from pins 14, 15, 18 and 19, I got some puzzling results. (Those pins use channels 0,1,2, and 3 of quad timer TMR3.) Since I set up and started all the PWM outputs in quick sequence, I expected all the outputs to rise within a few microseconds of each other. No Such Luck! All the falling edges were lined up! I found that inserting some delays between initializations would result in a fairly close line up of the leading edges. However, the values and positions of the delays don't seem to relate to the shift in the pulse positions. A key factor seems to be that two PWM outputs with the same pulse width line up nicely. DOH! if the pulses are the same width and the trailing edges line up so will the leading edges! I need to use different pulse widths because the ELINT system combined up to four receiver channels on a single downlink by using different pulse width for each channel. (80,120,160 and 200 microseconds high time with a nominal 1000microsecond Pulse Repitition Interval (PRI).
The simplified demo code is attached as are two scope screenshots. Does anybody know what's going on with the PWM initialization?
The simplified demo code is attached as are two scope screenshots. Does anybody know what's going on with the PWM initialization?
Code:
// test of Hardware PWM for POPPY oscilloscope simulation
const char compileTime [] = "\n\nPWM Phase Test compiled on " __DATE__ " " __TIME__;
#define PWPIN0 19 // yellow
#define PWPIN1 18 // purple
#define PWPIN2 14 // blue
#define PWPIN3 15 // green
#define PRI0 1000 // 1.00 mSec
void InitPWM(bool withdelays){
analogWriteResolution(10); // 10 bits = 1024 steps
// Common to all channels
analogWriteFrequency(PWPIN3, PRI0);
if(withdelays){delayMicroseconds(10);}
analogWriteFrequency(PWPIN2, PRI0);
if(withdelays){delayMicroseconds(28);}
analogWriteFrequency(PWPIN1, PRI0);
analogWriteFrequency(PWPIN0, PRI0);
analogWrite(PWPIN3, 200); // 200 uSec
analogWrite(PWPIN2, 160); // 160 uSec
analogWrite(PWPIN1, 80); // 80 uSec
if(withdelays){
analogWrite(PWPIN0, 80); // 80 uSec
} else {
analogWrite(PWPIN0, 200); // 80 uSec
}
}
void setup() {
Serial.begin(9600);
delay(1000); // wait for PC to connect
Serial.println(compileTime);
Serial.println("Starting PWM output");
InitPWM(true);
}
void loop() {
// Do 5 seconds with delays, then 5 seconds without them
InitPWM(true);
delay(5000);
InitPWM(false);
delay(5000);
} // end of loop()