#include #include #include "resource_table_empty.h" // Define Base Addresses for eHRPWM Modules (AM335x) #define EHRPWM1_BASE 0x48302200 #define EHRPWM2_BASE 0x48304200 // eHRPWM Register Offsets #define TBCTL 0x00 #define TBPRD 0x0A #define CMPA 0x12 #define AQCTLA 0x16 #define TBPHS 0x04 #define TBCNT 0x08 // Function to initialize PWM module void pwm_init(uint32_t base, uint16_t period) { // 1. Disable PWM *(uint16_t *)(base + TBCTL) = 0x0003; // Freeze and reset counter // 2. Set Period (Speed) *(uint16_t *)(base + TBPRD) = period - 1; // 3. Set Action Qualifiers (Set high on match, low on zero) *(uint16_t *)(base + AQCTLA) = 0x0012; // 4. Clear Counter and Phase *(uint16_t *)(base + TBCNT) = 0x0000; *(uint16_t *)(base + TBPHS) = 0x0000; // 5. Enable Clock and Unfreeze *(uint16_t *)(base + TBCTL) = 0x0000; // Count Up, Prescaler 1 *(uint16_t *)(base + TBCTL) |= (1 << 15); // TBCLKSYNC = 1 } void main(void) { // Initialize PRU configuration CT_CFG.SYSCFG_bit.STANDBY_INIT = 0; // Initialize eHRPWM1 and 2 // Period value depends on frequency needed pwm_init(EHRPWM1_BASE, 1000); pwm_init(EHRPWM2_BASE, 1000); // Set 50% duty cycle for initial step signal *(uint16_t *)(EHRPWM1_BASE + CMPA) = 500; *(uint16_t *)(EHRPWM2_BASE + CMPA) = 500; while (1) { // Main loop: Update TBPRD/CMPA based on rpmsg inputs // for speed/direction changes. } }