new fork sure

Dependencies:   HIDScope MODSERIAL PID QEI biquadFilter mbed

Fork of cpfromralph by Remi van Veen

Committer:
vsluiter
Date:
Tue Sep 23 18:56:14 2014 +0000
Revision:
13:18d4cef1fdb4
Parent:
11:ce72ec658a95
Child:
14:f83354387756
Changed comment to correct values...

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vsluiter 0:32bb76391d89 1 #include "mbed.h"
vsluiter 6:80c13d99aa55 2 #include "MODSERIAL.h"
vsluiter 11:ce72ec658a95 3 #include "HIDScope.h"
vsluiter 0:32bb76391d89 4
vsluiter 4:8b298dfada81 5 //Define objects
vsluiter 7:3396c3e33928 6 AnalogIn emg0(PTB1); //Analog input
ArvidKeemink 1:db54d9412d18 7 PwmOut red(LED_RED); //PWM output
vsluiter 8:8a17f65622b4 8 Ticker log_timer;
vsluiter 8:8a17f65622b4 9 MODSERIAL pc(USBTX,USBRX);
vsluiter 11:ce72ec658a95 10 HIDScope scope(2);
vsluiter 2:e314bb3b2d99 11
vsluiter 4:8b298dfada81 12 /** Looper function
vsluiter 4:8b298dfada81 13 * functions used for Ticker and Timeout should be of type void <name>(void)
vsluiter 4:8b298dfada81 14 * i.e. no input arguments, no output arguments.
vsluiter 4:8b298dfada81 15 * if you want to change a variable that you use in other places (for example in main)
vsluiter 4:8b298dfada81 16 * you will have to make that variable global in order to be able to reach it both from
vsluiter 4:8b298dfada81 17 * the function called at interrupt time, and in the main function.
vsluiter 4:8b298dfada81 18 * To make a variable global, define it under the includes.
vsluiter 4:8b298dfada81 19 * variables that are changed in the interrupt routine (written to) should be made
vsluiter 4:8b298dfada81 20 * 'volatile' to let the compiler know that those values may change outside the current context.
vsluiter 8:8a17f65622b4 21 * i.e.: "volatile uint16_t emg_value;" instead of "uint16_t emg_value"
vsluiter 4:8b298dfada81 22 * in the example below, the variable is not re-used in the main function, and is thus declared
vsluiter 4:8b298dfada81 23 * local in the looper function only.
vsluiter 4:8b298dfada81 24 **/
vsluiter 2:e314bb3b2d99 25 void looper()
vsluiter 2:e314bb3b2d99 26 {
vsluiter 4:8b298dfada81 27 /*variable to store value in*/
vsluiter 8:8a17f65622b4 28 uint16_t emg_value;
vsluiter 4:8b298dfada81 29 /*put raw emg value both in red and in emg_value*/
vsluiter 10:09b8424a7b39 30 red.write(emg0.read()); // read float value (0..1 = 0..3.3V)
vsluiter 8:8a17f65622b4 31 emg_value = emg0.read_u16(); // read direct ADC result (0..4096 = 0..3.3V)
vsluiter 8:8a17f65622b4 32 /*send value to PC. Line below is used to prevent buffer overrun */
vsluiter 6:80c13d99aa55 33 if(pc.rxBufferGetSize(0)-pc.rxBufferGetCount() > 30)
vsluiter 8:8a17f65622b4 34 pc.printf("%u\n",emg_value);
vsluiter 11:ce72ec658a95 35 scope.set(0,emg_value);
vsluiter 11:ce72ec658a95 36 scope.set(1,red.read());
vsluiter 11:ce72ec658a95 37 scope.send();
vsluiter 5:4dacb7b72109 38 /**When not using the LED, the above could also have been done this way:
vsluiter 8:8a17f65622b4 39 * pc.printf("%u\n", emg0.read_u16());
vsluiter 5:4dacb7b72109 40 */
vsluiter 2:e314bb3b2d99 41 }
vsluiter 0:32bb76391d89 42
vsluiter 0:32bb76391d89 43 int main()
vsluiter 0:32bb76391d89 44 {
vsluiter 4:8b298dfada81 45 /*setup baudrate. Choose the same in your program on PC side*/
vsluiter 2:e314bb3b2d99 46 pc.baud(115200);
vsluiter 4:8b298dfada81 47 /*set the period for the PWM to the red LED*/
vsluiter 2:e314bb3b2d99 48 red.period_ms(2);
vsluiter 4:8b298dfada81 49 /**Here you attach the 'void looper(void)' function to the Ticker object
vsluiter 9:d33e7b175ad7 50 * The looper() function will be called every 0.01 seconds.
vsluiter 4:8b298dfada81 51 * Please mind that the parentheses after looper are omitted when using attach.
vsluiter 4:8b298dfada81 52 */
vsluiter 13:18d4cef1fdb4 53 log_timer.attach(looper, 0.005);
ArvidKeemink 1:db54d9412d18 54 while(1) //Loop
vsluiter 0:32bb76391d89 55 {
vsluiter 4:8b298dfada81 56 /*Empty!*/
vsluiter 4:8b298dfada81 57 /*Everything is handled by the interrupt routine now!*/
vsluiter 0:32bb76391d89 58 }
vsluiter 0:32bb76391d89 59 }