Hallo Allemaal,
Heb vandaag weer zitten prutsen aan de arduino nano koppelen aan de PA8W 2.3 Doppler peiler.
Bedoeling is dat er agrelo (%bbb) uit de USB komt voor allerlei kaart programma's
Nog niet alles klaar maar alvast een voor proefje.
De arduino sketch zit er ook bij
Niet alles is klaar en working Yet !
Groeten,
Lodewijk
Source =============================================================== /* ((C))PA3BNX Arduino PA8W Agelo 19-09-2017 Not all ready yet! 2^5 data bits from PA8W and Strobe I think tap from 4017 the 5 bits and tap the freeze led as Strobe/Squelch 2^4 data bits and strobe from other dopplers Purpose is to give Agrelo Serial out with a cheap arduino(Uno,Nano) on existing doppler. ------- Use a inverting transistor to interface bits and strobe from doppler to arduino ------- Arduino outputs Agrelo like %DDD<cr><lf> Replacement 1995-N7LUE.pdf Agrelo Interface BY ROBERT SWAIN 4 or 5 counter hardware bits from 4040 or 4060 in hardware doppler and the strobe Zerocross pin. //Options also possible with arduino ? Arduino could also do GPS Module and output NMEA on software serial port ? Arduino could also do FluxCompas HMC5883 TWI interface ? 22-09-2017 04-08-2018 20-11-2019 potmeter 0 offset degrees so hardware pelorus same as agrelo pelorus ??? 22-11-2019 */
//Int const byte pinData[] = {2, 3, 4, 5, 6}; const byte pinStrobe = 7; const byte pinOffset = A0; //Pin offset Potmeter
//Const const int cNodegrees = 999; //Squelch const int cReset = 888; //Reset averaged with last degrees value only const double f = 359/1023; const int cSquelchOpenMax= 5000;//Max averaged time in Averaged sub
int Offset = 0;
unsigned long SquelchOpenStart = millis();
//Bool bool bMultiPathAverage; bool bAverage = true; bool bDemo = true;
void Message() { Serial.println(F("PA8W USB Agrelo Doppler Interface")); Serial.println(F("---------------------------------")); if (bDemo == true) { Serial.println(F("DemoMode")); } Serial.print(F("Data pins LSB to MSB=")); for (byte i = 0; i < 4; i++) { Serial.print(pinData[i]); Serial.print(" "); } Serial.println(); Serial.print(F("Strobe pin=")); Serial.println(pinStrobe); Serial.println(F("Squelch = LED_BUILDIN")); Serial.print(F("Offset pin="));Serial.println(pinOffset); }//==================Last Message==========================
int GetDemo(int x1, int x2) { const byte m = 55; static byte i; int x;
i++; x = random(x1, x2); if (i > m) { i = 0; return cNodegrees; } else { return x; } }//=============================Last Demo=================
void GetOffset() { int x;
x=int(analogRead(pinOffset) * f); Offset= LimitDegrees360( x + 180); }
int Calibrate(int x) {
if (x == cNodegrees) { return x; } else { return LimitDegrees360(x + Offset); } }
//Return Agrelo formatted string % and always 3 digits String Format3Degrees(int d) { String str; int digits[3]; int reminder; digits[0] = d / 100; reminder = d % 100; digits[1] = reminder / 10; reminder = reminder % 10; digits[2] = reminder; str += '%'; str += digits[0]; str += digits[1]; str += digits[2]; return str; }//==============================Last Format3Degrees==================================
//Limit Degrees 0 to 360 degrees int LimitDegrees360(int d) { //Limit degrees 0 to 360 here //If 999 then return 999 if (d == cNodegrees) { return d; } else { int x; x = d % 360; if (x < 0) { x += 360; } return x; } }//-------------------------------------Last LimitDegrees360==============================
//Get data from 4040 or 4060 counter in the doppler ? //Digital counting
//So get time to get the degrees counter lines
//Create new Function detecting Strobe for some time?
int GetBearing4() { int x = 0;
if (digitalRead(pinStrobe) == HIGH) { for (byte i = 0; i < 3; i++) { if (digitalRead(pinData[i] == LOW)) { x += pow(i, 2); } } return int(x * 22.5); } else { return cNodegrees; } }
int GetBearing5() { int x = 0;
if (digitalRead(pinStrobe) == HIGH) { for (byte i = 0; i < 4; i++) if (digitalRead(pinData[i] == LOW)) { x += pow(i, 2); } return int(x * 11.25); } else { return cNodegrees; } }
//----------------------------------------Average Degrees------------------------------------ int Average(int d) { //If d = 999 (cNoDegrees) then reset average and return last avDegrees witch is 999 //If d = 888 (cReset) then Reset all and put last avDegrees back in arrays
//Always return avDegrees and Set bMultiPath
//Integer static unsigned int sum[4] = {0, 0, 0, 0}; //Sum of counts for each kwadrant can be now 2^16=65536 static int c[4] = {0, 0, 0, 0}; //Amount of count static int totalCount = 0; //Sum of all counts static int avDegrees = cNodegrees; //Averaged degrees int xx[4] = {0, 0, 0, 0}; //Adjacent kwadrants counts int z = 0; //Most adjacent headings int z1 = 0; //Other two kwandants headings Multipath int y = 0; //Index where the most headings are
//Reset/clear and return cNodegrees or last avDegrees
//01-06-2015 No Averaging if (bAverage == false) { return d; }
//No Overflow in sum[] if (totalCount >= 180) { for (byte i = 0; i < 4; i++) { sum[i] = 0; c[i] = 0; } }
switch (d) { case cNodegrees: //Reset and Clear for (byte i = 0; i < 4; i++) { sum[i] = 0; c[i] = 0; } bMultiPathAverage = false; avDegrees = cNodegrees; return avDegrees; //Exit now case cReset: //Reset and fill with avDegrees //Reset for (byte i = 0; i < 4; i++) { sum[i] = 0; c[i] = 0; } //Fill with last avDegrees d = avDegrees; //Put last degrees in again }
if (d >= 0 && d < 90) { sum[0] += d; c[0]++; } if (d >= 90 && d < 180) { sum[1] += d; c[1]++; } if (d >= 180 && d < 270) { sum[2] += d; c[2]++; } if (d >= 270 && d <= 360) { sum[3] += d; c[3]++; }
//No degrees found so exit function totalCount = c[0] + c[1] + c[2] + c[3]; if (totalCount == 0) { bMultiPathAverage = false; avDegrees = cNodegrees; return avDegrees; }
//Find 2 adjacent kwadrants with hold most heading counts
//Count all adjacents kwadrants xx[0] = c[0] + c[1]; xx[1] = c[1] + c[2]; xx[2] = c[2] + c[3]; xx[3] = c[3] + c[0];
//Find out in witch two kwadrants the most headings are for (byte i = 0; i < 4; i++) { if (xx[i] > z) { z = xx[i]; //Most adjacent Headings counts y = i; //Witch 2 adjacent Array Index from xx[1] } }
//Check for multipath kwadrants switch (z) { case 0: z1 = 2; break; case 1: z1 = 3; break; case 2: z1 = 0; break; case 3: z1 = 1; break; }
if (xx[z] == xx[z1]) { bMultiPathAverage = true; } else { bMultiPathAverage = false; }
//Average the 2 most counts kwadrants switch (y) { case 0: avDegrees = (sum[0] + sum[1]) / xx[y]; break; case 1: avDegrees = (sum[1] + sum[2]) / xx[y]; break; case 2: avDegrees = (sum[2] + sum[3]) / xx[y]; break; case 3: if (c[3] == 0 && c[1] > 0) { avDegrees = sum[1] / c[1]; } else if (c[1] == 0 && c[3] > 0) { avDegrees = sum[3] / c[3]; } else if (c[3] > 0 && c[1] > 0) { avDegrees = LimitDegrees360(((sum[3] / c[3]) + ((sum[0] / c[0]) + 360) / 2)); }
break; }
return avDegrees; }//-----------------------------Last Average--------------------------------------------
void setup() { // put your setup code here, to run once:
Serial.begin(9600);
pinMode(LED_BUILTIN, OUTPUT); //Squelch indicator ?
for (byte x; x < 5; x++) { pinMode(pinData[x], INPUT_PULLUP); } pinMode(pinStrobe, INPUT_PULLUP);
Message();
Average(cNodegrees); //Init Average() returns cNoDegrees
}//------------------------------Last Setup==============================================
void loop() { //Put your main code here, to run repeatedly: static int OldDegrees; int x = cNodegrees;
GetOffset();
if (bDemo == true) { x = GetDemo(110, 290); //begin and end degrees } else { //Does the strobe be positive or negative edge triggerd ? //Squelch can be detected through ? and trigger LED_BUILTIN int start = millis() + 10; do { x = GetBearing4(); //x=GetBearing5(); } while (start < millis() && x != cNodegrees); }
x = Average(x);
//Detect when squelch = closed if (OldDegrees==cNodegrees) { SquelchOpenStart = millis() + cSquelchOpenMax; }
//bMultiPathAverage, bAverage, cReset ???? //Reduce data over RS232
if (OldDegrees != x ) { if (bMultiPathAverage == false || x == cNodegrees) { //Serial.println(Format3Degrees(LimitDegrees360(x))); Serial.println(Format3Degrees(Calibrate(x))); if (x == cNodegrees) { digitalWrite(LED_BUILTIN, HIGH); } else { digitalWrite(LED_BUILTIN, LOW); } OldDegrees = x; } }
//reset average after a while averaging ??? if (millis() > SquelchOpenStart) { SquelchOpenStart = millis() + cSquelchOpenMax; Average(cReset);//Save only last Averaged degrees value } delay(100);
}//=== =============================Last Loop ================================================
Bijlagen: |

DSC02021-1.jpg [ 159.87 KiB | 289 keer bekeken ]
|

HEF4050-arduino-1.png [ 81.7 KiB | 289 keer bekeken ]
|

DSC02021-1.jpg [ 159.87 KiB | 289 keer bekeken ]
|
_________________ 73's PA3BNX Lodewijk
Mijn Credo!
Zelfbouw: Minimaal hardware en maximaal software.
|