// Automatically generated C++ file on Wed Feb 11 22:26:20 2026 // // To build with Digital Mars C++ Compiler: // // dmc -mn -WD -o semnale_mcu_x1.cpp kernel32.lib union uData { bool b; char c; unsigned char uc; short s; unsigned short us; int i; unsigned int ui; float f; double d; long long int i64; unsigned long long int ui64; char *str; unsigned char *bytes; }; // int DllMain() must exist and return 1 for a process to load the .DLL // See https://docs.microsoft.com/en-us/windows/win32/dlls/dllmain for more information. int __stdcall DllMain(void *module, unsigned int reason, void *reserved) { return 1; } bool Last_CLK= 0; int counter= 0; int polarity= 1; int Counter_period= 1023; float Dutty=30; //int max_duty= 0.33 * Counter_period /2 ; int Offset_1= Counter_period * 0.3333 /2; int Offset_2= Counter_period * 0.6666 /2; // #undef pin names lest they collide with names in any header file(s) you might include. #undef CLK #undef Duty #undef PWM1 #undef PWM3 #undef PWM1N #undef PWM2N #undef PWM3N #undef PWM2 extern "C" __declspec(dllexport) void semnale_mcu_x1(void **opaque, double t, union uData *data) { bool CLK = data[0].b; // input int Duty = data[1].i; // input bool &PWM1 = data[2].b; // output bool &PWM3 = data[3].b; // output bool &PWM1N = data[4].b; // output bool &PWM2N = data[5].b; // output bool &PWM3N = data[6].b; // output bool &PWM2 = data[7].b; // output // Implement module evaluation code here: Dutty=Duty/100 *3/20 * Counter_period; //Dutty=Duty; if ( (CLK==1) && (Last_CLK==0) ) { counter= counter+polarity; if ( (counter > (Counter_period/2) ) || (counter ==0) ) { polarity= polarity * (-1); } if ( counter > ( (Counter_period/2) - Dutty ) ) { PWM1= 1; PWM1N= 0; } else { PWM1= 0; PWM1N= 1; } if ( counter > ( (Counter_period/2) - Dutty - Offset_1 ) ) { PWM2= 1; PWM2N= 0; } else { PWM2= 0; PWM2N= 1; } if ( counter > ( (Counter_period/2) - Dutty - Offset_2 ) ) { PWM3= 1; PWM3N= 0; } else { PWM3= 0; PWM3N= 1; } } // counter loop end Last_CLK=CLK; }