raschemmel:
Post your code .
Identify the pin you used to test the pwm.
Replace the 100 ohm resistor with a 470 ohm resistor with a led in series with the cathode connected to the collector. Repeat your test with the code.
I tested the pwm output with my ossiloscope and it showed it was working properly. I changed it to an LED is series and i still get the same .
Here is my code:
int BTTX = 1; //Bluetooth Transmit
int BTRX = 0; //Bluetooth Receive
int RFWD = 9; //Right Motor Forward PWM
int LBWD = 10; //Left Motor Backward PWM
int RBWD = 11; //Right Motor Backward PWM
int LFWD = 12; //Left Motor Forward PWM
int CPWM1 = 4; //62khZ Constant PWM
int CPWM2 = 13; //62khZ Constant PWM
String LeftDIR = "";
String LeftVAL = "";
String RightDIR = "";
String RightVAL = "";
String serialRead = "";
String LeftVALBin;
String RightVALBin;
int LStr2Byte = 0;
int RStr2Byte = 0;
char LeftVALBinArray[8];
char RightVALBinArray[8];
//Created by Alexander Bolton
void setup() {
// put your setup code here, to run once:
TCCR0B = TCCR0B & B11111000 | B00000001; // Sets pins 4 and 13 to 62Khz
Serial.begin(9600);
analogWrite(CPWM1, 173); //Set for the mosfet switch on the Buck Booster
analogWrite(CPWM2, 173); //Set for the mosfet switch on the Buck Booster
}
void loop() {
// put your main code here, to run repeatedly:
if (Serial.available() > 0) {
serialRead = Serial.readStringUntil('/N');
Serial.println(serialRead);
LeftDIR = serialRead.substring(0, 1);
LeftVALBin = serialRead.substring(1, 9);
LeftVALBin.toCharArray(LeftVALBinArray, 8);
RightDIR = serialRead.substring(9, 10);
RightVALBin = serialRead.substring(10, 17);
RightVALBin.toCharArray(RightVALBinArray, 8);
long LeftVAL1 = strtol(LeftVALBinArray, NULL, 2);
long RightVAL1 = strtol(RightVALBinArray, NULL, 2);
LeftVAL = String(LeftVAL1);
RightVAL = String(RightVAL1);
if (LeftDIR == "1") {
LStr2Byte = LeftVAL.toInt(); //Turn to string
analogWrite(LFWD, LStr2Byte * 2);
analogWrite(LBWD, 0);
Serial.println("Left Forward");
Serial.println(LStr2Byte * 2);
}
else if (LeftDIR == "0") {
LStr2Byte = LeftVAL.toInt();
analogWrite(LBWD, LStr2Byte * 2);
analogWrite(LFWD, 0);
Serial.println("Left Reverse");
Serial.println(LStr2Byte * 2);
}
if (RightDIR == "1") {
RStr2Byte = RightVAL.toInt();
analogWrite(RFWD, RStr2Byte * 2);
analogWrite(RBWD, 0);
Serial.println("Right Forward");
Serial.println(RStr2Byte * 2);
}
else if (RightDIR == "0") {
RStr2Byte = RightVAL.toInt();
analogWrite(RBWD, RStr2Byte * 2);
analogWrite(RFWD, 0);
Serial.println("Right Reverse");
Serial.println(RStr2Byte * 2);
}
}
}