Interference current stimulation program with kaji-lab ES device.
Dependencies: mbed SerialInputReactionHandler AMPulseTrain SwArr16MOSFET StrCommandHandler KajiLabES
Revision 5:779d799b5c83, committed 2020-02-03
- Comitter:
- aktk
- Date:
- Mon Feb 03 17:07:07 2020 +0000
- Parent:
- 4:8d73aaba879f
- Commit message:
- not hi-speed switching at all; just 200us 50 Hz for the back of the hand stim; [1-4] keys can switch the 4 channels;
Changed in this revision
AMPulseTrain.lib | Show annotated file Show diff for this revision Revisions of this file |
subroutines.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 8d73aaba879f -r 779d799b5c83 AMPulseTrain.lib --- a/AMPulseTrain.lib Mon Jan 06 21:38:02 2020 +0000 +++ b/AMPulseTrain.lib Mon Feb 03 17:07:07 2020 +0000 @@ -1,1 +1,1 @@ -https://os.mbed.com/users/aktk/code/AMPulseTrain/#77ac0df7c3a1 +https://os.mbed.com/users/aktk/code/AMPulseTrain/#5eae3f90d161
diff -r 8d73aaba879f -r 779d799b5c83 subroutines.cpp --- a/subroutines.cpp Mon Jan 06 21:38:02 2020 +0000 +++ b/subroutines.cpp Mon Feb 03 17:07:07 2020 +0000 @@ -1,18 +1,17 @@ #include "subroutines.h" #include "KajiLabES.h" +#include "AMPulseTrain.h" #include "SwArr16MOSFET.h" #include "StrCommandHandler.h" #include "SerialInputReactionHandler.h" -#include "AMPulseTrain.h" - Serial pc(USBTX, USBRX, 921600); // tx, rx Ticker ticker; KajiLabES stimulator; -static int const nofch = 8; +static int const nofch = 5; SwArr16MOSFET swBrd(nofch, p14, p13, p12, p11, p10); void callback_PulseEdge(bool arg_pulsestate, PulseTrain*, AMSignal*); @@ -21,6 +20,7 @@ new PulseTrain(20000, 1.0, 100000), new AMSignal(50, 200) ); +static float const AMPLE_MAX_mA = 15.0; StrCommandHandler command_handler; SerialInputReactionHandler reactor; @@ -28,28 +28,54 @@ static const int g_sample_size_imp = 100; uint16_t g_retval[g_sample_size_imp]; +static int g_ch = 1; +void * setch1(){g_ch = 1; return NULL;} +void * setch2(){g_ch = 2; return NULL;} +void * setch3(){g_ch = 3; return NULL;} +void * setch4(){g_ch = 4; return NULL;} +int signalvalue = 0; +int prevvalue = 0; + /// Wrapper to be attached to PulseTrain's Callback as pulse rising void callback_PulseEdge(bool arg_pulsestate, AMPulseTrain* arg_ampt) { - static int ch = 0; + //static int ch = 0; static int itr_sample = 0; + prevvalue = signalvalue; + signalvalue = arg_ampt->Signal->getAMSinalValue(); + if(prevvalue > 0&& signalvalue==0) pauseLoop(); + g_retval[itr_sample] = stimulator.DAAD( - arg_ampt->Signal->getAMSinalValue() * arg_pulsestate + signalvalue * arg_pulsestate ); - swBrd.setTwin(ch + 1, ((ch + nofch/2) % nofch) + 1); - //swBrd.setTwin(ch + 1, ((ch + nofch/2 - 1) % nofch) + 1); - ch = (ch + 3) % nofch; - if (ch+1 == 2) ch = 3 -1; + + if(signalvalue > 0) { + swBrd.setTwin(g_ch, nofch); + //swBrd.setTwin(ch + 1, ((ch + nofch/2) % nofch) + 1); + //swBrd.setTwin(ch + 1, ((ch + nofch/2 - 1) % nofch) + 1); + itr_sample = (itr_sample + 1) % g_sample_size_imp; + } else { + swBrd.allGround(); + } + #if 0 + do { + ch = (ch + 1) % nofch; + } while ( + //false + ch + 1 >= 3 + //&& + //ch + 1 == 1 + //|| + //ch + 1 >= 3 + ); + #endif //if (ch+1 == 2) ch = 6 -1; //if (ch+1 == 6) ch = 2 -1; //if (ch+1 == 5) ch = 2 - 1; //if (ch+1 == 6) ch = 1 - 1; - if(arg_pulsestate == 1) { - itr_sample = (itr_sample + 1) % g_sample_size_imp; - } } uint16_t callback_AMSignalExpression (AMPulseTrain* arg_ampt) @@ -69,7 +95,8 @@ { stimulator.init(); swBrd.allHiZ(); - swBrd.setPol(SwArr16MOSFET::Cathodic); + swBrd.setPol(SwArr16MOSFET::Anodic); + //swBrd.setPol(SwArr16MOSFET::Cathodic); swBrd.setTwin(1,2); } myled1 = 1; @@ -80,6 +107,10 @@ { ampt.attachCallback_asPulseEdge(callback_PulseEdge); ampt.attachAMSignalExpression(callback_AMSignalExpression); + command_handler.map("1", &setch1); + command_handler.map("2", &setch2); + command_handler.map("3", &setch3); + command_handler.map("4", &setch4); command_handler.map("a", &switchState); command_handler.map("E", &terminateLoop); command_handler.map("S", &startLoop); @@ -280,14 +311,14 @@ void * SetAmplitude(char const * const arg_digits) { - float lampl = 10.0 * ampt.Signal->getAmplitude_uf(); + float lampl = AMPLE_MAX_mA * ampt.Signal->getAmplitude_uf(); // read values if (scanValue(arg_digits, &lampl));//max 10mA // set values - if( lampl < 0.0 || 10.0 < lampl) lampl = 10.0 * ampt.Signal->getAmplitude_uf(); - ampt.Signal->setAmplitude((float)(lampl / 10.0)); + if( lampl < 0.0 || AMPLE_MAX_mA < lampl) lampl = AMPLE_MAX_mA * ampt.Signal->getAmplitude_uf(); + ampt.Signal->setAmplitude((float)(lampl / AMPLE_MAX_mA)); pc.puts("===\n"); pc.printf("set frequency:"); @@ -328,8 +359,8 @@ " ---\n" " v: set all paramater by arbitrary value\n" " ---\n" - " UP: Amplitude + 1(mA)\n" - " Down: Amplitude - 1(mA)\n" + " UP: Amplitude + 5% of Max I(mA)\n" + " Down: Amplitude - 5% of Max I(mA)\n" " Right: Frequency +10(Hz)\n" " Left: Frequency -10(Hz)\n" " ---\n" @@ -353,10 +384,12 @@ } l_mean /= g_sample_size_imp; pc.printf( - "Signal Amplitude: %3.3f " + "Signal Amplitude: %2.2f (MAX %2.2f)" "Carrier Frequency: %06d \n" "Z(min, mean, max)=(%d, %d, %d)\n" - , 15.0 * ampt.Signal->getAmplitude_uf(), ampt.Carrier->getFrequency() + , AMPLE_MAX_mA * ampt.Signal->getAmplitude_uf() + , AMPLE_MAX_mA + , ampt.Carrier->getFrequency() , l_min, l_mean, l_max); return NULL; }