Hello Everyone!
This is the first time I have attempted to use PWM on my AB01. I trying to send PWM through to a motor driver but for some reason I can’t for the life of me figure out, the max output is only about 0.013v on a 100% duty cycle. I have tested the full setup as a digital and the motor runs fine and the output is 3.3v as expected. I have also tested the bare board with nothing else connected and is the same across both PWM pins. I have updated my IDE and seem to have the latest core. I feel like I have missed something fundamental, despite trawling through these forums and github. Any advice would be greatly appreciated!
This is just my test code I have been using to try and fault find the issue…
#include “Arduino.h”
#include “LoRaWan_APP.h”
// — Motor A Pin Definitions —
const int PWMA = PWM1; // GPIO2 - Hardware PWM Channel 1
const int AIN1 = GPIO1;
const int AIN2 = GPIO5;
// — Motor B Pin Definitions —
const int PWMB = PWM2; // GPIO3 - Hardware PWM Channel 2
const int BIN1 = GPIO0;
const int BIN2 = GPIO4;
//const int VEXT = GPIO6;
void setup() {
// Enable Vext to power peripherals if your driver logic relies on it
//pinMode(VEXT, OUTPUT);
//digitalWrite(VEXT, HIGH);
//delay(20);
// Set up motor direction control pins
pinMode(AIN1, OUTPUT);
pinMode(AIN2, OUTPUT);
pinMode(BIN1, OUTPUT);
pinMode(BIN2, OUTPUT);
// Initialize hardware PWM pins via the official core macro definitions
pinMode(PWMA, OUTPUT);
pinMode(PWMB, OUTPUT);
//setPWM_Frequency(PWM_CLK_FREQ_12M);
//pwm period can be 0xFF~0xFFFF, default is 0xFFFF
//setPWM_ComparePeriod(0xFFFF);
// Initialize motors to a standstill
analogWrite(PWMA, 0);
analogWrite(PWMB, 0);
//digitalWrite(PWMA, LOW);
//digitalWrite(PWMB, LOW);
}
void loop() {
// — Move Forward —
digitalWrite(AIN1, HIGH);
digitalWrite(AIN2, LOW);
analogWrite(PWMA, 255); // 0 to 255 speed range
//digitalWrite(PWMA, HIGH);
digitalWrite(BIN1, HIGH);
digitalWrite(BIN2, LOW);
analogWrite(PWMB, 255); // 0 to 255 speed range
//digitalWrite(PWMB, HIGH);
delay(2000);
// --- Stop ---
analogWrite(PWMA, 0);
analogWrite(PWMB, 0);
//digitalWrite(PWMA, LOW);
//digitalWrite(PWMB, LOW);
digitalWrite(AIN1, LOW);
digitalWrite(AIN2, HIGH);
delay(2000);