Show Posts
Pages: 1 [2] 3
16  Forum 2005-2010 (read only) / Syntax & Programs / Re: Need help with interrupts on: June 25, 2010, 12:54:12 pm
Ok the buffer transistor with a pulldown has me CLOSE.  Getting the 'bad delay' i was afraid of with the loop routine - i just dont want to wait the 1 second for the loop to progress to pick up a key... back to interrupts now after this slight distraction. At least the electronics are now good, and I have an idea of what im doing with the code... very close now I think.
17  Forum 2005-2010 (read only) / Syntax & Programs / Re: Need help with interrupts on: June 25, 2010, 06:53:12 am
It's connected to an external voltage source thats normally high (common ground to the arduino, though).
 
Maybe I'll add a buffer transistor and pull from the 5v bus and see if it likes that better. I guess thats more 'correct' anyway.
18  Forum 2005-2010 (read only) / Syntax & Programs / Re: Need help with interrupts on: June 24, 2010, 10:53:36 pm
Ok... Found a problem.

I've got a variable that seems to be changing value. And Im not sure why.


cosstate should always be 0 (because its never goes to 1)... at least not as far as I can detect.

But it seems to be going to 1... and then invoking the wrong section of the 'if'. Causing it to key up, key down, loop, key up, key down, loop.

See below. Pay attention to the top section (if clause) of the loop section.

Code:
COS is at V+ (Squelch Closed)
another second elapsed
Begin Loop Routine
COS is at V+ (Squelch Closed)
another second elapsed
Begin Loop Routine
COS is at GND (Squelch Open)
Key
Begin Loop Routine
COS is at V+ (Squelch Closed)
We had been previously keyed
ct
unKey
another second elapsed
Begin Loop Routine
COS is at V+ (Squelch Closed)
another second elapsed
Begin Loop Routine
COS is at GND (Squelch Open)
Key
Begin Loop Routine
COS is at GND (Squelch Open)
Key
Begin Loop Routine
COS is at V+ (Squelch Closed)
We had been previously keyed
ct
unKey
another second elapsed

current code is this

Code:
/*
  ###########################################################
  #  Program: KC8OZA-ID - Open Source Repeater Controller   #
  #  Author: Josh Kittle, KC8OZA                            #
  #  Date: 06/2010                                          #
  #  Written for use on the Arduino Platform                #
  ###########################################################
*/



/*
    ######################################
    #  Includes and Variable Definitions #
    ######################################
*/

#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

int dahfreq = 600;
int ditfreq = 600;
int multi = 40;
int pttPin = 14;
int txActvLED = 4;
int txStbyLED = 5;
int audioPin = 6;                       // This pin is the audio output for CWID and Courtesy Tonet
int cosPin = 3;                          // COS Detect Pin
int waskeyed = 0;
int cosState;
char countertxt[3];
int original_id_timer = 15;
int cur_id_timer = original_id_timer;
int id_timer;
char cur_timetxt[5];

/*
    ##################
    #  Setup Routine #
    ##################
*/
    
void setup() {
Serial.begin(9600);
  // Define LCD Configuration Parameters
  
      lcd.begin(20, 4);  // Define the LED Size (4x20 LCD shown)
      
  
  // Display the initialization information on the LCD
 
      delay(3000);
      lcd.clear();
      lcd.setCursor(2, 0);
      lcd.print("KC8OZA  Repeater");
      lcd.setCursor(2, 2);
      lcd.print("Controller  Init");
 
 
  // Define Pin Modes
    
      pinMode(cosPin, INPUT);       // This is used for sensing COS activity
      pinMode(txActvLED, OUTPUT);  // This LED is lit when TXing
      pinMode(txStbyLED, OUTPUT);  // This LED is lit when not TXing
      pinMode(pttPin, OUTPUT);
  
      delay(3000);    
        digitalWrite(txStbyLED, HIGH);
        digitalWrite(txActvLED, LOW);
      
      cwid(); // ID the repeater on power-up
}

/*
    ##################
    #  Main Program  #
    ##################
*/

void loop() {
  Serial.println("Begin Loop Routine");
  lcd.clear();
  
  // Stuck in this loop while counting to do the ID




 cosState = digitalRead(cosPin);
 
if (cosState == 0)
{
  Serial.println("COS is at GND (Squelch Open)");
  Key();

  waskeyed = 1;
}
 
  else
  {
    
    Serial.println("COS is at V+ (Squelch Closed)");
    if (waskeyed == 1)
    {
      Serial.println("We had been previously keyed");
     // Key();
     ct();
     unKey();  
    
    waskeyed = 0;
}






  
  
  if (id_timer < cur_id_timer) {
  Serial.println("another second elapsed");
   delay (1000);
    
    cur_id_timer = cur_id_timer - 1;
    itoa(cur_id_timer, cur_timetxt, 10);
    
    lcd.clear();
    lcd.setCursor(2, 0);
    lcd.print("KC8OZA  Repeater");
    lcd.setCursor(4, 2);
    lcd.print(cur_timetxt);
    lcd.print(" sec to ID");
    
   }
  else
  {
    cwid();  // Timer Expired - ID the repeater
  }
 
 
}
}

/*
    ##################
    #  CWID Routine  #
    ##################
*/

void cwid()
{
  Serial.println("running cwid");
  lcd.clear();
  lcd.setCursor(2, 0);
  lcd.print("KC8OZA  Repeater");
  lcd.setCursor(3, 2);
  lcd.print("ID In Progress");
    
  Key();
  
  dah();
  dit();
  dah();
  letterspace();  // K
  dah();
  dit();
  dah();
  dit();
  letterspace(); // C
  dah();
  dah();
  dah();
  dit();
  dit();
  letterspace(); // 8
  dah();
  dah();
  dah();
  letterspace(); //O
  dah();
  dah();
  dit();
  dit();
  letterspace(); // Z
  dit();
  dah();
  letterspace(); // A

  unKey();
  ct();
cur_id_timer = original_id_timer;


}


/*
    ##################
    #  CW Routines   #
    ##################
*/

void dit()
{
  delay(1*multi);
  //digitalWrite(txPin, HIGH);
  tone(audioPin, ditfreq);
  delay(1*multi);
  noTone(audioPin);
  //delay(75);
  //tone(txPin, freq, 225);
}

void dah()
{
  delay(1*multi);
  //digitalWrite(txPin, HIGH);
  tone(audioPin, dahfreq);
  delay(3*multi);
  noTone(audioPin);
  //digitalWrite(txPin, LOW);
  //tone(txPin, freq, 225);
}

void letterspace()
{
  delay(2*multi);
}


void unKey()
{
  digitalWrite(txStbyLED, HIGH);
  digitalWrite(txActvLED, LOW);
  digitalWrite(pttPin, LOW); // Ensure the transmitter is not keyed by forcing the pin LOW (use pulldown instead??)
  Serial.println("unKey");
}

void Key()
{
  digitalWrite(txStbyLED, LOW);
  digitalWrite(txActvLED, HIGH);
  digitalWrite(pttPin, HIGH); // Ensure the transmitter is keyed by forcing the pin HIGH
  Serial.println("Key");
}

void ct()
{
   tone(audioPin, ditfreq*2, 200);
   Serial.println("ct");
}




19  Forum 2005-2010 (read only) / Syntax & Programs / Re: Need help with interrupts on: June 24, 2010, 10:33:48 pm
Sorry to be jumping around so much - but we're under active rapid development... hehe.

For play, I've removed the 'interrupt' side of things (and I'm thinking I'll be putting them back) just to try and whip the looping part of things - its really close. The input pin state changes are triggering the output pin state changes - but when the transmitter kicks in it immediately drops (runs the key() then unkey() - it should be staying keyed.   Still looking to see whats going on there.

.. many code changes. The latest revision (been renaming stuff to make it make more sense in my head)

Code:
/*
  ###########################################################
  #  Program: KC8OZA-ID - Open Source Repeater Controller   #
  #  Author: Josh Kittle, KC8OZA                            #
  #  Date: 06/2010                                          #
  #  Written for use on the Arduino Platform                #
  ###########################################################
*/



/*
    ######################################
    #  Includes and Variable Definitions #
    ######################################
*/

#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

int dahfreq = 600;
int ditfreq = 600;
int multi = 40;
int pttPin = 14;
int txActvLED = 4;
int txStbyLED = 5;
int audioPin = 6;                       // This pin is the audio output for CWID and Courtesy Tonet
int cosPin = 3;                          // COS Detect Pin
int waskeyed = 0;
int cosState;
char countertxt[3];
int original_id_timer = 15;
int cur_id_timer = original_id_timer;
int id_timer;
char cur_timetxt[5];

/*
    ##################
    #  Setup Routine #
    ##################
*/
    
void setup() {
Serial.begin(9600);
  // Define LCD Configuration Parameters
  
      lcd.begin(20, 4);  // Define the LED Size (4x20 LCD shown)
      
  
  // Display the initialization information on the LCD
 
      delay(3000);
      lcd.clear();
      lcd.setCursor(2, 0);
      lcd.print("KC8OZA  Repeater");
      lcd.setCursor(2, 2);
      lcd.print("Controller  Init");
 
 
  // Define Pin Modes
    
      pinMode(cosPin, INPUT);       // This is used for sensing COS activity
      pinMode(txActvLED, OUTPUT);  // This LED is lit when TXing
      pinMode(txStbyLED, OUTPUT);  // This LED is lit when not TXing
      pinMode(pttPin, OUTPUT);
  
      delay(3000);    
        digitalWrite(txStbyLED, HIGH);
        digitalWrite(txActvLED, LOW);
      
      cwid(); // ID the repeater on power-up
}

/*
    ##################
    #  Main Program  #
    ##################
*/

void loop() {
  Serial.println("Begin Loop Routine");
  lcd.clear();
  
  // Stuck in this loop while counting to do the ID
 cosState = digitalRead(cosPin);
 
if (cosState == 0)
{
  Serial.println("IF cosstate ==0");
  Key();

  waskeyed = 1;
}
 
  else
  {
    
    Serial.println("IF cosstate == 1");
    if (waskeyed == 1)
    {
      Serial.println("IF waskeyed ==1");
     // Key();
     ct();
     unKey();  
    
    waskeyed = 0;
}


  
  
  if (id_timer < cur_id_timer) {
  Serial.println("another second elapsed");
   delay (1000);
    
    cur_id_timer = cur_id_timer - 1;
    itoa(cur_id_timer, cur_timetxt, 10);
    
    lcd.clear();
    lcd.setCursor(2, 0);
    lcd.print("KC8OZA  Repeater");
    lcd.setCursor(4, 2);
    lcd.print(cur_timetxt);
    lcd.print(" sec to ID");
    
   }
  else
  {
    cwid();  // Timer Expired - ID the repeater
  }
 
 
}
}

/*
    ##################
    #  CWID Routine  #
    ##################
*/

void cwid()
{
  Serial.println("running cwid");
  lcd.clear();
  lcd.setCursor(2, 0);
  lcd.print("KC8OZA  Repeater");
  lcd.setCursor(3, 2);
  lcd.print("ID In Progress");
    
  Key();
  
  dah();
  dit();
  dah();
  letterspace();  // K
  dah();
  dit();
  dah();
  dit();
  letterspace(); // C
  dah();
  dah();
  dah();
  dit();
  dit();
  letterspace(); // 8
  dah();
  dah();
  dah();
  letterspace(); //O
  dah();
  dah();
  dit();
  dit();
  letterspace(); // Z
  dit();
  dah();
  letterspace(); // A

  unKey();
  ct();
cur_id_timer = original_id_timer;


}


/*
    ##################
    #  CW Routines   #
    ##################
*/

void dit()
{
  delay(1*multi);
  //digitalWrite(txPin, HIGH);
  tone(audioPin, ditfreq);
  delay(1*multi);
  noTone(audioPin);
  //delay(75);
  //tone(txPin, freq, 225);
}

void dah()
{
  delay(1*multi);
  //digitalWrite(txPin, HIGH);
  tone(audioPin, dahfreq);
  delay(3*multi);
  noTone(audioPin);
  //digitalWrite(txPin, LOW);
  //tone(txPin, freq, 225);
}

void letterspace()
{
  delay(2*multi);
}


void unKey()
{
  digitalWrite(txStbyLED, HIGH);
  digitalWrite(txActvLED, LOW);
  digitalWrite(pttPin, LOW); // Ensure the transmitter is not keyed by forcing the pin LOW (use pulldown instead??)
  Serial.println("unKey");
}

void Key()
{
  digitalWrite(txStbyLED, LOW);
  digitalWrite(txActvLED, HIGH);
  digitalWrite(pttPin, HIGH); // Ensure the transmitter is keyed by forcing the pin HIGH
  Serial.println("Key");
}

void ct()
{
   tone(audioPin, ditfreq*2, 200);
   Serial.println("ct");
}



20  Forum 2005-2010 (read only) / Syntax & Programs / Re: Need help with interrupts on: June 24, 2010, 08:31:27 pm
I'm trying to modify the global variable - my intent was not to do locally scoped variables.  What do I need to do differently?


.. just drop the 'int' ?
21  Forum 2005-2010 (read only) / Syntax & Programs / Re: Need help with interrupts on: June 24, 2010, 08:01:06 pm
Is this more along the lines of what you were thinking for an interrupt-less version?

It doenst seem to be working though... like I'm stuck in the while loop. Should I change it to an if loop instead of a while loop?

Code:

/*
  ###########################################################
  #  Program: KC8OZA-ID - Open Source Repeater Controller   #
  #  Author: Josh Kittle, KC8OZA                            #
  #  Date: 06/2010                                          #
  #  Written for use on the Arduino Platform                #
  ###########################################################
*/



/*
    ######################################
    #  Includes and Variable Definitions #
    ######################################
*/

#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

int dahfreq = 600;
int ditfreq = 600;
int multi = 40;
int pttPin = 14;
int txActvLED = 4;
int txStbyLED = 5;
int audioPin = 6;                       // This pin is the audio output for CWID and Courtesy Tonet
int cosPin = 2;                          // COS Detect Pin
int waskeyed = 0;
int cosState;
char countertxt[3];
int original_id_timer = 300;
int cur_id_timer = original_id_timer;
int id_timer;
char cur_timetxt[5];

/*
    ##################
    #  Setup Routine #
    ##################
*/
    
void setup() {
Serial.begin(9600);
  // Define LCD Configuration Parameters
  
      lcd.begin(20, 4);  // Define the LED Size (4x20 LCD shown)
      
  
  // Display the initialization information on the LCD
 
      delay(3000);
      lcd.clear();
      lcd.setCursor(2, 0);
      lcd.print("KC8OZA  Repeater");
      lcd.setCursor(2, 2);
      lcd.print("Controller  Init");
 
 
  // Define Pin Modes
    
      pinMode(cosPin, INPUT);       // This is used for sensing COS activity
      pinMode(txActvLED, OUTPUT);  // This LED is lit when TXing
      pinMode(txStbyLED, OUTPUT);  // This LED is lit when not TXing
      pinMode(pttPin, OUTPUT);
  
      delay(3000);    
        digitalWrite(txStbyLED, HIGH);
        digitalWrite(txActvLED, LOW);
      
      cwid(); // ID the repeater on power-up
}

/*
    ##################
    #  Main Program  #
    ##################
*/

void loop() {
  Serial.println("Begin Loop Routine");
  lcd.clear();
  
  // Stuck in this loop while counting to do the ID
 cosState = digitalRead(cosPin);
 
if (cosState == 0)
{
  Key();

  int waskeyed = 1;
}
 
  else
  {
    if (waskeyed == 1)
    {
     Key();
     ct();
     unKey();  
}


  
  
  while (id_timer < cur_id_timer) {
  Serial.println("in the while loop");
   delay (1000);
    
    cur_id_timer = cur_id_timer - 1;
    itoa(cur_id_timer, cur_timetxt, 10);
    
    lcd.clear();
    lcd.setCursor(2, 0);
    lcd.print("KC8OZA  Repeater");
    lcd.setCursor(4, 2);
    lcd.print(cur_timetxt);
    lcd.print(" sec to ID");
    
   }
  
  // When the loop ends - run the ID
    Serial.println("Run CWID Routine");
  cwid();  // Timer Expired - ID the repeater

}
}

/*
    ##################
    #  CWID Routine  #
    ##################
*/

void cwid()
{
  Serial.println("running cwid");
  lcd.clear();
  lcd.setCursor(2, 0);
  lcd.print("KC8OZA  Repeater");
  lcd.setCursor(3, 2);
  lcd.print("ID In Progress");
    
  Key();
  
  dah();
  dit();
  dah();
  letterspace();  // K
  dah();
  dit();
  dah();
  dit();
  letterspace(); // C
  dah();
  dah();
  dah();
  dit();
  dit();
  letterspace(); // 8
  dah();
  dah();
  dah();
  letterspace(); //O
  dah();
  dah();
  dit();
  dit();
  letterspace(); // Z
  dit();
  dah();
  letterspace(); // A

  unKey();
  
cur_id_timer = original_id_timer;


}


/*
    ##################
    #  CW Routines   #
    ##################
*/

void dit()
{
  delay(1*multi);
  //digitalWrite(txPin, HIGH);
  tone(audioPin, ditfreq);
  delay(1*multi);
  noTone(audioPin);
  //delay(75);
  //tone(txPin, freq, 225);
}

void dah()
{
  delay(1*multi);
  //digitalWrite(txPin, HIGH);
  tone(audioPin, dahfreq);
  delay(3*multi);
  noTone(audioPin);
  //digitalWrite(txPin, LOW);
  //tone(txPin, freq, 225);
}

void letterspace()
{
  delay(2*multi);
}


void unKey()
{
  digitalWrite(txStbyLED, HIGH);
  digitalWrite(txActvLED, LOW);
  digitalWrite(pttPin, LOW); // Ensure the transmitter is not keyed by forcing the pin LOW (use pulldown instead??)
  Serial.println("unKey");
}

void Key()
{
  digitalWrite(txStbyLED, LOW);
  digitalWrite(txActvLED, HIGH);
  digitalWrite(pttPin, HIGH); // Ensure the transmitter is keyed by forcing the pin HIGH
  Serial.println("Key");
}

void ct()
{
   tone(audioPin, ditfreq*2, 200);
}




22  Forum 2005-2010 (read only) / Syntax & Programs / Re: Need help with interrupts on: June 24, 2010, 07:13:26 pm
I'm no beginner. I've been writing really bad code for 20 years. Ask anybody who's ever seen it smiley  It takes years of practice to write code as awfully as some of mine has been  smiley  

lol.
23  Forum 2005-2010 (read only) / Syntax & Programs / Re: Need help with interrupts on: June 24, 2010, 06:57:56 pm
lol. my brain is hurting trying to do that heheh. But yeah thats what I'm doing now. Figured Id open it up to comments anyway. Like 'hey dummy, you're making this harder than it has to be'. lol smiley
24  Forum 2005-2010 (read only) / Syntax & Programs / Re: Need help with interrupts on: June 24, 2010, 06:49:06 pm
Still trying to sort out the number of states.....

Heres where my brain is.

I think I need a 'tx mode',  'rx mode with beep', and 'rx mode no beep'

Because In the loop, I guess its going to detect 'do I need to turn on the transmitter (due to interrupt), its going to detect 'do I need to drop the transmitter and beep (because somebdoy talked), or 'do I need to keep the transmitter dropped, but not beep???

Thoughts? Confusing myself. lol.
25  Forum 2005-2010 (read only) / Syntax & Programs / Re: Need help with interrupts on: June 24, 2010, 06:31:48 pm
If I understand the question - I'm fine with the CWID taking place 'over top' or while the interrupt is triggered, yes. I may want to make that more intelligent later, but right now, at this stage, I'm just going for basic functionality.

'Trying' to walk before I run, anyway.
26  Forum 2005-2010 (read only) / Syntax & Programs / Re: Need help with interrupts on: June 24, 2010, 06:07:53 pm
Nodding head... Understood.  Will rethink this one this evening and see where I can get with it.

Trying to figure out if I need to represent 2 states or 3..... Obviously there is a  'did somebody just talk = yes' state, and a 'did somebody just talk = no' state.... my brain is thinking there is a third combination somewhere... Will see where my creativity leads tonight. I'm really stinking close.

27  Forum 2005-2010 (read only) / Syntax & Programs / Re: Need help with interrupts on: June 23, 2010, 09:26:18 pm
Well, I've made some progress. Still a few kinks, but very close.

To give a little better information for those who might be reading this who aren't 'hams' - the purpose of this device is simple - to provide a logic interface between a transmitter and a receiver, providing for the machine to identify itself via morse code every 10 minutes, to provide for sensing of an interrupt to determine when to key a transmitter, and to provide for sensing of 'end of transmission' to play a 'roger beep' or 'courtesy tone'.

I've got interrupts working, and basic functionality pretty much doing what i want - but it seems like something is unstable. Triggering interrupts is generating the beep I want, but currently not keying the transmitter ( I think I can find that problem) but seems to 'rapidly change state' in the beginning - and then settle to a stable state. Sort of what you'd see with a switch needing debouncing. Do I need that sort of logic here?


I want it to do this

....while loop.. ID every 10 minutes.

When interrupt = CHANGE (falling) trip a ptt relay and hold it open.
When interrupt = CHANGE (rising) close the ptt relay and play a beep.

DO you guys see a simpler way to code this?

Current code - for those interested in how this is evolving.

Code:
/*
  ###########################################################
  #  Program: KC8OZA-ID - Open Source Repeater Controller   #
  #  Author: Josh Kittle, KC8OZA                            #
  #  Date: 06/2010                                          #
  #  Written for use on the Arduino Platform                #
  ###########################################################
*/



/*
    ######################################
    #  Includes and Variable Definitions #
    ######################################
*/

#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

int dahfreq = 600;
int ditfreq = 600;
int multi = 40;
int pttPin = 14;
int txActvLED = 4;
int txStbyLED = 5;
int audioPin = 6;                       // This pin is the audio output for CWID and Courtesy Tonet
int cosPin = 2;                         // Only pins 2 and 3 can be used for interrupts, so we will use pin 2
volatile int cosState = HIGH ;      // The value for this variable is ready from memory so you need to define it as volatile
volatile int pttState = 0;
int InterruptState;
char countertxt[3];
int original_id_timer = 300;
int cur_id_timer = original_id_timer;
int id_timer;
char cur_timetxt[5];

/*
    ##################
    #  Setup Routine #
    ##################
*/
    
void setup() {
Serial.begin(9600);
  // Define LCD Configuration Parameters
  
      lcd.begin(20, 4);  // Define the LED Size (4x20 LCD shown)

  // Configure the Interrupt for COS
  
      attachInterrupt(1, pttEval, CHANGE);
      interrupts();
      
  
  // Display the initialization information on the LCD
 
      delay(3000);
      lcd.clear();
      lcd.setCursor(2, 0);
      lcd.print("KC8OZA  Repeater");
      lcd.setCursor(2, 2);
      lcd.print("Controller  Init");
 
 
  // Define Pin Modes
    
      pinMode(cosPin, INPUT);       // This is used for sensing COS activity
      pinMode(txActvLED, OUTPUT);  // This LED is lit when TXing
      pinMode(txStbyLED, OUTPUT);  // This LED is lit when not TXing
      pinMode(pttPin, OUTPUT);
  
      delay(3000);    
      
      cwid(); // ID the repeater on power-up
}

/*
    ##################
    #  Main Program  #
    ##################
*/

void loop() {
  Serial.println("Begin Loop Routine");
  digitalWrite(txStbyLED, HIGH);
  digitalWrite(txActvLED, LOW);
  digitalWrite(pttPin, LOW); // Ensure the transmitter is not keyed by forcing the pin LOW (use pulldown instead??)
  lcd.clear();
  
  // Stuck in this loop while counting to do the ID
  
  while (id_timer < cur_id_timer) {
  Serial.println("in the while loop");
   delay (1000);
    
    cur_id_timer = cur_id_timer - 1;
    itoa(cur_id_timer, cur_timetxt, 10);
    
    lcd.clear();
    lcd.setCursor(2, 0);
    lcd.print("KC8OZA  Repeater");
    lcd.setCursor(4, 2);
    lcd.print(cur_timetxt);
    lcd.print(" sec to ID");
    
   }
  
  // When the loop ends - run the ID
    Serial.println("Run CWID Routine");
  cwid();  // Timer Expired - ID the repeater

}

/*
    ##################
    #  CWID Routine  #
    ##################
*/

void cwid()
{
  Serial.println("running cwid");
  lcd.clear();
  lcd.setCursor(2, 0);
  lcd.print("KC8OZA  Repeater");
  lcd.setCursor(3, 2);
  lcd.print("ID In Progress");
    
  pttClose();
  
  dah();
  dit();
  dah();
  letterspace();  // K
  dah();
  dit();
  dah();
  dit();
  letterspace(); // C
  dah();
  dah();
  dah();
  dit();
  dit();
  letterspace(); // 8
  dah();
  dah();
  dah();
  letterspace(); //O
  dah();
  dah();
  dit();
  dit();
  letterspace(); // Z
  dit();
  dah();
  letterspace(); // A

  pttOpen();
cur_id_timer = original_id_timer;


}


/*
    ######################
    #  PTT Relay Routine #
    ######################
*/

void pttEval() // Evaluate PTT State
{
InterruptState = digitalRead(cosPin);

if (InterruptState == HIGH)

{
  pttOpen();
}
else {
  
  pttClose();
 
}
}



void pttClose() // This is used to close the PTT relay (trigger PTT)
{
 Serial.println("pttClose Routine");
 // Change the LED state to indicate active TX
 
  digitalWrite(txStbyLED, LOW);
  digitalWrite(txActvLED, HIGH);
 
 // Trigger the PTT Relay ON
 
  int pttState =     1;
Serial.println("PTT State 1");
  digitalWrite(pttPin, HIGH);
 
 }


void pttOpen() // This is used to open the PTT relay (drop the PTT signal)
{
  Serial.println("pttOpen Routine");
  tone(audioPin, ditfreq*2, 400); // This is our courtesy tone
  
  digitalWrite(txStbyLED, HIGH);
  digitalWrite(txActvLED, LOW);
  
  // Trigger the PTT Relay OFF
  
  int pttState = 0;
  Serial.println("PTT State 0");
  digitalWrite(pttPin, LOW);

}

/*
    ##################
    #  CW Routines   #
    ##################
*/

void dit()
{
  delay(1*multi);
  //digitalWrite(txPin, HIGH);
  tone(audioPin, ditfreq);
  delay(1*multi);
  noTone(audioPin);
  //delay(75);
  //tone(txPin, freq, 225);
}

void dah()
{
  delay(1*multi);
  //digitalWrite(txPin, HIGH);
  tone(audioPin, dahfreq);
  delay(3*multi);
  noTone(audioPin);
  //digitalWrite(txPin, LOW);
  //tone(txPin, freq, 225);
}

void letterspace()
{
  delay(2*multi);
}




28  Forum 2005-2010 (read only) / Syntax & Programs / Re: Need help with interrupts on: June 20, 2010, 07:25:25 pm
Ok I think I'm really close here.

I've made the following changes - the system boots, runs an initial cwid(), and goes into the while loop.... starting the countdown timer.

As the timer expires, the id plays and PTT does what it's supposed to.

But... it get stuck in a loop and keeps executing the cwid() over and over.  Gotta be a simple error in the variable state - care to peek for a second set of eyes?

/*
  ###########################################################
  #  Program: KC8OZA-ID - Open Source Repeater Controller   #
  #  Author: Josh Kittle, KC8OZA                            #
  #  Date: 06/2010                                          #
  #  Written for use on the Arduino Platform                #
  ###########################################################
*/



/*
    ######################################
    #  Includes and Variable Definitions #
    ######################################
*/

#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
int dahfreq = 600;
int ditfreq = 600;
int multi = 40;
int pttPin = 14;
int txActvLED = 4;
int txStbyLED = 5;
int audioPin = 6;                       // This pin is the audio output for CWID and Courtesy Tonet
int cosPin = 2;                         // Only pins 2 and 3 can be used for interrupts, so we will use pin 2
volatile int cosState = HIGH ;      // The value for this variable is ready from memory so you need to define it as volatile
volatile int pttState = 0;
char countertxt[3];
int cur_id_timer = 20;
int id_timer;
char cur_timetxt[5];

/*
    ##################
    #  Setup Routine #
    ##################
*/
    
void setup() {

  // Define LCD Configuration Parameters
  
      lcd.begin(20, 4);  // Define the LED Size (4x20 LCD shown)

  // Configure the Interrupt for COS
  
      attachInterrupt(1, pttEval, CHANGE);
      interrupts();
      
  
  // Display the initialization information on the LCD
 
      delay(3000);
      lcd.clear();
      lcd.setCursor(2, 0);
      lcd.print("KC8OZA  Repeater");
      lcd.setCursor(2, 2);
      lcd.print("Controller  Init");
 
 
  // Define Pin Modes
    
      pinMode(cosPin, INPUT);       // This is used for sensing COS activity
      pinMode(txActvLED, OUTPUT);  // This LED is lit when TXing
      pinMode(txStbyLED, OUTPUT);  // This LED is lit when not TXing
      pinMode(pttPin, OUTPUT);
  
      delay(3000);    
      
      cwid(); // ID the repeater on power-up
}

/*
    ##################
    #  Main Program  #
    ##################
*/

void loop() {
  digitalWrite(txStbyLED, HIGH);
  digitalWrite(txActvLED, LOW);
 
  digitalWrite(pttPin, LOW); // Ensure the transmitter is not keyed by forcing the pin LOW (use pulldown instead??)
  
  
//  digitalWrite(cosPin, cosState);

  lcd.clear();
  
  if (pttState == 0){
 
  while (id_timer < cur_id_timer) {
  
   delay (1000);
    
    cur_id_timer = cur_id_timer - 1;
    itoa(cur_id_timer, cur_timetxt, 10);
    
    lcd.clear();
    lcd.setCursor(2, 0);
    lcd.print("KC8OZA  Repeater");
    lcd.setCursor(4, 2);
    lcd.print(cur_timetxt);
    lcd.print(" sec to ID");
  }    
  }
  else
  {
   pttOpen();
  
   }
  
  

  
    lcd.clear();
    lcd.setCursor(2, 0);
    lcd.print("KC8OZA  Repeater");
    lcd.setCursor(3, 2);
    lcd.print("ID In Progress");
    
  cwid();  // Timer Expired - ID the repeater

}

/*
    ##################
    #  CWID Routine  #
    ##################
*/

void cwid()
{
  pttClose();
  
  dah();
  dit();
  dah();
  letterspace();  // K
  dah();
  dit();
  dah();
  dit();
  letterspace(); // C
  dah();
  dah();
  dah();
  dit();
  dit();
  letterspace(); // 8
  dah();
  dah();
  dah();
  letterspace(); //O
  dah();
  dah();
  dit();
  dit();
  letterspace(); // Z
  dit();
  dah();
  letterspace(); // A

  pttOpen();

}


/*
    ######################
    #  PTT Relay Routine #
    ######################
*/

void pttEval() // Evaluate PTT State
{
  if (pttState == 0)

{
  pttClose();
}
  
  else
 {
 
   pttOpen();

 }
}

void pttClose() // This is used to close the PTT relay (trigger PTT)
{
  
 // Change the LED state to indicate active TX
 
  digitalWrite(txStbyLED, LOW);
  digitalWrite(txActvLED, HIGH);
 
 // Trigger the PTT Relay ON
 
  pttState = 1;

  digitalWrite(pttPin, HIGH);
 
 }


void pttOpen() // This is used to open the PTT relay (drop the PTT signal)
{
  tone(audioPin, ditfreq*2, 200); // This is our courtesy tone
  
  digitalWrite(txStbyLED, HIGH);
  digitalWrite(txActvLED, LOW);
  
  // Trigger the PTT Relay OFF
  
  pttState = 0;
  
  digitalWrite(pttPin, LOW);

}

/*
    ##################
    #  CW Routines   #
    ##################
*/

void dit()
{
  delay(1*multi);
  //digitalWrite(txPin, HIGH);
  tone(audioPin, ditfreq);
  delay(1*multi);
  noTone(audioPin);
  //delay(75);
  //tone(txPin, freq, 225);
}

void dah()
{
  delay(1*multi);
  //digitalWrite(txPin, HIGH);
  tone(audioPin, dahfreq);
  delay(3*multi);
  noTone(audioPin);
  //digitalWrite(txPin, LOW);
  //tone(txPin, freq, 225);
}

void letterspace()
{
  delay(2*multi);
}




29  Forum 2005-2010 (read only) / Syntax & Programs / Re: Need help with interrupts on: June 20, 2010, 06:56:09 pm
Thanks for the clarification. I was definitely screwed up smiley
I'm doing external pullups, so I'm not intending to use the internal ones.

The inconsistancy in the interrupt is because ... I changed which pin I was using, got things a little out of sync there.

I'm rewriting some code now - breaking the ptt routine into two separate routes... a 'close relay' routine, and an 'open relay' routine. This seems to make more sense than doing ct() elsewhere - since every time I open the relay I want to play the tone - so why not just code it that way - I figure.

A little variable magic here, and some tweaking, I think I'll be ready to connect the arduino and test.

I LOVE this Arduino smiley


30  Forum 2005-2010 (read only) / Syntax & Programs / Re: Need help with interrupts on: June 20, 2010, 06:17:06 pm
Hmm.

So does that mean that I don't really need the following code in my sketch?

int cosPin = 2;                         // Only pins 2 and 3 can be used for interrupts, so we will use pin 2

and

 digitalWrite(cosPin, cosState);


... the cospin is being used as an input.  I think I misunderstood how the example code was working.
Pages: 1 [2] 3