Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed MODSERIAL telemetry-master
main.cpp@3:39e6440ccd45, 2015-05-05 (annotated)
- Committer:
- cheryl_he
- Date:
- Tue May 05 21:44:06 2015 +0000
- Revision:
- 3:39e6440ccd45
- Parent:
- 1:ff0fc50372c8
- Child:
- 4:8ee76f6d32b5
telemetry up
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| cheryl_he | 0:453d27750ab3 | 1 | #include "mbed.h" |
| cheryl_he | 1:ff0fc50372c8 | 2 | #include "telemetry.h" |
| cheryl_he | 1:ff0fc50372c8 | 3 | #include "telemetry-mbed.h" |
| cheryl_he | 3:39e6440ccd45 | 4 | #include "MODSERIAL.h" |
| cheryl_he | 1:ff0fc50372c8 | 5 | |
| cheryl_he | 3:39e6440ccd45 | 6 | #include "stdlib.h" |
| cheryl_he | 3:39e6440ccd45 | 7 | #include <vector> |
| cheryl_he | 3:39e6440ccd45 | 8 | |
| cheryl_he | 3:39e6440ccd45 | 9 | MODSERIAL telemetry_serial(USBTX, USBRX); |
| cheryl_he | 1:ff0fc50372c8 | 10 | telemetry::MbedHal telemetry_hal(telemetry_serial); |
| cheryl_he | 1:ff0fc50372c8 | 11 | telemetry::Telemetry telemetry_obj(telemetry_hal); |
| cheryl_he | 1:ff0fc50372c8 | 12 | |
| cheryl_he | 1:ff0fc50372c8 | 13 | telemetry::Numeric<uint32_t> tele_time_ms(telemetry_obj, "time", "Time", "ms", 0); |
| cheryl_he | 1:ff0fc50372c8 | 14 | telemetry::NumericArray<uint16_t, 128> tele_linescan(telemetry_obj, "linescan", "Linescan", "ADC", 0); |
| cheryl_he | 1:ff0fc50372c8 | 15 | telemetry::Numeric<float> tele_motor_pwm(telemetry_obj, "motor", "Motor PWM", "%DC", 0); |
| cheryl_he | 0:453d27750ab3 | 16 | |
| cheryl_he | 3:39e6440ccd45 | 17 | //Outputs |
| cheryl_he | 0:453d27750ab3 | 18 | DigitalOut myled(LED1); |
| cheryl_he | 3:39e6440ccd45 | 19 | DigitalOut clk(PTD5); |
| cheryl_he | 3:39e6440ccd45 | 20 | DigitalOut si(PTD4); |
| cheryl_he | 3:39e6440ccd45 | 21 | PwmOut motor1(PTA12); |
| cheryl_he | 3:39e6440ccd45 | 22 | PwmOut motor2(PTA4); |
| cheryl_he | 3:39e6440ccd45 | 23 | DigitalOut break1(PTC7); |
| cheryl_he | 3:39e6440ccd45 | 24 | DigitalOut break2(PTC0); |
| cheryl_he | 3:39e6440ccd45 | 25 | PwmOut servo(PTA5); |
| cheryl_he | 3:39e6440ccd45 | 26 | |
| cheryl_he | 3:39e6440ccd45 | 27 | //Serial pc(USBTX, USBRX); // tx, rx |
| cheryl_he | 3:39e6440ccd45 | 28 | |
| cheryl_he | 3:39e6440ccd45 | 29 | //Inputs |
| cheryl_he | 3:39e6440ccd45 | 30 | AnalogIn camData(PTC2); |
| cheryl_he | 3:39e6440ccd45 | 31 | |
| cheryl_he | 3:39e6440ccd45 | 32 | //Encoder setup and variables |
| cheryl_he | 3:39e6440ccd45 | 33 | InterruptIn interrupt(PTA13); |
| cheryl_he | 3:39e6440ccd45 | 34 | |
| cheryl_he | 3:39e6440ccd45 | 35 | Timer t; |
| cheryl_he | 3:39e6440ccd45 | 36 | |
| cheryl_he | 3:39e6440ccd45 | 37 | float ADCdata [128]; |
| cheryl_he | 3:39e6440ccd45 | 38 | |
| cheryl_he | 3:39e6440ccd45 | 39 | void initADC(void){ |
| cheryl_he | 3:39e6440ccd45 | 40 | |
| cheryl_he | 3:39e6440ccd45 | 41 | ADC0->CFG1 = ADC0->CFG1 & ( |
| cheryl_he | 3:39e6440ccd45 | 42 | ~( |
| cheryl_he | 3:39e6440ccd45 | 43 | 0x80 // LDLPC = 0 ; no low-power mode |
| cheryl_he | 3:39e6440ccd45 | 44 | | 0x60 // ADIV = 1 |
| cheryl_he | 3:39e6440ccd45 | 45 | | 0x10 // Sample time short |
| cheryl_he | 3:39e6440ccd45 | 46 | | 0x03 // input clock = BUS CLK |
| cheryl_he | 3:39e6440ccd45 | 47 | ) |
| cheryl_he | 3:39e6440ccd45 | 48 | ) ; // clkdiv <= 1 |
| cheryl_he | 3:39e6440ccd45 | 49 | ADC0->CFG2 = ADC0->CFG2 |
| cheryl_he | 3:39e6440ccd45 | 50 | | 0x03 ; // Logsample Time 11 = 2 extra ADCK |
| cheryl_he | 3:39e6440ccd45 | 51 | ADC0->SC3 = ADC0->SC3 |
| cheryl_he | 3:39e6440ccd45 | 52 | & (~(0x03)) ; // hardware avarage off |
| cheryl_he | 3:39e6440ccd45 | 53 | } |
| cheryl_he | 0:453d27750ab3 | 54 | |
| cheryl_he | 0:453d27750ab3 | 55 | int main() { |
| cheryl_he | 3:39e6440ccd45 | 56 | |
| cheryl_he | 3:39e6440ccd45 | 57 | telemetry_serial.baud(115200); |
| cheryl_he | 1:ff0fc50372c8 | 58 | telemetry_obj.transmit_header(); |
| cheryl_he | 3:39e6440ccd45 | 59 | //uint16_t data [128] = {0}; |
| cheryl_he | 3:39e6440ccd45 | 60 | |
| cheryl_he | 3:39e6440ccd45 | 61 | //Alter reg values to speed up KL25Z |
| cheryl_he | 3:39e6440ccd45 | 62 | initADC(); |
| cheryl_he | 3:39e6440ccd45 | 63 | |
| cheryl_he | 3:39e6440ccd45 | 64 | t.start(); |
| cheryl_he | 1:ff0fc50372c8 | 65 | //uint16_t* data = cam1.read(); |
| cheryl_he | 1:ff0fc50372c8 | 66 | |
| cheryl_he | 0:453d27750ab3 | 67 | while(1) { |
| cheryl_he | 3:39e6440ccd45 | 68 | /* myled = 1; |
| cheryl_he | 0:453d27750ab3 | 69 | wait(0.2); |
| cheryl_he | 0:453d27750ab3 | 70 | myled = 0; |
| cheryl_he | 0:453d27750ab3 | 71 | wait(0.2); |
| cheryl_he | 3:39e6440ccd45 | 72 | */ |
| cheryl_he | 1:ff0fc50372c8 | 73 | /*for (uint16_t i=0; i<128; i++) { |
| cheryl_he | 1:ff0fc50372c8 | 74 | tele_linescan[i] = data[i]; |
| cheryl_he | 1:ff0fc50372c8 | 75 | } |
| cheryl_he | 1:ff0fc50372c8 | 76 | */ |
| cheryl_he | 3:39e6440ccd45 | 77 | |
| cheryl_he | 3:39e6440ccd45 | 78 | tele_time_ms = t.read_ms(); |
| cheryl_he | 3:39e6440ccd45 | 79 | for (uint16_t i=0; i<128; i++) { |
| cheryl_he | 3:39e6440ccd45 | 80 | tele_linescan[i] = ADCdata[i]; |
| cheryl_he | 3:39e6440ccd45 | 81 | } |
| cheryl_he | 3:39e6440ccd45 | 82 | |
| cheryl_he | 1:ff0fc50372c8 | 83 | telemetry_obj.do_io(); |
| cheryl_he | 1:ff0fc50372c8 | 84 | |
| cheryl_he | 0:453d27750ab3 | 85 | } |
| cheryl_he | 0:453d27750ab3 | 86 | } |