writePWMFrequency() command not generating PWM signal on Raspberry Pi (Raspberry Pi Support Package)

4 Ansichten (letzte 30 Tage)
I am using a Raspberry Pi Compute module 4 with the Raspberry Pi support Package to interface with some IO. I need to output a PWM signal from the PI, for interfacing with a drive. I can successfully generate a PWM signal with the writePWMDutyCycle() command, but not with the writePWMFrequency() or writePWMVoltage() commands. I have hooked it up to a scope (don't have a great way to get the scope picture to my PC without some trouble). But I can generate the desired PWM frequency for about 200ms if I first send a writePWMDutyCycle() command first, and then the writePWMFrequency() or writePWMVoltage() command afterwards. (The Frequency is very consistent and exactly at the desired value for that 200ms). Then the PWM signal cuts off, like it is only working just for the moment the command is issued and then drops out. All the other IO and Buses seem to be working as intended, and I can write the pin high and low without it dropping out. I am running Full Debian Bullseye (32bit, Legacy), as anything newer than that or 64-bit would not work properly for me with the PI support package. But with that instance, I was able to get all the packages installed and interface with the PI no problem. I am also using a Elastel EG500 shield which basically converts the IO from 0-3.3v to a 24v pull-down IO interface. All signs point to an issue with the command, but I can't open the commands to compare the Duty Cycle version with the Frequency Version.
% This outputs the right PWM frequency for 200ms before stopping with no commands issued
MainRasp = raspi();
PUL = 22;
configurePin(MainRasp, PUL, 'PWM');
writePWMDutyCycle(MainRasp, PUL, .2);
writePWMFrequency(MainRasp, PUL, 4000);
% This does not output any PWM signal
MainRasp = raspi();
PUL = 22;
configurePin(MainRasp, PUL, 'PWM');
writePWMFrequency(MainRasp, PUL, 4000);
%This ouputs a PWM signal, but the frequency cannot be precisely controlled
MainRasp = raspi();
PUL = 22;
configurePin(MainRasp, PUL, 'PWM');
writePWMDutyCycle(MainRasp, PUL, .2);
  1 Kommentar
David Streit
David Streit am 1 Apr. 2024
Bearbeitet: David Streit am 1 Apr. 2024
Update: I was able to get some functionality by setting the frequency first and then the voltage as shown below. I was only able to go up to about 1KHz before the signal quality would degrade to basically be always on (should be able to go much higher), but that may be a limit of the switching frequency of the shield I am using. I don't see any mention of this in the documentation, so I don't think it's supposed to work this way, but should be good enough to work. Note that the Voltage needs to be set as low as possible, as it seems like (looking at the scope) that it basically is using that as the "base" voltage, and then the frequency command pulses up from there, so you will erode away your signal clarity with larger voltage values.
PUL = 20;
PulseFreq = 1000;
configurePin(MainRasp, PUL, 'PWM');
writePWMFrequency(MainRasp,PUL,PulseFreq)
writePWMVoltage(MainRasp,PUL,.1)
pause(2)
writePWMVoltage(MainRasp,PUL,0)

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu MATLAB Support Package for Raspberry Pi Hardware finden Sie in Help Center und File Exchange

Produkte


Version

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by