PropWare  3.0.0.229
C++ objects and CMake build system for Parallax Propeller
DualPWM_Demo.cpp

Drive two PWM waves on GPIO pins with varying duty cycles. Duty will vary from 0% up to 100% in 12.5% increments.

cmake_minimum_required(VERSION 3.12)
find_package(PropWare REQUIRED)
project(DualPWM_Demo)
create_simple_executable(${PROJECT_NAME} DualPWM_Demo.cpp)
static const unsigned int PWM_FREQUENCY = 20000;
static const PropWare::Port::Mask MASK_1 = Port::P0;
static const PropWare::Port::Mask MASK_2 = Port::P1;
int main () {
static uint32_t stack[48];
volatile unsigned int leftDuty;
volatile unsigned int rightDuty;
const DualPWM pwmController(PWM_FREQUENCY, MASK_1, MASK_2, &leftDuty, &rightDuty, stack);
Runnable::invoke(pwmController);
while (1) {
for (unsigned int i = 0; i <= DualPWM::MAX_DUTY; i += DualPWM::MAX_DUTY / 8) {
leftDuty = i;
rightDuty = DualPWM::MAX_DUTY - i;
waitcnt(CNT + MILLISECOND);
}
}
}
PropWare::DualPWM
Dual-pin PWM driver. Requires a cog to run and will use both counter modules in that cog.
Definition: dualpwm.h:40
PropWare::Port::Mask
Mask
Definition: port.h:43
PropWare::Port
Flexible port that can have any pin enabled or disabled. Pins are independent of each other.
Definition: port.h:38
main
int main(void)
Definition: GraphicsTest.c:20
PropWare::Runnable
Helper class for creating easy parallel applications.
Definition: runnable.h:75
dualpwm.h
waitcnt
#define waitcnt(a)
Wait until system counter reaches a value.
Definition: propeller.h:176
CNT
#define CNT
The system clock count.
Definition: propeller1.h:151
PropWare
Generic definitions and functions for the Parallax Propeller.
Definition: runnable.h:33