From 764c8722596f5b3bd01bb26848f7289b0972d7b0 Mon Sep 17 00:00:00 2001 From: Abel Tim Date: Sun, 23 Mar 2025 12:38:48 +0100 Subject: updated repo structure --- .../debug/prewk/motordriver/softPWM/softPWM.ino | 46 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 OLD_CODE_REMOVE_LATER/debug/prewk/motordriver/softPWM/softPWM.ino (limited to 'OLD_CODE_REMOVE_LATER/debug/prewk/motordriver/softPWM/softPWM.ino') diff --git a/OLD_CODE_REMOVE_LATER/debug/prewk/motordriver/softPWM/softPWM.ino b/OLD_CODE_REMOVE_LATER/debug/prewk/motordriver/softPWM/softPWM.ino new file mode 100644 index 0000000..ab74715 --- /dev/null +++ b/OLD_CODE_REMOVE_LATER/debug/prewk/motordriver/softPWM/softPWM.ino @@ -0,0 +1,46 @@ +#include +#include + +int pwmPin = 3; + +volatile int PWMval = 0; // PWM value 0-100 + +void setup() { + pinMode(pwmPin, OUTPUT); + Serial.begin(9600); + + Timer3.initialize(800); // 800 microseconds or 1.25kHz + Timer3.attachInterrupt(updatePWM); +} + +void updatePWM() { + static int counter = 0; + + if (counter < PWMval) { + digitalWrite(pwmPin, HIGH); + } else { + digitalWrite(pwmPin, LOW); + } + + counter++; + if (counter >= 100) { + counter = 0; + } +} + +void mcpsoftpwm(int value) { + if (value < 0) value = 0; + if (value > 100) value = 100; + + Serial.print("softPWM pin: 3, value: "); + Serial.println(value); + PWMval = value; +} + +void loop() { + mcpsoftpwm(100); // Set PWM to 100% + delay(1000); + mcpsoftpwm(50); // Set PWM to 50% + delay(1000); + Serial.println("loop"); +} -- cgit v1.2.3