Hi,
I need help with a program i’m doing for a motor controller, I am trying to limit the current to 100 amps but but still have the PWM control work. I’ve got the program to stop PWM output when current goes above 100 amps but then I can’t get the PWM to go back down once it reaches that current, any help would be appreciated.
#include <PWM.h>
int32_t frequency = 10000; //frequency HZ
int current = 0; // Current Sensor
int motoramps = 0; // Motor Amps
int throttlePin = A0; //Throttle input
int currentPin = A1; //Current sensor input
void setup() {
InitTimersSafe ();
// Serial.begin(9600);
bool success = SetPinFrequencySafe(9, frequency);
if(success) {
pinMode (13, OUTPUT);
digitalWrite(13, HIGH);
}
}
void loop() {
int throttleValue = analogRead(throttlePin);
throttleValue = map(throttleValue, 0, 1023, 0, 255);
current = analogRead(currentPin);
current = map(current, 0, 1023, 0, 5000);
motoramps = ((current - 2525) / 3.65);
if (motoramps <= 100){
pwmWrite(9, throttleValue);
}
// Serial.println(motoramps, 2);
delay(10); // delay inbetween reads for stability
}