How to control fine PWM on AI64?

hello.
I am trying to control a WS2813 LED STRIP.
On the Raspberry Pi, it works well with the help of several modules.

I was wondering if there is a python module to control the PWM on the AI64.

/dev/bone/pwm/2/b
capture duty_cycle enable period polarity power uevent

With the above files, I tried to control the PWM with sysfs.

enabled pwm0(overlay edit) and checked the waveform on osiloscope.

But I can’t seem to get it to produce an 8-bit waveform, let alone a 24-bit one.

No matter how many times you enter duty_cycle and change enable 0 and 1 for a short period of time, you’ll get a lot of waveforms on the oscilloscope.
So I can’t run 0code and 1code over and over again.

create a waveform like ‘01010101’ in Python?


1 Like

@ALEX_PARK ,

I am by far an awesome programmer here but…

  1. I think there are timers
  2. In /dev/bone/, there should be another form of usage for timers and/or counters.
  3. I will go and research these ideas now, i.e. as I have not used them or used them recently.

For instance:

The primary difference between the PWM module and the timer module is that the timer module has only one compare register and can only be configured to trigger a hardware output event on one comparison value at any time.

The above quote is from nxp.com. I am sure there are many ideas floating around w/ nxp and ti and other research that can be derived. I can test this soon. My programming skills, as I say, are weak and my Oscilloscope work is not good (I have an o-scope that likes 5v).

Anyway, I am researching how in fact one can come to the short wave nonfluctuating PWM signal… This will be good for me. I need to learn more of the intricacies instead of all the “fun.”

Oh!

Nordic Semiconductor Infocenter and instead of just pushing random logic ideas at you, I will get out the O-Scope if you will walk me through it.

It seems no matter how much or how little I learn at some intervals, I retain little.

So…I hope this is helpful. If not, please try those counters and timers in /dev/bone/.

That is why hard working people like those people are around… To make my life easier! I will get the o-scope out and try it… Give me time and please reply to me by my screen name so I can see the ideas, updates, and gestures.

Seth

Update

So, what is the main goal? Should I try to use a motor in this theory? I will look up how to get an 8-bit waveform going or a 24-bit one too…

I will try some source that has given insight from guidance. Until I get this set up done, I can send over some ideas when you want (my testing of ideas)…

1 Like

@silver2row
Thanks for the reply.
First of all my goal is to get the LED STRIP working.
create a 0 code, 1 code from a PWM running at 800khz and export a 24 bit waveform.

I saw your answer and looked up the TDA4VM manual.
Enhanced High Resolution Pulse-Width Modulator Module (eHRPWM) and was wondering if you know anything about this.

Ah…
BONE-PWM0 is ehrpwm0_a,b (P8_13, 19).
I using P8_13 (ehrpwm0_b) and need to understand EHRPWM first.

1 Like

From TI.com, I am sure there should be plenty of ideas. If you get into Device Tree Compiler lingo, I am out. I am still learning that also…

I am setting up now to figure out how to get your end goal… Why? B/c, I think I should know about PWM, Counters, and Timers.

I just figured the comparator stuck to the am335x or TDA4VM has this ability to proceed w/ what you and I are discussing here.

eHRPWM is useful. Do I know the ins and outs of every way to port it to the source from hardware, no. I cannot guide you in this manner.

Seth

P.S. I am almost fully attached now and cannot wait to see what you say. It is obvious you are more skilled but…

  1. Learning is up there w/ helping.
  2. Vice versa
  3. I think I can take away some lessons from our discussions.
1 Like

Oh…I don’t care.
I’m not an embedded developer, I’m just trying to understand PWM behavior and the goal is to get the LED STRIP working on AI64.

I don’t mind if I’m late in replying, I’m in a non-English speaking country so I can’t understand your intentions 100%, but I’ll try to find some resources and give it a go.

1 Like

No intentions except for pure fun!

Here are some photos to make sure you do not think I am goofing w/ you…

Seth

Oh! Photos!

eQEP2!

Here…for now!

Update

No eQEP2 or any eQEP counters or timers to use for now. I need to update my image and so on. BBL!

One More Update Until…

I was incorrect. I thought the work was already done. I was incorrect.

So, should we help out a bit?

If you can help, I’d appreciate it.

This is the waveform I tested.

In yellow, we have AI64 repeatedly send a 0 code and a 1 code from Python, but only a 0 code is output multiple times. (My intention is to have 0 code output once, and then 1 code).

Blue is the waveform from the Raspberry Pi sending PWM to the LED STRIP.

(yellow)
I coded to create a waveform with period and duty_cycle, but it didn’t work.

(Blue)
If you look closely at the waveforms, you can see the waveforms with 0 code and 1 code. (The part with the long HIGH is the 0 code part)

I want to export a waveform like the blue one to AI64’s PWM.

UPDATE


Can’t Python run below 55us?

I’ll have to make it in C++.

1 Like

Hello,

Not tonight but soon. I need to find the correct image that beagleboard.org provided to handle sysfs and their builds. Until then, I am a bit out. C/C++ is something I was going to mention earlier but…

I can tell from programming that C is faster to use on the end user compared to Python3.

Also…I will get on the image process first, then build from that point forward, and then report back.

I thought it was going to be as easy as 1-2-3 but the images I have found so far are not allowing me to use the peripherals of the TDA4VM and so on…

Seth

P.S. Your Tektronix is far superior to my Rigol. I have two channels, a smaller screen, and the software for it is a bit dated. 2006. Anyway, updates on the way (not now though). Sleep time!

1 Like

Thanks for your help as always.
This is where I ate lunch a little while ago. :smiley:

For now, I’ll try my hand at writing some C++ code.
Good night!

1 Like

Okay…and we are back,

@ALEX_PARK , I found the correct image w/ the ehrpwm modules located on it…

If you go and get an image w/ /opt/dtbs/ located in that file, use make && sudo make install_arm64.

That should make it accessible for you to use those modules. Now, for the timers and eQEP modules, I have not found out how to utilize them yet, i.e. as I am not in charge of porting the hardware to DTS format nor could I do it anyway.

Seth

P.S. I think BONE-PWM{0-2}.dtbo is not the same thing. Is BONE-PWM1 the same as ehrpwm?

Okay. So, w/out further evidence here, I am posting a photo of period and duty_cycle on the ehrpwm channel at P9.25.

I will read more in time and report back. For now, that is what I am getting on my set up. I have been reading on my oscilloscope details. The guide book is okay, I guess. Anyway, I will produce a better reference waveform later in the week, i.e. Sat. or Sun.

I have to get ready for the ole day.

1 Like

https://docs.beagleboard.org/latest/books/beaglebone-cookbook/03displays/displays.html#writing-to-a-neopixel-led-string-using-the-prus

That will help w/ a LED strip (I think).

I hope you had a good weekend.

https://elinux.org/Beagleboard:BeagleBone_cape_interface_spec#PWM

I got the info from the link above.

BONE-PWM2.dts applied. and connected P8.13.

In my list of HEADER PINs, it is specified as EHRPWM0_B.

Hello @ALEX_PARK ,

The weekend was okay. Finally…rest. Anyway, in the new image (Bookworm), there are two pins that are listed as ehrpwm on the /boot/firmware/overlays/ files that one can add in w/ the /boot/firmware/extlinux/extlinux.conf file.

From my knowledge, this does not specifically mean that the other PWMSS pins are not ehrpwm enabled but maybe they are not.

I do not know right now what to make of it.

Seth

P.S. BeagleBone cape interface spec — BeagleBoard Documentation

I will test again and see if I cannot get better results like we discussed earlier last week.

Update

Here is the Bookworm page on this forums w/ the ehrpwm peripheral access overlays:

Another Update and Ideas…

  1. I have all my PWM overlays enabled which includes the ehrpwm overlays at P9.25/P8.37.
  2. Do you think testing PWM1 and then ehrpwm at P9.25 will encounter different results on the oscilloscope?
  3. If I encounter different results, I will reply w/ that info. and add photos in the mix.

I had some issues w/ the software on my oscilloscope. Bugs. I should report them to Rigol. I had to erase every form of source from Rigol to get rid of the pop-up installs. Blah.

Anyway, I can test right now even though I need to learn the divisible part of my connections w/ the Rigol in mind. Updates on the way. Also, the link I posted can get you about 200MHz loops from the PRU…

1 Like

@silver2row
I am using bullseye because of EDGEAI.

https://forum.beagleboard.org/t/arm64-debian-11-x-bullseye-monthly-snapshots-2023-08-05/32318/3

I happened to be testing BBAI64-P9_25-ehrpwm4_b.dtbo.
If I have any updates, I’ll share them.

1 Like

Sir,

Just a heads up here. These photos so far mean nothing to me. I need to research exactly what they mean.

The first photo is the ehrpwm overlay being used w/:

  1. echo 500000 > period
  2. echo 10000 > duty_cycle
  3. echo 1 > enable

The second photo is the pwm at file /dev/bone/pwm/1/a/.

  1. echo 500000 > period
  2. echo 10000 > duty_cycle
  3. echo 1 > enable

So far, and as I update firmware to the scope (phew), I have noticed that at the same time and at the same voltage, I have different ideas presented.

Oh and I know what you said earlier about my angle on this discussion which is listed further up the post. No issue but my intentions are to learn more and use this discussion to handle that learning.

Photo 1 of the ehrpwm ss:

and…

Photo 2 of PWMSS:

I will be researching the time and voltage aspects to each photo and output so I can learn. Hopefully, this helps a bit to the trained eye.

Seth

P.S. If you need additional info. from me on the oscilloscope, please let me know.

@silver2row

I’m not an embedded developer.

More and more, I’m not sure I’m on the right track.

First, I realized that it’s probably not possible to simply change the values of period, duty_cycle, and enable.

Second, there is too little information about EHRPWM. I have no idea what to do.

I want to make the 0 and 1 codes 1.25us apart, blowing up just one set of 24 bits. :sob: :sob:

But it’s harder than just swapping duty_cycle and enable.
In Python or C++, generating 0 code and 1 code once produces multiple waveforms.

I need to clear my head and move on to other things.

update

Changing the duty_cycle produces 19 waveforms.
(duty_cycle 800 > change duty_cycle 400)
make 24us delay.

1 Like

Hello…you can change them to suit your needs. In source, it is a bit more complicated. You can always try a shell script too (bash).

Just for reference, my photos were the result of using the command line commands: echo 1 > enable

When you say 0 and 1, I am assuming you mean on and off. GPIO is good for this idea. It is either 0 or 1 and can help you w/ ease.

For instance…

timing the GPIO to on and then timing it to off may prove valuable.

There is a built-in called time. You can use the sleep function in the built-in time.

i.e. from time import sleep as s

So, you can sleep instead of just on/off the GPIO to 1/0.

Seth

P.S. For LEDs on and off is easy w/ Python3 and sleep from time, i.e. GPIO wise here.

W/ PWM, one can sleep again w/ time in Python3 or usleep in C w/ microseconds.

#!/bin/bash

pwm_path="/dev/bone/pwm/bbai64_P9_25_ehrpwm4_b/"

while true; do
  echo 400 > "${pwm_path}duty_cycle"
  echo 800 > "${pwm_path}duty_cycle"
done

I created a bash script to alternate the duty cycle between 400 and 800.
Instead of generating and changing one waveform, we generate and change 43 waveforms.

delay 44us

Ps. 24us delay on C++ / 44us delay on bash script / 41us delay on python while

1 Like

Okay!

You are getting somewhere…

So, if anything, are there any ideas outside of what you know that I can be of service to currently?

I mean…

How can I help?

Seth

P.S. Optimization?

1 Like

As I said above, I want to make 24 bits of 0 code, 1 code with 1.25us period (800khz), and when I make one set of 24, I want to send it to PWM.
(If I make 24 bits, I will have 24 waveforms).

I was wondering if there is any other way to do this besides changing the duty_cycle to echo.
For example, DMA?

I’m very grateful for the help. @silver2row