Reaction Wheel Actuated Satellite Dynamics Test Platform

Dependencies:   mbed

Diploma Thesis in Aerospace Engineering, January 2014

University of Applied Sciences Munich, Faculty 03

Electronics:

  • 1x mbed NXP LPC 1768 Microcontroller
  • 2x XBee S1 Radios + Sparkfun USB Adapter
  • 1x CHR UM6-lt IMU
  • 4x Graupner BEC 8 Motor Controllers
  • 4x ROXXY 2826/09 Brushless Motors
  • 1x Hacker TopFuel LiPo 1300mAh Battery
  • 1x big Selfmade BreakOutBoard to connect all components
  • 1x small BreakOutBoard to connect IMU

Hardware developed with Catia V5R20

Manufactoring Technology: Rapid Prototyping - EOS Formiga P110

Controlled via text based menu with DockLight

__________________

Committer:
DimitriGruebel
Date:
Wed Jul 09 07:35:50 2014 +0000
Revision:
0:1447d2f773db
Dynamics Test Platform

Who changed what in which revision?

UserRevisionLine numberNew contents of line
DimitriGruebel 0:1447d2f773db 1 #ifdef COMPILE_EXAMPLE_CODE_MODSERIAL_MODDMA
DimitriGruebel 0:1447d2f773db 2
DimitriGruebel 0:1447d2f773db 3 /*
DimitriGruebel 0:1447d2f773db 4 * To run this test program, link p9 to p10 so the Serial loops
DimitriGruebel 0:1447d2f773db 5 * back and receives characters it sends.
DimitriGruebel 0:1447d2f773db 6 */
DimitriGruebel 0:1447d2f773db 7
DimitriGruebel 0:1447d2f773db 8 #include "mbed.h"
DimitriGruebel 0:1447d2f773db 9
DimitriGruebel 0:1447d2f773db 10 /* Note, this example requires that you also import into the Mbed
DimitriGruebel 0:1447d2f773db 11 compiler the MODDMA project as well as MODSERIAL
DimitriGruebel 0:1447d2f773db 12 http://mbed.org/users/AjK/libraries/MODDMA/latest
DimitriGruebel 0:1447d2f773db 13 MODDMA.h MUST come before MODSERIAL.h */
DimitriGruebel 0:1447d2f773db 14 #include "MODDMA.h" // <--- Declare first
DimitriGruebel 0:1447d2f773db 15 #include "MODSERIAL.h" // Flollowed by MODSERIAL
DimitriGruebel 0:1447d2f773db 16
DimitriGruebel 0:1447d2f773db 17 DigitalOut led1(LED1);
DimitriGruebel 0:1447d2f773db 18 DigitalOut led2(LED2);
DimitriGruebel 0:1447d2f773db 19 DigitalOut led3(LED3);
DimitriGruebel 0:1447d2f773db 20 DigitalOut led4(LED4);
DimitriGruebel 0:1447d2f773db 21
DimitriGruebel 0:1447d2f773db 22 MODSERIAL pc(USBTX, USBRX);
DimitriGruebel 0:1447d2f773db 23
DimitriGruebel 0:1447d2f773db 24 /*
DimitriGruebel 0:1447d2f773db 25 * As experiement, you can define MODSERIAL as show here and see what
DimitriGruebel 0:1447d2f773db 26 * effects it has on the LEDs.
DimitriGruebel 0:1447d2f773db 27 *
DimitriGruebel 0:1447d2f773db 28 * MODSERIAL uart(TX_PIN, RX_PIN, 512);
DimitriGruebel 0:1447d2f773db 29 * With this, the 512 characters sent can straight into the buffer
DimitriGruebel 0:1447d2f773db 30 * vary quickly. This means LED1 is only on briefly as the TX buffer
DimitriGruebel 0:1447d2f773db 31 * fills.
DimitriGruebel 0:1447d2f773db 32 *
DimitriGruebel 0:1447d2f773db 33 * MODSERIAL uart(TX_PIN, RX_PIN, 32);
DimitriGruebel 0:1447d2f773db 34 * With this, the buffer is smaller than the default 256 bytes and
DimitriGruebel 0:1447d2f773db 35 * therefore LED1 stays on much longer while the system waits for
DimitriGruebel 0:1447d2f773db 36 * room in the TX buffer.
DimitriGruebel 0:1447d2f773db 37 */
DimitriGruebel 0:1447d2f773db 38 MODSERIAL uart(TX_PIN, RX_PIN);
DimitriGruebel 0:1447d2f773db 39
DimitriGruebel 0:1447d2f773db 40 MODDMA dma;
DimitriGruebel 0:1447d2f773db 41
DimitriGruebel 0:1447d2f773db 42 // This function is called when a character goes from the TX buffer
DimitriGruebel 0:1447d2f773db 43 // to the Uart THR FIFO register.
DimitriGruebel 0:1447d2f773db 44 void txCallback(void) {
DimitriGruebel 0:1447d2f773db 45 led2 = !led2;
DimitriGruebel 0:1447d2f773db 46 }
DimitriGruebel 0:1447d2f773db 47
DimitriGruebel 0:1447d2f773db 48 // This function is called when TX buffer goes empty
DimitriGruebel 0:1447d2f773db 49 void txEmpty(void) {
DimitriGruebel 0:1447d2f773db 50 led2 = 0;
DimitriGruebel 0:1447d2f773db 51 pc.puts(" Done. ");
DimitriGruebel 0:1447d2f773db 52 }
DimitriGruebel 0:1447d2f773db 53
DimitriGruebel 0:1447d2f773db 54 void dmaComplete(void) {
DimitriGruebel 0:1447d2f773db 55 led1 = 1;
DimitriGruebel 0:1447d2f773db 56 }
DimitriGruebel 0:1447d2f773db 57
DimitriGruebel 0:1447d2f773db 58 // This function is called when a character goes into the RX buffer.
DimitriGruebel 0:1447d2f773db 59 void rxCallback(void) {
DimitriGruebel 0:1447d2f773db 60 led3 = !led3;
DimitriGruebel 0:1447d2f773db 61 pc.putc(uart.getc());
DimitriGruebel 0:1447d2f773db 62 }
DimitriGruebel 0:1447d2f773db 63
DimitriGruebel 0:1447d2f773db 64 int main() {
DimitriGruebel 0:1447d2f773db 65 char s1[] = " *DMA* *DMA* *DMA* *DMA* *DMA* *DMA* *DMA* ";
DimitriGruebel 0:1447d2f773db 66 int c = 'A';
DimitriGruebel 0:1447d2f773db 67
DimitriGruebel 0:1447d2f773db 68 // Tell MODSERIAL where the MODDMA controller is.
DimitriGruebel 0:1447d2f773db 69 pc.MODDMA( &dma );
DimitriGruebel 0:1447d2f773db 70
DimitriGruebel 0:1447d2f773db 71 // Ensure the baud rate for the PC "USB" serial is much
DimitriGruebel 0:1447d2f773db 72 // higher than "uart" baud rate below.
DimitriGruebel 0:1447d2f773db 73 pc.baud( PC_BAUD );
DimitriGruebel 0:1447d2f773db 74
DimitriGruebel 0:1447d2f773db 75 // Use a deliberatly slow baud to fill up the TX buffer
DimitriGruebel 0:1447d2f773db 76 uart.baud(1200);
DimitriGruebel 0:1447d2f773db 77
DimitriGruebel 0:1447d2f773db 78 uart.attach( &txCallback, MODSERIAL::TxIrq );
DimitriGruebel 0:1447d2f773db 79 uart.attach( &rxCallback, MODSERIAL::RxIrq );
DimitriGruebel 0:1447d2f773db 80 uart.attach( &txEmpty, MODSERIAL::TxEmpty );
DimitriGruebel 0:1447d2f773db 81
DimitriGruebel 0:1447d2f773db 82 // Loop sending characters. We send 512
DimitriGruebel 0:1447d2f773db 83 // which is twice the default TX/RX buffer size.
DimitriGruebel 0:1447d2f773db 84
DimitriGruebel 0:1447d2f773db 85 led1 = 0;
DimitriGruebel 0:1447d2f773db 86
DimitriGruebel 0:1447d2f773db 87 // Send the buffer s using DMA channel 7
DimitriGruebel 0:1447d2f773db 88 pc.attach_dmaSendComplete( &dmaComplete );
DimitriGruebel 0:1447d2f773db 89 pc.dmaSend( s1, sizeof(s1), MODDMA::Channel_7 );
DimitriGruebel 0:1447d2f773db 90
DimitriGruebel 0:1447d2f773db 91 for (int loop = 0; loop < 512; loop++) {
DimitriGruebel 0:1447d2f773db 92 uart.printf("%c", c);
DimitriGruebel 0:1447d2f773db 93 c++;
DimitriGruebel 0:1447d2f773db 94 if (c > 'Z') c = 'A';
DimitriGruebel 0:1447d2f773db 95 }
DimitriGruebel 0:1447d2f773db 96
DimitriGruebel 0:1447d2f773db 97 led1 = 0; // Show the end of sending by switching off LED1.
DimitriGruebel 0:1447d2f773db 98
DimitriGruebel 0:1447d2f773db 99 // End program. Flash LED4. Notice how LED 2 and 3 continue
DimitriGruebel 0:1447d2f773db 100 // to flash for a short period while the interrupt system
DimitriGruebel 0:1447d2f773db 101 // continues to send the characters left in the TX buffer.
DimitriGruebel 0:1447d2f773db 102
DimitriGruebel 0:1447d2f773db 103 while(1) {
DimitriGruebel 0:1447d2f773db 104 led4 = !led4;
DimitriGruebel 0:1447d2f773db 105 wait(0.25);
DimitriGruebel 0:1447d2f773db 106 }
DimitriGruebel 0:1447d2f773db 107 }
DimitriGruebel 0:1447d2f773db 108
DimitriGruebel 0:1447d2f773db 109 /*
DimitriGruebel 0:1447d2f773db 110 * Notes. Here is the sort of output you can expect on your PC/Mac/Linux host
DimitriGruebel 0:1447d2f773db 111 * machine that is connected to the "pc" USB serial port.
DimitriGruebel 0:1447d2f773db 112 *
DimitriGruebel 0:1447d2f773db 113 * *DMA* *DMA* *DMA* *DMA* *DMA* *DMA* *DMA* ABCDEFGHIJKLMNOPQRSTUVWXYZABCDE
DimitriGruebel 0:1447d2f773db 114 * FGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZA
DimitriGruebel 0:1447d2f773db 115 * BCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVW
DimitriGruebel 0:1447d2f773db 116 * XYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRS
DimitriGruebel 0:1447d2f773db 117 * TUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNO
DimitriGruebel 0:1447d2f773db 118 * PQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJK
DimitriGruebel 0:1447d2f773db 119 * LMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFG
DimitriGruebel 0:1447d2f773db 120 * HIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQ Done. R
DimitriGruebel 0:1447d2f773db 121 *
DimitriGruebel 0:1447d2f773db 122 * Note how the DMA blocks the TX buffer sending under standard interrupt control.
DimitriGruebel 0:1447d2f773db 123 * Not until the DMA transfer is complete will "normal" buffered TX sending resume.
DimitriGruebel 0:1447d2f773db 124 *
DimitriGruebel 0:1447d2f773db 125 * Of interest is that last "R" character after the system has said "Done."
DimitriGruebel 0:1447d2f773db 126 * This comes from the fact that the TxEmpty callback is made when the TX buffer
DimitriGruebel 0:1447d2f773db 127 * becomes empty. MODSERIAL makes use of the fact that the Uarts built into the
DimitriGruebel 0:1447d2f773db 128 * LPC17xx device use a 16 byte FIFO on both RX and TX channels. This means that
DimitriGruebel 0:1447d2f773db 129 * when the TxEmpty callback is made, the TX buffer is empty, but that just means
DimitriGruebel 0:1447d2f773db 130 * the "last few characters" were written to the TX FIFO. So although the TX
DimitriGruebel 0:1447d2f773db 131 * buffer has gone empty, the Uart's transmit system is still sending any remaining
DimitriGruebel 0:1447d2f773db 132 * characters from it's TX FIFO. If you want to be truely sure all the characters
DimitriGruebel 0:1447d2f773db 133 * you have sent have left the Mbed then call txIsBusy(); This function will
DimitriGruebel 0:1447d2f773db 134 * return true if characters are still being sent. If it returns false after
DimitriGruebel 0:1447d2f773db 135 * the Tx buffer is empty then all your characters have been sent.
DimitriGruebel 0:1447d2f773db 136 *
DimitriGruebel 0:1447d2f773db 137 * In a similar way, when characters are received into the RX FIFO, the entire
DimitriGruebel 0:1447d2f773db 138 * FIFO contents is moved to the RX buffer, assuming there is room left in the
DimitriGruebel 0:1447d2f773db 139 * RX buffer. If there is not, any remaining characters are left in the RX FIFO
DimitriGruebel 0:1447d2f773db 140 * and will be moved to the RX buffer on the next interrupt or when the running
DimitriGruebel 0:1447d2f773db 141 * program removes a character(s) from the RX buffer with the getc() method.
DimitriGruebel 0:1447d2f773db 142 */
DimitriGruebel 0:1447d2f773db 143
DimitriGruebel 0:1447d2f773db 144 #endif