This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
i test on am437x idk. using PRU IDK 5.0's example to control via constant table. But i found that i can not control it by running program. TI could offer some demo to show how to control ehrpwm on PRU?
/* * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/ * * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the * distribution. * * * Neither the name of Texas Instruments Incorporated nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include <stdint.h> #include <pru_cfg.h> #include <pru_ctrl.h> #include <sys_pwmss.h>//add by yoda #include "resource_table_empty.h" /* Mapping Constant Table (CT) registers to variables */ volatile far uint8_t CT_MCSPI0 __attribute__((cregister("MCSPI0", near), peripheral)); #ifndef PRU_SRAM #define PRU_SRAM __far __attribute__((cregister("PRU_SHAREDMEM", near))) #endif /* NOTE: Allocating shared_freq_x to PRU Shared Memory means that other PRU cores on * the same subsystem must take care not to allocate data to that memory. * Users also cannot rely on where in shared memory these variables are placed * so accessing them from another PRU core or from the ARM is an undefined behavior. */ PRU_SRAM volatile uint32_t shared_freq_1; PRU_SRAM volatile uint32_t shared_freq_2; PRU_SRAM volatile uint32_t shared_freq_3; /* PRCM Registers */ #define CM_PER_BASE ((volatile uint8_t *)(0x44E00000)) #define SPI0_CLKCTRL (0x4C) #define ON (0x2) #define MCSPI0_MODULCTRL (*((volatile uint32_t*)(&CT_MCSPI0 + 0x128))) /* This is a char so that I can force access to R31.b0 for the host interrupt */ volatile register uint8_t __R31; /* PRU-to-ARM interrupt */ #define PRU_ARM_INTERRUPT (19+16) int main(void) { uint32_t result; volatile uint8_t *ptr_cm; ptr_cm = CM_PER_BASE; /*****************************************************************/ /* Access PRU peripherals using Constant Table & PRU header file */ /*****************************************************************/ /* Clear SYSCFG[STANDBY_INIT] to enable OCP master port */ CT_CFG.SYSCFG_bit.STANDBY_INIT = 0; /* Read IEPCLK[OCP_EN] for IEP clock source */ result = CT_CFG.IEPCLK_bit.OCP_EN; /*****************************************************************/ /* Access SoC peripherals using Constant Table */ /*****************************************************************/ /* Access PRCM (without CT) to initialize McSPI0 clock */ ptr_cm[SPI0_CLKCTRL] = ON; /* Read McSPI0_MODULCTRL (offset 0x128)*/ result = MCSPI0_MODULCTRL; /* Toggle MCSPI0_MODULCTRL[MS] (offset 0x128, bit 2) */ MCSPI0_MODULCTRL ^= 0x4; /* Reset MCSPI0_MODULCTRL[MS] to original value */ MCSPI0_MODULCTRL = result; /*****************************************************************/ /* Access PRU Shared RAM using Constant Table */ /*****************************************************************/ /* C28 defaults to 0x00000000, we need to set bits 23:8 to 0x0100 in order to have it point to 0x00010000 */ PRU0_CTRL.CTPPR0_bit.C28_POINTER = 0x0100; /* Define value of shared_freq_1 */ shared_freq_1 = 1; /* Read PRU Shared RAM Freq_1 memory */ if (shared_freq_1 == 1) shared_freq_2 = shared_freq_2 + 1; else shared_freq_2 = shared_freq_3; /*test PWM output*/ PWMSS1.EPWM_TBPRD = 0x4B0; PWMSS1.EPWM_TBPHS = 0; PWMSS1.EPWM_TBCTL = 0; PWMSS1.EPWM_CMPCTL = 0; PWMSS1.EPWM_CMPA = 0x250; PWMSS1.EPWM_AQCTLA = 0x30; /* Halt PRU core */ __halt(); }
是的,pru控制arm上面的pwm资源来控制电机,同时通过constant table来获取相位差的计数。现在不懂怎么在pru上用constant table来操作这两个资源?
我做了如下的尝试
在pru sdk提供的pru_access_constant_table的例子中,引用了#include <sys_pwmss.h>,该头文件定义了pwmss0,pwmss1,pwmss2三个结构体。他们涵盖了
pwm操作的所有寄存器。我在main函数中使能了ehprm1的时钟,设置了时间,设置了比较寄存器A的值,并且设置了模式为up-dowm,在对应的引脚上面接了示波器,没有看到有输出,操作步骤有没有什么缺的?有没有什么现成的例子来通过constant table访问ehrpwm的?
核心几行代码如下
PWMSS1.CLKCONFIG_bit.EPWMCLK_EN = 1;
PWMSS1.EPWM_TBPRD = 0x4B0;
PWMSS1.EPWM_CMPA = 0x250;
PWMSS1.EPWM_AQCTLA = 0x30;