Tool/software: Code Composer Studio
Hello everyone
My goal is create an PWM in PRU (AM335X) in the Beaglebone black. The pwm is Time-Base with a fixed duty cycle and frequency. The application is to allow events triggering in ADC conversion.
I developed a code in CSS and think the problem is the registers settings (I am new to AM335X). I'm trying to replicate this example from datashet.
my code:
#define C_CONVERSIONS_AMOUNT_LIMIT 6400 //max conversions
//////////////////////////////////MACROS to save cycles ////////////////////////////////////////////////
#define CLR_BIT(p,n) ((p) &= ~((1) << (n))) //clear p position n
#define SET_BIT(p,n) ((p) |= ((1) << (n))) //set p position n
#define TGL_BIT(p,n) ((p) ^= ((1) << (n))) //toggle p position n
#define COMPARE_VAL(a,b) (a==b ? 1 : 0)//MUST BE TESTED //Compare macro
#define ADD(p,n,m) (p = n+m) //Add 2 values
/* Non-CT register defines */
#define CM_PER_EPWMSS1 (*((volatile unsigned int *)0x44E000CC))
//GPIO parameters
volatile register unsigned int __R31, __R30; //R31 = INPUT; R30 = Output
/* Prototypes */
void init_epwm();
void main(void) {
CLR_BIT(__R30,C_OUTPUT_LED1_RED);
CLR_BIT(__R30,C_OUTPUT_LED0_AZUL);
CT_CFG.SYSCFG_bit.STANDBY_INIT = 0;
/* Initialize peripheral fuctions */
init_epwm();
while (1) {
//just for debugging
TGL_BIT(__R30,C_OUTPUT_LED1_RED);
__delay_cycles(200000000); // half-second delay
}
}
/*
* Init ePWM
*/
void init_epwm() {
/* Enable PWMSS1 clock signal generation */
while (!(CM_PER_EPWMSS1 & 0x2)) {
CM_PER_EPWMSS1 |= 0x2;
}
//SET_BIT(__R30,C_OUTPUT_LED1_RED);
PWMSS1.EPWM_TBCTL = 0x0030;
PWMSS1.CLKCONFIG = 273;
PWMSS1.CLKSTATUS = 273;
PWMSS1.EPWM_TBPRD = 0x258; //600 decimal
//PWMSS1.EPWM_TBPHSHR = 0x0000;
PWMSS1.EPWM_TBPHS = 0x0000;
PWMSS1.EPWM_TBCNT = 0x0000;
PWMSS1.EPWM_CMPA = 0x15E; //350 decimal
PWMSS1.EPWM_CMPB = 0xC8; //200 decimal
PWMSS1.EPWM_CMPCTL = 0x0000;
PWMSS1.EPWM_AQCTLA = 0x0012;
PWMSS1.EPWM_AQCTLB = 0x0102;
}