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 SerialInputReactionHandler AMPulseTrain SwArr16MOSFET StrCommandHandler KajiLabES
main.cpp@1:b97639dad576, 2019-10-23 (annotated)
- Committer:
- aktk
- Date:
- Wed Oct 23 20:08:31 2019 +0000
- Revision:
- 1:b97639dad576
- Parent:
- 0:19a67422961f
- Child:
- 2:5cb68cc8ecaa
used at VRSJ24 DEMO
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| aktk | 0:19a67422961f | 1 | #include "mbed.h" |
| aktk | 0:19a67422961f | 2 | #include "KajiLabES.h" |
| aktk | 0:19a67422961f | 3 | #include "PMRC16ch.h" |
| aktk | 0:19a67422961f | 4 | #include "sigbind.h" |
| aktk | 0:19a67422961f | 5 | #include <iostream> |
| aktk | 0:19a67422961f | 6 | #include <bitset> |
| aktk | 1:b97639dad576 | 7 | ProcessState pstate = WAIT_A_CERTAIN_KEY; |
| aktk | 1:b97639dad576 | 8 | ElectrodeSpacing spacing = WIDE_CONDITION; |
| aktk | 1:b97639dad576 | 9 | StimulationMode smode = BIPOLAR; |
| aktk | 0:19a67422961f | 10 | Serial pc(USBTX, USBRX); // tx, rx |
| aktk | 0:19a67422961f | 11 | |
| aktk | 0:19a67422961f | 12 | DigitalOut myled1(LED1); |
| aktk | 0:19a67422961f | 13 | DigitalOut myled2(LED2); |
| aktk | 0:19a67422961f | 14 | DigitalOut myled3(LED3); |
| aktk | 0:19a67422961f | 15 | DigitalOut myled4(LED4); |
| aktk | 0:19a67422961f | 16 | KajiLabES stimulator; |
| aktk | 0:19a67422961f | 17 | PMRC16ch pmrc(16); |
| aktk | 0:19a67422961f | 18 | uint32_t pw;//pulse width |
| aktk | 0:19a67422961f | 19 | uint32_t pp;//pulse period |
| aktk | 0:19a67422961f | 20 | uint32_t ph;//pulse hight |
| aktk | 0:19a67422961f | 21 | |
| aktk | 0:19a67422961f | 22 | int main() |
| aktk | 0:19a67422961f | 23 | { |
| aktk | 1:b97639dad576 | 24 | stimulator.init(); |
| aktk | 0:19a67422961f | 25 | myled1 = 1; |
| aktk | 0:19a67422961f | 26 | pmrc.allHiZ(); |
| aktk | 0:19a67422961f | 27 | myled2 = 1; |
| aktk | 0:19a67422961f | 28 | { |
| aktk | 0:19a67422961f | 29 | using namespace aktk_sigbind; |
| aktk | 0:19a67422961f | 30 | pc.baud(921600); |
| aktk | 0:19a67422961f | 31 | pc.attach(&keyBind); |
| aktk | 0:19a67422961f | 32 | pw = 100; |
| aktk | 0:19a67422961f | 33 | pp = 5000; |
| aktk | 0:19a67422961f | 34 | ph = 0; |
| aktk | 0:19a67422961f | 35 | printKBManual(); |
| aktk | 0:19a67422961f | 36 | wait(.5); |
| aktk | 0:19a67422961f | 37 | } |
| aktk | 0:19a67422961f | 38 | while(1) { |
| aktk | 0:19a67422961f | 39 | while (pstate == WAIT_A_CERTAIN_KEY) { |
| aktk | 0:19a67422961f | 40 | myled3 = (!myled3); |
| aktk | 0:19a67422961f | 41 | wait(0.5); |
| aktk | 0:19a67422961f | 42 | } |
| aktk | 0:19a67422961f | 43 | myled3 = 1; |
| aktk | 0:19a67422961f | 44 | pmrc.setPol(PMRC16ch::Cathodic); |
| aktk | 0:19a67422961f | 45 | while (pstate == MAIN_ROUTINE) { |
| aktk | 1:b97639dad576 | 46 | |
| aktk | 1:b97639dad576 | 47 | for (int i = 0; i < 2; i++) { |
| aktk | 1:b97639dad576 | 48 | switch(smode){ |
| aktk | 1:b97639dad576 | 49 | case BIPOLAR: pmrc.setPol((PMRC16ch::Polarity)i); break; |
| aktk | 1:b97639dad576 | 50 | case CATHODIC: pmrc.setPol(PMRC16ch::Cathodic); break; |
| aktk | 1:b97639dad576 | 51 | case ANODIC: pmrc.setPol(PMRC16ch::Anodic); break; |
| aktk | 1:b97639dad576 | 52 | } |
| aktk | 1:b97639dad576 | 53 | if(spacing == WIDE_CONDITION) |
| aktk | 1:b97639dad576 | 54 | //pmrc.setTrio(3,1,5); |
| aktk | 1:b97639dad576 | 55 | pmrc.setTwin(1, 2); |
| aktk | 1:b97639dad576 | 56 | else |
| aktk | 1:b97639dad576 | 57 | //pmrc.setTrio(3,2,4); |
| aktk | 1:b97639dad576 | 58 | pmrc.setTwin(1, 3); |
| aktk | 1:b97639dad576 | 59 | wait_us(pp-pw); |
| aktk | 1:b97639dad576 | 60 | stimulator.DAAD(ph); |
| aktk | 1:b97639dad576 | 61 | wait_us(pw); |
| aktk | 1:b97639dad576 | 62 | stimulator.DAAD(0); |
| aktk | 1:b97639dad576 | 63 | } |
| aktk | 1:b97639dad576 | 64 | /* |
| aktk | 0:19a67422961f | 65 | for(int i = 0; i < 2; i++) { |
| aktk | 0:19a67422961f | 66 | pmrc.setTwin(i+1, (i+1)%8+1); |
| aktk | 1:b97639dad576 | 67 | //pmrc.setTwin(i+1, (i+1)%8+1); |
| aktk | 1:b97639dad576 | 68 | //pmrc.setTwin(i+1, (i+1)%8+1); |
| aktk | 0:19a67422961f | 69 | //pmrc.setOvsO(i+1); |
| aktk | 0:19a67422961f | 70 | wait_us(pp-pw); |
| aktk | 0:19a67422961f | 71 | stimulator.DAAD(ph); |
| aktk | 0:19a67422961f | 72 | wait_us(pw); |
| aktk | 0:19a67422961f | 73 | stimulator.DAAD(0); |
| aktk | 0:19a67422961f | 74 | //pmrc.allHiZ(); |
| aktk | 0:19a67422961f | 75 | //wait_us(pw); |
| aktk | 0:19a67422961f | 76 | } |
| aktk | 1:b97639dad576 | 77 | */ |
| aktk | 0:19a67422961f | 78 | if (pstate == TERMINATED) break; |
| aktk | 0:19a67422961f | 79 | } |
| aktk | 0:19a67422961f | 80 | } |
| aktk | 0:19a67422961f | 81 | } |