Sequencer programvaran klar.

Jag vill tacka SM0RVV/Erik för programmeringen. Själv har jag stått för funderingarna och elektronikkopplingarna. Mitt bygge innehåller lite mer än schemat, t.ex. optokopplare för att nyckla alla utgångar.

Sequencerns programvara är alltså nu färdig att släppas. Ritningen hittar ni på följande ställe. Glöm dock INTE att koppla in pullupmotstånd till ALLA in-pinnarna. Det får väl bli er hemläxa som elektronikövning 😉 . Jag kommer att lägga ett snyggare schema när jag hinner, men som ni förstår så har jag en NAC 144 att hinna klart till. Och då gäller det att köra på med projekten.

Här följer koden. Den kan du kopiera och klistra in i ditt eget projekt.

sketch_feb26a_SEQUENCER_0_4_rvv_5a

 

Creative Commons-licens
Arduino sequencer for ham radio by Erik Linder/SM0RVV Kai Rämö/SM0RCL is licensed under a Creative Commons Erkännande-DelaLika 3.0 Unported License.

// SM0RCL sequencer for controtrolling power amplifier and pre-amp with single PTT
// With small adjustments by SM0RVV

// constants won’t change. They’re used here to
// set pin numbers:
const byte ptt_in_Pin = 6;        // PTT input pin
const byte pre_in_Pin =  7;       // pre-aplifier input pin
const byte pa_in_Pin =  8;        // power aplifier input pin
const byte pre_on_Pin =  9;       // pre-aplifier on pin
const byte pa_on_Pin =  10;       // poweraplifier on pin
const byte rig_on_Pin =  13;      // PTT rig on pin

// Vars
boolean isTX = false;               // Keep track of what we are doing, true || false
boolean isPre = false;              // Keep track of preamp, true || false
boolean debug = false;              // Set to true for debug messages om serial port
unsigned int pre_off_dly = 200;    // delay for preamp to go to safe state, max 65535
unsigned int pa_on_dly = 200;      // delay for PA to get ready for tx, max 65535
unsigned int pa_off_dly = 200;     // delay to protect preamp and rx from pa, max 65535
unsigned int ptt_off_dly = 200;    // delay to protect preamp and rx from rig, max 65535
byte debounceTime = 50;            // time for ptt to settle, 0-255
long time;                         // long time – no se. 🙂 reference time for debounce

// Soft control of active high or active low for all pins
// INPUTS
byte ptt_in_ON = LOW;                // Active state for PTT in, 0 = active low, 1 = active high
byte ptt_in_OFF = HIGH;              // Active state for PTT in, 0 = active low, 1 = active high
byte pa_in_ON = HIGH;                // Active state for PA in, 0 = active low, 1 = active high
byte pa_in_OFF = LOW;                // Active state for PA in, 0 = active low, 1 = active high
byte pre_in_ON = HIGH;               // Active state for PRE in, 0 = active low, 1 = active high
byte pre_in_OFF = LOW;               // Active state for PRE in, 0 = active low, 1 = active high
// OUTPUTS
byte ptt_out_ON = HIGH;              // Active state for PTT out, 0 = active low, 1 = active high
byte ptt_out_OFF = LOW;              // Active state for PTT out, 0 = active low, 1 = active high
byte pa_out_ON = HIGH;               // Active state for PA out, 0 = active low, 1 = active high
byte pa_out_OFF = LOW;               // Active state for PA out, 0 = active low, 1 = active high
byte pre_out_ON = HIGH;              // Active state for PRE out, 0 = active low, 1 = active high
byte pre_out_OFF = LOW;              // Active state for PRE out, 0 = active low, 1 = active high

void setup() {

if (debug) {
Serial.begin(9600);
}

if (debug) {
Serial.println(”Setup starting…”);
}

pinMode(ptt_in_Pin, INPUT);
pinMode(pre_in_Pin, INPUT);
pinMode(pa_in_Pin, INPUT);

pinMode(pre_on_Pin, OUTPUT);
pinMode(pa_on_Pin, OUTPUT);
pinMode(rig_on_Pin, OUTPUT);

// Ensure we don’t start TX here
digitalWrite (pa_on_Pin, pa_out_OFF);    // pa RX
digitalWrite (rig_on_Pin, ptt_out_OFF);   // rig RX

if (debug) {
Serial.println(”Waiting for ! PTT…”);
}

// read the state of the PTT input
// Refuse to start sequencer with PTT on
while (digitalRead(ptt_in_Pin) == ptt_in_ON) {
// Maybe some kind of error here? LED? LCD? Beep?
delay (200);
}

// Start preamp if the user want it
if (digitalRead (pre_in_Pin) == pre_in_ON) {
digitalWrite (pre_on_Pin, pre_out_ON);
}
else {
digitalWrite (pre_on_Pin, pre_out_OFF);
}

if (debug) {
Serial.println(”Setup ended…”);
}
}

void loop() {

if (debug) {
Serial.println(”loop starting…”);
Serial.print(”isTX: ”);
Serial.println(isTX);
Serial.print(”ptt_in_Pin: ”);
Serial.println(digitalRead(ptt_in_Pin));
}

if (digitalRead(ptt_in_Pin) == ptt_in_ON) {  // PTT is pressed
time = millis();              // Reset time

while (millis() < time + debounceTime); // wait a moment

// Only call TX if we are in RX
if (digitalRead(ptt_in_Pin) == ptt_in_ON && !isTX) {
TX();
}

// Only call RX if we are in TX
if (digitalRead(ptt_in_Pin) == ptt_in_OFF && isTX) {
RX();
}
}

// Preamp control off
if (digitalRead(pre_in_Pin) == pre_in_OFF && isPre) {
PreCtrl(false);
}

// Preamp control on
if (digitalRead(pre_in_Pin) == pre_in_ON && !isTX && !isPre) {
PreCtrl(true);
}

if (debug) {
Serial.println(”loop ended…”);
delay(500);
}

}

void TX() {

if (debug) {
Serial.println(”TX…”);
}

isTX = true;

// We’re running with afterburner
if (digitalRead(pa_in_Pin) == pa_in_ON) {
if (digitalRead(pre_in_Pin) == pre_in_ON) {
preOff();
}
paOn();
pttOn();
}

// We’re running barefoot
else {
if (digitalRead(pre_in_Pin) == pre_in_OFF) {
preOff();
}
pttOn();
}
}

void RX() {

if (debug) {
Serial.println(”RX…”);
}

isTX = false;

// We’re running with afterburner
if (digitalRead(pa_in_Pin) == pa_in_ON) {
pttOff();
paOff();
if (digitalRead(pre_in_Pin) == pre_in_ON) {
preOn();
}
}

// We’re running barefoot
else {
pttOff();
if (digitalRead(pre_in_Pin) == pre_in_ON) {
preOn();
}
}
}

void PreCtrl(boolean use) {
if (use) {
isPre = true;
preOn();
}
else {
isPre = false;
preOff();
}
}

void paOff() {
digitalWrite (pa_on_Pin, pa_out_OFF);
}

void paOn() {
digitalWrite (pre_on_Pin, pre_out_OFF); // To be extra extra shure. aka damage control
digitalWrite (pa_on_Pin, pa_out_ON);
delay (pa_on_dly);
}

void preOn() {
delay (pa_off_dly);  // maybe this delay should be placed in ”paOff()” ????
digitalWrite (pre_on_Pin,pre_out_ON);
}

void preOff() {
digitalWrite (pre_on_Pin,pre_out_OFF);
delay (pre_off_dly);
}

void pttOn() {
digitalWrite (pre_on_Pin, pre_out_OFF); // To be extra extra shure. aka damage control
digitalWrite (rig_on_Pin, ptt_out_ON);
}

void pttOff() {
digitalWrite (rig_on_Pin,ptt_out_OFF);
}

Annonser

2 Responses to “Sequencer programvaran klar.”


  1. 1 Erik mars 26, 2012 kl. 07:58

    Thumbs Up!


Kommentera

Fyll i dina uppgifter nedan eller klicka på en ikon för att logga in:

WordPress.com Logo

Du kommenterar med ditt WordPress.com-konto. Logga ut / Ändra )

Twitter-bild

Du kommenterar med ditt Twitter-konto. Logga ut / Ändra )

Facebook-foto

Du kommenterar med ditt Facebook-konto. Logga ut / Ändra )

Google+ photo

Du kommenterar med ditt Google+-konto. Logga ut / Ändra )

Ansluter till %s