UKHAS Wiki

UK High Altitude Society

User Tools

Site Tools


guides:interrupt_driven_rtty

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
guides:interrupt_driven_rtty [2014/04/12 13:40] ibanezmatt13guides:interrupt_driven_rtty [2015/02/03 13:43] (current) danielrichman
Line 4: Line 4:
  
  
-{{ :guides:881951_721113604583622_1292041006_o.jpg?700x500 }}+{{ :guides:881951_721113604583622_1292041006_o.jpg?700x500 | NORB 3 tracker PCB }}
  
  
Line 10: Line 10:
 Interrupts work by doing exactly what they say on the tin, they interrupt the running program to do something, before allowing the main program to continue on its way. This means that instead of waiting for an instruction to be executed before moving on to the next step, the main program can be doing something useful, and the interrupt will intervene when necessary to execute the instruction in question. Interrupts work by doing exactly what they say on the tin, they interrupt the running program to do something, before allowing the main program to continue on its way. This means that instead of waiting for an instruction to be executed before moving on to the next step, the main program can be doing something useful, and the interrupt will intervene when necessary to execute the instruction in question.
  
-There are many types of interrupt, and each type can be triggered in a certain way, details of which can be found in the interrupt vectors section of any AVR datasheet. An interrupt can be triggered by a pin being pulled low, or perhaps each time an external oscillator ticks, or by many other ways that can be found in the datasheet. In this example, we will be focusing on using a software based timer interrupt using the popular ATMEGA328P, a chip used on many Arduino platforms. I will assume prior knowledge of the RTTY (radio teletype) radio mode.+There are many types of interrupt, and each type can be triggered in a certain way, details of which can be found in the interrupt vectors section of any AVR datasheet. An interrupt can be triggered by a pin being pulled low, or perhaps each time an external oscillator ticks, or in many other ways that are described in the datasheet. In this example, we will be focusing on using a software based timer interrupt using the popular ATMEGA328P, a chip used on many Arduino platforms. I will assume prior knowledge of the RTTY (radio teletype) radio mode. 
 + 
  
  
Line 52: Line 54:
           sentence_needed = false;           sentence_needed = false;
           digitalWrite(LED_1, LOW);           digitalWrite(LED_1, LOW);
 +          // warning! The lack of "break" in this branch means that we
 +          // fall through to "case 1" immediately, in order to start
 +          // sending the start bit.
         }         }
         else {         else {
Line 133: Line 138:
 void loop() void loop()
 { {
 + // for you to have a play with ;-)
 } }
    
Line 140: Line 146:
 Firstly, you must understand that we are using 7 bit ASCII. ASCII is one of the common ways of encoding all the 128 characters we typically use. It gives each character a value which is comprised of so many bits. There’s 7 bit ASCII and 8 bit ASCII, though here we’ll be using 7 bit ASCII. So you understand now that the radio transmitter must transmit each bit at a time. Firstly, you must understand that we are using 7 bit ASCII. ASCII is one of the common ways of encoding all the 128 characters we typically use. It gives each character a value which is comprised of so many bits. There’s 7 bit ASCII and 8 bit ASCII, though here we’ll be using 7 bit ASCII. So you understand now that the radio transmitter must transmit each bit at a time.
  
-If the interrupt fires every 20ms, you will understand that we can’t possibly send more than one bit per routine as this would just register as a longer bit, making no sense to the way in which RTTY works. This means that we will have different conditions in which the routine will operate differently. We can mark each condition by having a status variable which will change depending on when the condition for transmission needs to be updated. Above, this variable is marked tx_status, and it’s different conditions are described below:+If the interrupt fires every 20ms, you will understand that we can’t possibly send more than one bit per routine as this would just register as a longer bit, making no sense to the way in which RTTY works. This means that we will have different conditions in which the routine will operate differently. We can mark each condition by having a status variable which will change depending on when the condition for transmission needs to be updated. Above, this variable is marked tx_status, and its different conditions are described below:
  
  
Line 146: Line 152:
 **//tx_status = 0:// ** **//tx_status = 0:// **
  
-The way in which this code works is that when a new sentence is required by the ISR, the sentence_needed Boolean is changed to true. This informs the running program that if this is the case, a new sentence is stored in a buffer which the ISR will be searching through. At this time also, a pointer is initialized in the line ptr = send_datastring. This pointer will point to the location of the first character in the buffer which will be used each time the ISR tries to find a new character. If the pointer happens to be valid and a character is present, the status is updated to 1 so that upon the next calling of the ISR, the sentence can begin to be transmitted.+The way in which this code works is that when a new sentence is required by the ISR, the sentence_needed Boolean is changed to true. This informs the running program that if this is the case, a new sentence is stored in a buffer which the ISR will be searching through. At this time also, a pointer is initialized in the line ptr = send_datastring (a clue for the creation of your own loop function). This pointer will point to the location of the first character in the buffer which will be used each time the ISR tries to find a new character. If the pointer happens to be valid and a character is present, the status is updated to 1 so that upon the next calling of the ISR, the sentence can begin to be transmitted.
  
  
Line 162: Line 168:
 This is the normal transmission condition where each bit is sent consecutively until there are no more left to send. The line rtty_txbit(currentbyte & 1); transmits the current bit of the byte. After doing this, it then checks to see if the bit it just sent was the last in the byte – in this case using 7 bit ASCII, it checks that the bit sent was the 7th bit. If so, the status is updated ready for sending the stop bits to complete transmission. If this is not the case however, the next bit needs to be sent. This is the normal transmission condition where each bit is sent consecutively until there are no more left to send. The line rtty_txbit(currentbyte & 1); transmits the current bit of the byte. After doing this, it then checks to see if the bit it just sent was the last in the byte – in this case using 7 bit ASCII, it checks that the bit sent was the 7th bit. If so, the status is updated ready for sending the stop bits to complete transmission. If this is not the case however, the next bit needs to be sent.
  
-RTTY works by sending the least significant bit first (LSB for short). If you imagine the byte 01100101, the LSB is the very last bit. If we had just sent this bit and wished to send the next bit, we need to in a way shift all the bit along 1 to the right so that the bit that was second to last is now the last and thus the LSB to be sent. This so called shift by 1 to the right is done with the line currentbyte = currentbyte >> 1. The currentbitcount is then incremented ready for the next triggering of the ISR.+RTTY works by sending the least significant bit first (LSB for short). If you imagine the byte 01100101, the LSB is the very last bit. If we had just sent this bit and wished to send the next bit, we need to in a way shift all the bits along 1 to the right so that the bit that was second to last is now the last and thus the LSB to be sent. This so called shift by 1 to the right is done with the line currentbyte = currentbyte >> 1. The currentbitcount is then incremented ready for the next triggering of the ISR.
  
  
Line 175: Line 181:
  
  
-And there you have it, one fully functional example of interrupt driven 50 baud RTTY, full explained. The code in this example of course is only a demonstration and is not a complete program in itself. However, it’s the little guides like this that make you stitch each piece of knowledge together into a structure so valuable and so close to you that, you’ll be far more satisfied with what you achieve in your HAB endeavors. Time I had a cup of tea and a biscuit, good luck!+And there you have it, one fully functional example of interrupt driven 50 baud RTTY, fully explained. The code in this example of course is only a demonstration and is not a complete program in itself. However, it’s the little guides like this that provide opportunity for you to stitch each piece of knowledge together into a structure that, in time, you’ll be far more satisfied with in your HAB endeavors. Time I had a cup of tea and a biscuit, good luck!
  
  
guides/interrupt_driven_rtty.1397310018.txt.gz · Last modified: 2014/04/12 13:40 by ibanezmatt13

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki