BeagleY-AI and GPIO Pins

Are you sure that board has PWM on it, the pin out shows pwm1 &0.

However, the spec sheet does not mention any thing about PWM. So, that would lead me to make a loose assumption that PWM is either PRU or Software. Hence, your code would not work on that board, regardless. If you can post more info about that I would like to see it. I ordered the same board you have and was getting ready to create a roadmap and the lack of PWM has raised some questions.

UPDATE:
@silver2row
I was wrong and just found it starting on page 1947 of the TRM, they call it EPWM. Might be why I did not see it. Loaded an overlay and tried to turn it on manually using sys and it might need more than period, duty, cycle to get it going.

fred@bby1:/sys/class/pwm/pwmchip0$ tree
.
β”œβ”€β”€ device -> ../../../23100000.pwm
β”œβ”€β”€ export
β”œβ”€β”€ npwm
β”œβ”€β”€ power
β”‚   β”œβ”€β”€ async
β”‚   β”œβ”€β”€ autosuspend_delay_ms
β”‚   β”œβ”€β”€ control
β”‚   β”œβ”€β”€ runtime_active_kids
β”‚   β”œβ”€β”€ runtime_active_time
β”‚   β”œβ”€β”€ runtime_enabled
β”‚   β”œβ”€β”€ runtime_status
β”‚   β”œβ”€β”€ runtime_suspended_time
β”‚   └── runtime_usage
β”œβ”€β”€ pwm0
β”‚   β”œβ”€β”€ capture
β”‚   β”œβ”€β”€ duty_cycle
β”‚   β”œβ”€β”€ enable
β”‚   β”œβ”€β”€ period
β”‚   β”œβ”€β”€ polarity
β”‚   β”œβ”€β”€ power
β”‚   β”‚   β”œβ”€β”€ async
β”‚   β”‚   β”œβ”€β”€ autosuspend_delay_ms
β”‚   β”‚   β”œβ”€β”€ control
β”‚   β”‚   β”œβ”€β”€ runtime_active_kids
β”‚   β”‚   β”œβ”€β”€ runtime_active_time
β”‚   β”‚   β”œβ”€β”€ runtime_enabled
β”‚   β”‚   β”œβ”€β”€ runtime_status
β”‚   β”‚   β”œβ”€β”€ runtime_suspended_time
β”‚   β”‚   └── runtime_usage
β”‚   └── uevent
β”œβ”€β”€ subsystem -> ../../../../../../class/pwm
β”œβ”€β”€ uevent
└── unexport

1 Like

Sorry…

I was just wondering about the source and if the C syntax was okay or if I went overboard with another odd entailment.

That source was for another board with PWM on it.

I was trying to receive some feedback on it.

Seth

There’s nothing inherently wrong with those functions, you certainly may do it like that. Its clear and explicit, which is always good. There are however a couple of comments regarding style I could make -
1: You are masking any errors
2: The 3 functions are quite similar, you dont have to combine them, but it’s worth considering.

If it were me, I would probably write it more like this (depending on the specific circumstances)

const char* enablePath = "/dev/beagle/pwm/P9_16/enable";
const char* periodPath = "/dev/beagle/pwm/P9_16/period";
const char* dutyPath = "/dev/beagle/pwm/P9_16/duty_cycle";


int myFunc(const char* path, int val) {
  FILE *theFile;
  int ret;

  theFile = fopen(path, "w");
  if (theFile == NULL)
    return -1;
  ret = fseek(theFile, 0, SEEK_SET);
  if (ret == 0)
    ret = fprintf(theFile, "%d", val);

  fclose(theFile);
  return ret;
}

  // use it like this
  ret = myFunc(brightPath, 1);
1 Like

If it works it is EXCELLENT.

I run clion and pycharm for writing code, both are worth the money. Once you get some time on it you will appreciate it even more.

This is turning into a can of worms, only kernel module loaded is for the fan and I could not find any for the pwm.

$ find /lib/modules/$(uname -r) -name "pwm-*.ko"

1 Like

Hello…thank you for the additions. I will look into it.

Do you want me to apply that command to my board to see about the PWM modules?

Seth

P.S. @foxsquirrel , just let me know if this is what you demand. I do not even think I used apt to install the headers just yet.

No, mine is loaded with the same image. Just posted that to share with you. I might have over looked something.

As it stands at this moment, pwm on that board is going to be a waste of time. Part of the problem is doing that on a linux os is very difficult. You can work on it via registers however you will have a jalopy.

That EPWM module is very powerful according the specs, it will sync and has configurable input / capture. Most certainly worth looking into if your project would do a $M a year in sales. It most likely will have to be some bare-metal/rtos.

Best option at this point is to buy some stepper drive controls and connect them to gpio that are active. You can bit bang a square wave for stepping and have couple different frequencies for high/low rpm. Then use 2 more lines for enable and direction.

I found some really cheap ones on amazon 2 for $16 and free shipping. Suppose to handle a nema 17 stepper, when those arrive I will work on getting them up on that board.

1 Like

Yaya…no money on my end so far. So, testing and testing until blue in the face is a key notion.

Thank you for making me understand the ePWM module a bit more.

I have this stepper drive. Three GPIO pins and go-go-go. It is nice for now but…

  1. I cannot incorporate it into a full build just yet.
  2. The β€œHat” is needing to supply the BeagleY-AI with power to make things work.

I am not willing to move forward with powering the BeagleY-AI via this β€œHat” and for good reason.

Like someone stated, I have intermittent power failures on the action of the β€œHat” most likely due to the 5v pin onboard powering the Chip without specific level translation. Right?

Seth

P.S. I have searched the fs so far and found some very tidy and neat things placed in specific files. Can I use them yet? Nope. Still trying over here. $M!

Powering a SBC from any node other than its dedicated power input can be a bit risky. Usually, header pins are positioned on the output side of the regulator, and the traces there tend to be smaller. Ideally, power conductors should have larger surface areas to handle greater power capacity safely and efficiently.

1 Like

You are right. I was a risk taker with this board upfront.

I need to be more relaxed and reserved now.

Seth

P.S. I will try to read the files and see if I get anywhere.

1 Like

I posted on Ti e2e forum regarding the pwm.

This is the response I got, its about device tree config.

diff --git a/arch/arm64/boot/dts/ti/k3-j721e-main.dtsi b/arch/arm64/boot/dts/ti/k3-j721e-main.dtsi
index 8675a4887..619532f9e 100644
--- a/arch/arm64/boot/dts/ti/k3-j721e-main.dtsi
+++ b/arch/arm64/boot/dts/ti/k3-j721e-main.dtsi
@@ -71,8 +71,74 @@
                        #mux-control-cells = <1>;
                        mux-reg-masks = <0x4000 0x8000000>, /* USB0 to SERDES0/3 mux */
                                        <0x4010 0x8000000>; /* USB1 to SERDES1/2 mux */
-           };
+               };
+
+               tbclk_ctrl: tbclk_ctrl@4140 {
+                       compatible = "syscon";
+                       reg = <0x4140 0x18>;
+               };
+       };
+
+       ehrpwm_tbclk: clk0 {
+               compatible = "ti,am654-ehrpwm-tbclk";
+               #clock-cells = <1>;
+               ti,tbclk-syscon = <&tbclk_ctrl>;
+       };
+
+       ehrpwm0: pwm@3000000 {
+               compatible = "ti,am654-ehrpwm", "ti,am3352-ehrpwm";
+               #pwm-cells = <3>;
+               reg = <0x0 0x3000000 0x0 0x100>;
+               power-domains = <&k3_pds 83 TI_SCI_PD_EXCLUSIVE>;
+               clocks = <&ehrpwm_tbclk 0>, <&k3_clks 83 0>;
+               clock-names = "tbclk", "fck";
+       };
+
+       ehrpwm1: pwm@3010000 {
+               compatible = "ti,am654-ehrpwm", "ti,am3352-ehrpwm";
+               #pwm-cells = <3>;
+               reg = <0x0 0x3010000 0x0 0x100>;
+               power-domains = <&k3_pds 84 TI_SCI_PD_EXCLUSIVE>;
+               clocks = <&ehrpwm_tbclk 1>, <&k3_clks 84 0>;
+               clock-names = "tbclk", "fck";
+       };
+
+       ehrpwm2: pwm@3020000 {
+               compatible = "ti,am654-ehrpwm", "ti,am3352-ehrpwm";
+               #pwm-cells = <3>;
+               reg = <0x0 0x3020000 0x0 0x100>;
+               power-domains = <&k3_pds 85 TI_SCI_PD_EXCLUSIVE>;
+               clocks = <&ehrpwm_tbclk 2>, <&k3_clks 85 0>;
+               clock-names = "tbclk", "fck";
+       };
+
+       ehrpwm3: pwm@3030000 {
+               compatible = "ti,am654-ehrpwm", "ti,am3352-ehrpwm";
+               #pwm-cells = <3>;
+               reg = <0x0 0x3030000 0x0 0x100>;
+               power-domains = <&k3_pds 86 TI_SCI_PD_EXCLUSIVE>;
+               clocks = <&ehrpwm_tbclk 3>, <&k3_clks 86 0>;
+               clock-names = "tbclk", "fck";
+       };
+
+       ehrpwm4: pwm@3040000 {
+               compatible = "ti,am654-ehrpwm", "ti,am3352-ehrpwm";
+               #pwm-cells = <3>;
+               reg = <0x0 0x3040000 0x0 0x100>;
+               power-domains = <&k3_pds 87 TI_SCI_PD_EXCLUSIVE>;
+               clocks = <&ehrpwm_tbclk 4>, <&k3_clks 87 0>;
+               clock-names = "tbclk", "fck";
+       };
+
+       ehrpwm5: pwm@3050000 {
+               compatible = "ti,am654-ehrpwm", "ti,am3352-ehrpwm";
+               #pwm-cells = <3>;
+               reg = <0x0 0x3050000 0x0 0x100>;
+               power-domains = <&k3_pds 88 TI_SCI_PD_EXCLUSIVE>;
+               clocks = <&ehrpwm_tbclk 5>, <&k3_clks 88 0>;
+               clock-names = "tbclk", "fck";
        };
+ };

All the 6 instances are enabled as part of the above patch.

All the CONFIGs related to EHRPWM are already enabled. So by adding the above DT nodes
one should be able to look at the sysfs nodes.

Best Regards,
Keerthy
1 Like

Configuring the beagley-ai for pwm is documented here:
https://docs.beagleboard.org/books/beaglebone-cookbook/04motors/motors.html#id12
https://docs.beagleboard.org/boards/beagley/ai/demos/beagley-ai-using-pwm.html#beagley-ai-using-pwm

1 Like

Hey guys…

Seth here. @bbbpaul and @foxsquirrel , do you two think that using PWM instead of all GPIO pins is necessary? I mean…

From what the source and datasheet are saying, GPIO is all that is needed…

I am just not sure as of now.

Seth

You can just use gpio, it depends on what you need.

Gpio timing is not particularly accurate on linux. For low speed this is probably not an issue, but for higher speeds or high accuracy (which is kind of why you’d use steppers in the first place) it might be a deal breaker.

Pwm may be easier to code for too, depending on your point of view, as you can set the frequency and just let it run. You would possibly still need accurate timing or pulse counting though. Again it depends on your needs.

If you’re unsure - try it and see if it works for you.

That looks like BBB.

The first link is bbb and bby, there’s a tab part way down the page to switch between the 2. The second is bby in more detail.

Yes, I seen that. Its faux pwm, not using the hardware, just bit banging gpio. If you only want to run blinky and fans it is perfect for that. When you have motors and such involved its not a serious option other than demonstration purposes.

Posted this on e2e and best response was a snippet for device tree overlay… If Ti cannot explicitly state a meaning full response it becomes very clear what game(s) they are playing with the β€œlow value” customer base that are not strategically important to them .

Apart from playing around you do not want to do any real motor control with Linux. You need to use a real time processor such as a PRU or dedicated hardware.

This is 10 years old now, but is quite impressive - from around 30 seconds in.
BeagleBone Black PRU motor control.

1 Like

That is definitely neat…

I do not think I am up for that amount of data exchange just yet. I was having some data exchange times with the BeagleCPP lib. I found online.

I got some aspects to the BeagleCPP lib. to work on the BBB but not all.

Anyway, thank you for showing me what is possible with the BBB and PRUs onboard.

Seth

P.S. Ben, I guess I am going to have to rethink it again…