Hi William , TJF, 

Digging into the directories, I found a solution.

WARNING : It's only for kernel 4.1.6 with the newest debian 8.2 image from 
the mighty Robert Nelson. The device tree has been a bit modified according 
to https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-class-pwm

It's a bit ugly but it works. With reference to that page 
http://klaus.ede.hih.au.dk/index.php/BBB_Enabling_PWM : 

Looking for address 48300000 in the memory map, you'll find this is in the 
> L4_PER block, and this is listed as the “PWM subsystem 0″, and 48300200 is 
> the EHR0 PWM channel and 48300100 the eCAP0 PWM. Also, address 4830200 is 
> the “PWM subsystem 1″, and address 4830400 is the “PWM subsystem 2″. 


If I list /sys/devices/platform/ocp/subsystem/devices, I get a list of 
symbolic links :

debian@arm:~$ ls /sys/devices/platform/ocp/subsystem/devices/
40300000.ocmcram         48200000.interrupt-controller  ocp:P8_10_pinmux
44d00000.wkup_m3         48300000.epwmss                ocp:P8_11_pinmux
44e00000.prcm            48300100.ecap                  ocp:P8_12_pinmux
44e07000.gpio            48300180.eqep                  ocp:P8_13_pinmux
44e09000.serial          48300200.ehrpwm                ocp:P8_14_pinmux
44e0b000.i2c             48302000.epwmss                ocp:P8_15_pinmux
44e10000.scm             48302180.eqep                  ocp:P8_16_pinmux
44e10000.scm_conf        48302200.ehrpwm                ocp:P8_17_pinmux
44e10620.control         48304000.epwmss                ocp:P8_18_pinmux
44e10650.cpsw-phy-sel    48304100.ecap                  ocp:P8_19_pinmux
44e10800.pinmux          48304180.eqep                  ocp:P8_26_pinmux
44e11324.wkup_m3_ipc     48304200.ehrpwm                ocp:P9_11_pinmux
44e35000.wdt             4830e000.lcdc                  ocp:P9_12_pinmux
44e3e000.rtc             48310000.rng                   ocp:P9_13_pinmux
47400000.dma-controller  49000000.edma                  ocp:P9_14_pinmux
47400000.usb             4a100000.ethernet              ocp:P9_15_pinmux
47401300.usb-phy         4a101000.mdio                  ocp:P9_16_pinmux
47401400.usb             4a300000.pruss                 ocp:P9_17_pinmux
47401b00.usb-phy         4a334000.pru0                  ocp:P9_18_pinmux
47401c00.usb             4a338000.pru1                  ocp:P9_21_pinmux
48022000.serial          4c000000.emif                  ocp:P9_22_pinmux
48024000.serial          53100000.sham                  ocp:P9_23_pinmux
4802a000.i2c             53500000.aes                   ocp:P9_24_pinmux
48030000.spi             56000000.sgx                   ocp:P9_26_pinmux
48038000.mcasp           alarmtimer                     ocp:P9_27_pinmux
48042000.timer           bone_capemgr                   ocp:P9_30_pinmux
48044000.timer           clk_mcasp0                     ocp:P9_42_pinmux
48046000.timer           clk_mcasp0_fixed               ocp:P9_91_pinmux
48048000.timer           cpufreq-voltdm.0               omap-pcm-audio
4804a000.timer           edma-dma-engine.0              oprofile-perf.0
4804c000.gpio            fixedregulator@0               pm33xx.0
48060000.mmc             hdmi                           pmu
480c8000.mailbox         hdmi_audio@0                   reg-dummy
480ca000.spinlock        leds                           serial8250
4819c000.i2c             musb-hdrc.0.auto               snd-soc-dummy
481a0000.spi             musb-hdrc.1.auto               soc
481a8000.serial          ocp                            soc:mpu
481ac000.gpio            ocp:cape-universal             sound
481ae000.gpio            ocp:l4_wkup@44c00000           tps65217-bl
481cc000.can             ocp:P8_07_pinmux               tps65217-pmic
481d0000.can             ocp:P8_08_pinmux
481d8000.mmc             ocp:P8_09_pinmux


I can from there list the directory according to the memory address from 
the Sitara SRM.  For instance 48300200.ehrpwm.

debian@arm:/sys/devices/platform/ocp/subsystem/devices/48300200.ehrpwm/pwm$ 
ls
pwmchip0


>From there on , I can determine the pwmchip number attributed at boot time. 

As TJF mentioned, there are two channels per EHRPWM, and it's a matter of 
echo 0 or 1 to .../pwmchip0/export as before (o for channel A , 1 for 
channel B).

Programmatically,  I ended up modifying the library from 
https://github.com/SaadAhmad/beaglebone-black-cpp-PWM 
. <https://github.com/SaadAhmad/beaglebone-black-cpp-PWM>

There are a few things that were needed, but the core of the solution looks 
like that : 

Enter code here...void InitPinFS()
        {
            LoadDeviceTreeModule(std::string("cape-universaln")); //Modified 
for kernel 4.1.6 and cape-universaln
            //std::string pinModule = std::string("sc_pwm_") + GetPinName();
            //LoadDeviceTreeModule(pinModule);

            //Find chip name
            std::string m_chipAddress;
            std::string m_pwmNumber;
            //EHRPWM0A
            if (m_pinName == "P9_22" || m_pinName == "P9_31") {
                m_chipAddress = "48300200.ehrpwm";
                m_pwmNumber = "pwm0";
                }
            //EHRPWM0B
            if (m_pinName == "P9_21" || m_pinName == "P9_29") {
                m_chipAddress = "48300200.ehrpwm";
                m_pwmNumber = "pwm1";
                }
            //EHRPWM1A
            if (m_pinName == "P9_14" || m_pinName == "P8_36") {
                m_chipAddress = "48302200.ehrpwm";
                m_pwmNumber = "pwm0";
                }
            //EHRPWM1B
            if (m_pinName == "P9_16" || m_pinName == "P8_34") {
                m_chipAddress = "48302200.ehrpwm";
                m_pwmNumber = "pwm1";
                }
            //EHRPWM2A
            if (m_pinName == "P8_19" || m_pinName == "P8_45") {
                m_chipAddress = "48304200.ehrpwm";
                m_pwmNumber = "pwm0";
                }
            //EHRPWM2B
            if (m_pinName == "P8_13" || m_pinName == "P8_46") {
                m_chipAddress = "48304200.ehrpwm";
                m_pwmNumber = "pwm1";
                }
            //ECAPPWM0
            if (m_pinName == "P9_42") {
                m_chipAddress = "48300100.ecap";
                m_pwmNumber = "pwm0";
                }\
            //EHCAPPWM2
            if (m_pinName == "P9_28") {
                m_chipAddress = "48300200.ecap";
                m_pwmNumber = "pwm0";
                }
            std::string m_chipPath = GetOCPPath() + "subsystem/devices/" + 
m_chipAddress + "/pwm/" ;

            std::string pinInterfacePath = m_chipPath + 
GetFullNameOfFileInDirectory(m_chipPath, "pwmchip") + "/" + m_pwmNumber + 
"/";
            m_dutyFilePath = pinInterfacePath + "duty_cycle";
            m_periodFilePath = pinInterfacePath + "period";
            m_polarityFilePath = pinInterfacePath + "polarity";
            m_runFilePath = pinInterfacePath + "enable";

I haven't looked into the reason why one of the eCAP did not show up, as I 
only need 6 PWM for the project. 

Time for another coffee. 

Thanks a lot for your replies. 

Cheers, 

Pierre-Louis

On Friday, October 23, 2015 at 1:38:27 AM UTC+8, William Hermans wrote:
>
> Heya plc66,
>
> Have you seen this yet ? 
> https://briancode.wordpress.com/2015/01/06/working-with-pwm-on-a-beaglebone-black/
>
> Unfortunately I have yet to use PWMs on the BBB, so can not offer you any 
> first hand experience advice. 
>
> On Thu, Oct 22, 2015 at 8:42 AM, TJF <[email protected] <javascript:>> 
> wrote:
>
>> Hi!
>>
>> I don't know much about the sysfs PWM capabilities. But I know a bit 
>> about the AM335x CPU. It has three PWMSS subsystems, each has a PWM module, 
>> each has two outputs (A and B). So there're six PWM outputs in total. I 
>> guess this is what sysfs supports.
>>
>> Additionaly you can generate PWM pulse trains by the eCAP modules (also 
>> integrated in each PWMSS). AFAIK this isn't supported by sysfs (but 
>> libpruio <http://beagleboard.org/project/libpruio/> can handle that). 
>> Only two eCAP output pins are available on the BBB headers (P9_28 and 
>> P9_42). So you can have a maximum of eight PWM outputs at a time.
>>
>> BR
>>
>> -- 
>> For more options, visit http://beagleboard.org/discuss
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "BeagleBoard" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
For more options, visit http://beagleboard.org/discuss
--- 
You received this message because you are subscribed to the Google Groups 
"BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to