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.

AM335X PWM Control via direct access to registers

I am attempting to create a memory map of the PWM subsystem through the mmap() function on the Beaglebone. My code (attached) compiles and appears to be reading the correct register.

I initially hooked up the pin to a scope and went through the file system (/sys/class/pwm/ehrpwm.1:0) to output an 80% duty cycle (#echo 10000 > period_freq #echo 80 > duty_percent #echo 1 > run) this outputs the correct waveform yet I expect it to change to a 50% duty_cycle upon writing to the CMPA register.

I tried turning run off but was greeted with a "Bus error"

How can I write CMPA and other registers? what does it mean when you "write a 1 to run?"

Any help is appreciated

-Tom

5282.memorymap_main.cpp

  • Hi Tom,

    For accessing registers clock should be enabled.Writing 1 to run will turn on the clock for PWM module

    & will turned off clock by writing 0 to run.For other sysfs interface, clock enabled before accessing registers

    & disable after. So accessing registers with clock disabled will throw "Bus error".

    Thanks avinash

  • Thanks for the response. I'd also like to be able to enable the clock by writing to it directly(the enables in CLKCONFIG and CLKSTATUS), but I still get a bus error. Is there another clock I have to enable first that might block my ability to write to ePWMCLK_EN and ePWMCLK_EN_ACK?

    -Tom

  • Hi,

    Can you please check register CM_PER_EPWMSS0_CLKCTRL.

    This has to enabled, as this is controlling clock for pwmss0 modules.

    Like this, there will be CM_PER_EPWMSS1_CLKCTRL & CM_PER_EPWMSS2_CLKCTRL

    registers also. These registers are enbled clock on writing 1 to run.

    Please see details in TRM at

    8.1.12.1.37 CM_PER_EPWMSS0_CLKCTRL Register (offset = D4h) [reset = 30000h]

    Thanks Avinash

  • I am also working with Tom on this problem.  We are able to write the registers now by enabling clocks through the CM_PER registers.  However, there is no output on the pins normally.  If we turn on the PWM channel with the sysfs interface (i.e. "echo 1 > run" from the command line), we can then control frequency, duty cycle, etc., by writing registers directly.  That means that we are mapped to the correct location and writing all the correct registers.  But why is there no output without the "run" command?  What does that command do through sysfs?  I have tried to find the source code, but it doesn't appear to be installed on the BeagleBone Angstrom distro.

    Thanks.