I messed up the merge, so pushing it over to another repo so I don't lose it. Will tidy up and remove later
Dependencies: BufferedSerial FatFileSystemCpp mbed
LTCDecode.h@7:87aea27cc68b, 2021-02-12 (annotated)
- Committer:
- AndyA
- Date:
- Fri Feb 12 14:24:55 2021 +0000
- Revision:
- 7:87aea27cc68b
- Parent:
- 0:97661408d0f9
- Child:
- 9:7214e3c3e5f8
HACK JOB - USE PREVIOUS VERSION; This version reads time from LTC but then runs from the PPF input.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AndyA | 0:97661408d0f9 | 1 | #ifndef __LTCDECODE_H__ |
AndyA | 0:97661408d0f9 | 2 | #define __LTCDECODE_H__ |
AndyA | 0:97661408d0f9 | 3 | |
AndyA | 0:97661408d0f9 | 4 | #include "mbed.h" |
AndyA | 0:97661408d0f9 | 5 | |
AndyA | 0:97661408d0f9 | 6 | const uint32_t minBitPeriodUS = |
AndyA | 0:97661408d0f9 | 7 | (uint32_t)((1000000.0f / 2400) / 1.1f); // allow for 10% time error |
AndyA | 0:97661408d0f9 | 8 | const uint32_t maxMidSymbolTimeUS = (uint32_t)( |
AndyA | 0:97661408d0f9 | 9 | ((1000000.0f / (1920 * 2))) * 1.1f); // allow for 10% time error |
AndyA | 0:97661408d0f9 | 10 | |
AndyA | 0:97661408d0f9 | 11 | class LTCDecode { |
AndyA | 0:97661408d0f9 | 12 | |
AndyA | 0:97661408d0f9 | 13 | public: |
AndyA | 0:97661408d0f9 | 14 | LTCDecode(const PinName pin); |
AndyA | 0:97661408d0f9 | 15 | void setInputTimer(Timer *inputTimer); |
AndyA | 0:97661408d0f9 | 16 | |
AndyA | 0:97661408d0f9 | 17 | bool synced() { return LTCsynced; }; |
AndyA | 0:97661408d0f9 | 18 | |
AndyA | 0:97661408d0f9 | 19 | // reads pending data up to a sync marker, returns true is sync is found. |
AndyA | 0:97661408d0f9 | 20 | bool searchForSync(); |
AndyA | 0:97661408d0f9 | 21 | |
AndyA | 0:97661408d0f9 | 22 | // reads pending data up to the end of the frame, returns true at the end of a |
AndyA | 0:97661408d0f9 | 23 | // frame. check sync stats and lastFrameData for results. |
AndyA | 0:97661408d0f9 | 24 | bool readWaitingData(); |
AndyA | 0:97661408d0f9 | 25 | |
AndyA | 0:97661408d0f9 | 26 | typedef struct { |
AndyA | 0:97661408d0f9 | 27 | int hours; |
AndyA | 0:97661408d0f9 | 28 | int minutes; |
AndyA | 0:97661408d0f9 | 29 | int seconds; |
AndyA | 0:97661408d0f9 | 30 | int frame; |
AndyA | 0:97661408d0f9 | 31 | bool frameDrop; |
AndyA | 0:97661408d0f9 | 32 | uint32_t frameStartTime; |
AndyA | 0:97661408d0f9 | 33 | } LTCData_t; |
AndyA | 0:97661408d0f9 | 34 | |
AndyA | 0:97661408d0f9 | 35 | const LTCData_t *getLastFrame() { return &lastFrame; }; |
AndyA | 0:97661408d0f9 | 36 | |
AndyA | 7:87aea27cc68b | 37 | void disable() { |
AndyA | 7:87aea27cc68b | 38 | _LTCIn.fall(NULL); |
AndyA | 7:87aea27cc68b | 39 | _LTCIn.rise(NULL); |
AndyA | 7:87aea27cc68b | 40 | } |
AndyA | 0:97661408d0f9 | 41 | // buffer holding received LTC bits and their start times. |
AndyA | 0:97661408d0f9 | 42 | |
AndyA | 0:97661408d0f9 | 43 | private: |
AndyA | 0:97661408d0f9 | 44 | void LTCOnEdge(void); |
AndyA | 0:97661408d0f9 | 45 | |
AndyA | 0:97661408d0f9 | 46 | InterruptIn _LTCIn; |
AndyA | 0:97661408d0f9 | 47 | Timer *_inputTimer; |
AndyA | 0:97661408d0f9 | 48 | |
AndyA | 0:97661408d0f9 | 49 | LTCData_t lastFrame; |
AndyA | 0:97661408d0f9 | 50 | |
AndyA | 0:97661408d0f9 | 51 | static const int _newBitBufferSize_ = 80; |
AndyA | 0:97661408d0f9 | 52 | |
AndyA | 0:97661408d0f9 | 53 | bool newBitBuffer[_newBitBufferSize_]; |
AndyA | 0:97661408d0f9 | 54 | uint32_t bitTimes[_newBitBufferSize_]; |
AndyA | 0:97661408d0f9 | 55 | |
AndyA | 0:97661408d0f9 | 56 | bool LTCsynced; |
AndyA | 0:97661408d0f9 | 57 | |
AndyA | 0:97661408d0f9 | 58 | volatile int newBitsWrite; |
AndyA | 0:97661408d0f9 | 59 | int newBitsRead; |
AndyA | 0:97661408d0f9 | 60 | |
AndyA | 0:97661408d0f9 | 61 | // max bit period = 520.8 ms (1920 Hz) |
AndyA | 0:97661408d0f9 | 62 | // min bit period = 416.7 ms (2400 Hz) |
AndyA | 0:97661408d0f9 | 63 | // max period of a '1' symbol = 260.4ms (1920Hz * 2) |
AndyA | 0:97661408d0f9 | 64 | |
AndyA | 0:97661408d0f9 | 65 | uint32_t lastTransition; |
AndyA | 0:97661408d0f9 | 66 | uint32_t lastBitStart; |
AndyA | 0:97661408d0f9 | 67 | |
AndyA | 0:97661408d0f9 | 68 | uint32_t LTCBuffer[3]; |
AndyA | 0:97661408d0f9 | 69 | uint32_t firstMark; |
AndyA | 0:97661408d0f9 | 70 | int markCount; |
AndyA | 0:97661408d0f9 | 71 | uint32_t nextSecondStart; |
AndyA | 0:97661408d0f9 | 72 | uint32_t PPSWidth; |
AndyA | 0:97661408d0f9 | 73 | int bitCounter ; |
AndyA | 0:97661408d0f9 | 74 | int dwordCounter ; |
AndyA | 0:97661408d0f9 | 75 | |
AndyA | 0:97661408d0f9 | 76 | uint32_t timeOfBit, frameStartTime; |
AndyA | 0:97661408d0f9 | 77 | }; |
AndyA | 0:97661408d0f9 | 78 | |
AndyA | 0:97661408d0f9 | 79 | #endif |