--
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 beagleboard...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beagleboard/25541a5f-3b5c-4a5d-92fe-3b70bfd8cb48%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
with the parameters: P8_36, fastslew, output, pulldown, mode2.
This gave me the overlay code:
/*
* Copyright (C) 2013 CircuitCo
À * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This is a template-generated file from BoneScript
*/
/dts-v1/;
/plugin/;
/ {
compatible = "ti,beaglebone", "ti,beaglebone-black";
/* identification */
part-number = "BS_PWM_P8_36_0x2";
/* state the resources this cape uses */
exclusive-use =
/* the pin header uses */
"P8.36",
/* the hardware IP uses */
"ehrpwm1A";
fragment@0 {
target = <&am33xx_pinmux>;
__overlay__ {
bs_pwm_P8_36_0x2: pinmux_bs_pwm_P8_36_0x2 {
pinctrl-single,pins = <0x0c8 0x2>;
};
};
};
fragment@1 {
target = <&ocp>;
__overlay__ {
bs_pwm_test_P8_36 {
compatible = "pwm_test";
pwms = <&ehrpwm1 0 500000 0>;
pwm-names = "PWM_P8_36";
pinctrl-names = "default";
pinctrl-0 = <&bs_pwm_P8_36_0x2>;
enabled = <1>;
duty = <0>;
status = "okay";
};
};
};
};
which I copied in /lib/firmware/bspwm_P8_36_2-00A0.dts
and compiled with dtc -O dtb -o /lib/firmware/bspwm_P8_36_2-00A0.dtbo -b 0 -@
/lib/firmware/bspwm_P8_36_2-00A0.dts
After that I loaded the am33xx_pwm as well as the compiled overlay but again I
was unable to produce any output by writing the already mentioned values into
the files.
Loading the overlay also generated read only files which I was unable to write
any values into, even after running chmod a+w and writing as root.
--
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 beagleboard...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beagleboard/3be86866-0420-446e-abd3-c6b65131da24%40googlegroups.com.
- you say that I still have to manually export pwm0 and pwm1. You mean after mounting your cape, I will have to write a 0 and 1 into the export file of the pwmchip<number> directories in /sys/class/pwm?
This site has a table most of the way down that explains it. However do keep in mind that it's outdated material, and that now we only have pwm0, and pwm 1 per module. No, pwm0, pwm1, pwm2, pwm3, etc. Also the pwm directories will no longer show in /sys/class/pwm, but will now show in /sys/class/pwm/pwmchipX where X is the chip number.
I'm not 100% sure, but ns sounds reasonable. However, I'm not sure the time period matters so much, as duty_cycle is a percentage of period. So in our circuit here, which is reverse logic. A period of 2000 with a duty_cycle of 2000 would be 100% duty_cycle. BUt I was just driving LEDs with it, not a stepper motor or anything period critical.
Anyway, you can always hook the output up to a scope . . .
Hello William,
so I tried your approach however without success. Here is how I did it:
0: PF---- -1
1: PF---- -1
2: PF---- -1
3: PF---- -1
4: P-O-L- 0 Override Board Name,00A0,Override Manuf,BB-UART1
5: P-O-L- 1 Override Board Name,00A0,Override Manuf,BB-UART5
6: P-O-L- 2 Override Board Name,00A0,Override Manuf,univ-wph cd /sys/class/pwm
for chip in *; do for i in 0 1; do echo ${i} > ${chip}/export; done ; done root@beaglebone:/sys/class/pwm/pwmchip0/pwm0# ls
duty_cycle enable period polarity power uevent cd /sys/class/pwm
for chip in *; do for i in 0 1; do echo 100000 > ${chip}/pwm${i}/period; echo 50000 > ${chip}/pwm${i}/duty_cycle; echo 1 > ${chip}/pwm${i}/enable ; done ; doneroot@beaglebone:/sys/class/pwm/pwmchip0/pwm0# cat enable period duty_cycle
1
100000
50000
However I could not produce any outputs. I measure all channels with an oscilloscope, but unfortunately no success. Do you know what I did wrong?
--
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 beagleboard...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beagleboard/220d6ab8-6015-442c-92c9-293e0eed5df5%40googlegroups.com.
root@beaglebone:/lib/firmware# ls /sys/devices/platform/ocp/
40300000.ocmcram 47400000.usb 48046000.timer 4819c000.i2c 48302000.epwmss 4a100000.ethernet modalias ocp:P9_22_pinmux
40302000.ocmcram_nocache 48022000.serial 48048000.timer 481a0000.spi 48304000.epwmss 4a300000.pruss ocp:l4_wkup@44c00000 of_node
44e07000.gpio 48030000.spi 4804a000.timer 481aa000.serial 48310000.rng 4c000000.emif ocp:P8_13_pinmux power
44e09000.serial 48038000.mcasp 4804c000.gpio 481ac000.gpio 49000000.edma 53100000.sham ocp:P8_19_pinmux subsystem
44e0b000.i2c 4803c000.mcasp 48060000.mmc 481ae000.gpio 49800000.tptc 53500000.aes ocp:P9_14_pinmux uevent
44e35000.wdt 48042000.timer 480c8000.mailbox 48200000.interrupt-controller 49900000.tptc 56000000.sgx ocp:P9_16_pinmux
44e3e000.rtc 48044000.timer 480ca000.spinlock 48300000.epwmss 49a00000.tptc driver_override ocp:P9_21_pinmux
dtc -O dtb -o /lib/firmware/univ-wph-00A0.dtbo -b 0 -@ /lib/firmware/univ-wph-00A0.dtsimport os
import glob
from collections import OrderedDict
from pprint import pprint
os.chdir('/sys/class/pwm/')
chips = glob.glob('pwmchip*')
pwms = ['PWM0A', 'PWM0B', 'PWM1A', 'PWM1B', 'PWM2A', 'PWM2B']
nbpwm = 0
pwm_dict = OrderedDict()
for chip in chips:
npwm = int(open('{}/npwm'.format(chip)).read())
if npwm == 2:
for i in [0, 1]:
path = '/sys/class/pwm/{}/'.format(chip)
open(path+'export', 'w').write(str(i))
pwm_dict[pwms[nbpwm+i]] = '{}/pwm{}/'.format(path, i)
nbpwm += 2
pprint(pwm_dict)root@beaglebone:~# ./PWM_4.4.py
{'PWM0A': '/sys/class/pwm/pwmchip0//pwm0/',
'PWM0B': '/sys/class/pwm/pwmchip0//pwm1/',
'PWM1A': '/sys/class/pwm/pwmchip2//pwm0/',
'PWM1B': '/sys/class/pwm/pwmchip2//pwm1/',
'PWM2A': '/sys/class/pwm/pwmchip4//pwm0/',
'PWM2B': '/sys/class/pwm/pwmchip4//pwm1/'}
root@beaglebone:~# config-pin P9_14 pwm
root@beaglebone:~# cd /sys/class/pwm/pwmchip2/pwm0/
root@beaglebone:/sys/class/pwm/pwmchip2/pwm0# ls
duty_cycle enable period polarity power uevent
root@beaglebone:/sys/class/pwm/pwmchip2/pwm0# echo 1000000 > period
root@beaglebone:/sys/class/pwm/pwmchip2/pwm0# echo 200000 > duty_cycle
root@beaglebone:/sys/class/pwm/pwmchip2/pwm0# echo 1 > enable
and I got the correct PWM on my oscilloscope, hope it helps, good luck !
Samuel
Hi
PWM red_pwm("48304000.epwmss/48304200.pwm/pwm/pwmchip*/pwm0");GPIO: read failed to open file : No such file or directory#ifndef PWM_H_
#define PWM_H_
#include<string>
using std::string;
#define PWM_PATH "/sys/devices/platform/ocp/"
#define PWM_PERIOD "period"
#define PWM_DUTY "duty_cycle"
#define PWM_POLARITY "polarity"
#define PWM_RUN "enable"
namespace exploringBB {
class PWM {
public:
enum POLARITY{ ACTIVE_LOW=0, ACTIVE_HIGH=1 };
private:
string name, path;
float analogFrequency; //defaults to 100,000 Hz
float analogMax; //defaults to 3.3V
public:
PWM(string pinName);
virtual int setPeriod(unsigned int period_ns);
virtual unsigned int getPeriod();
virtual int setFrequency(float frequency_hz);
virtual float getFrequency();
virtual int setDutyCycle(unsigned int duration_ns);
virtual int setDutyCycle(float percentage);
virtual unsigned int getDutyCycle();
virtual float getDutyCyclePercent();
virtual int setPolarity(PWM::POLARITY);
virtual void invertPolarity();
virtual PWM::POLARITY getPolarity();
virtual void setAnalogFrequency(float frequency_hz) { this->analogFrequency = frequency_hz; }
virtual int calibrateAnalogMax(float analogMax); //must be between 3.2 and 3.4
virtual int analogWrite(float voltage);
virtual int run();
virtual bool isRunning();
virtual int stop();
virtual ~PWM();
private:
float period_nsToFrequency(unsigned int);
unsigned int frequencyToPeriod_ns(float);
};
} /* namespace exploringBB */
#endif /* PWM_H_ */#include "PWM.h"
#include "util.h"
#include <cstdlib>
namespace exploringBB {
PWM::PWM(string pinName) {
this->name = pinName;
this->path = PWM_PATH + this->name + "/";
this->analogFrequency = 100000;
this->analogMax = 3.3;
}
int PWM::setPeriod(unsigned int period_ns){
return write(this->path, PWM_PERIOD, period_ns);
}
unsigned int PWM::getPeriod(){
return atoi(read(this->path, PWM_PERIOD).c_str());
}
float PWM::period_nsToFrequency(unsigned int period_ns){
float period_s = (float)period_ns/1000000000;
return 1.0f/period_s;
}
unsigned int PWM::frequencyToPeriod_ns(float frequency_hz){
float period_s = 1.0f/frequency_hz;
return (unsigned int)(period_s*1000000000);
}
int PWM::setFrequency(float frequency_hz){
return this->setPeriod(this->frequencyToPeriod_ns(frequency_hz));
}
float PWM::getFrequency(){
return this->period_nsToFrequency(this->getPeriod());
}
int PWM::setDutyCycle(unsigned int duty_ns){
return write(this->path, PWM_DUTY, duty_ns);
}
int PWM::setDutyCycle(float percentage){
if ((percentage>100.0f)||(percentage<0.0f)) return -1;
unsigned int period_ns = this->getPeriod();
float duty_ns = period_ns * (percentage/100.0f);
this->setDutyCycle((unsigned int) duty_ns );
return 0;
}
unsigned int PWM::getDutyCycle(){
return atoi(read(this->path, PWM_DUTY).c_str());
}
float PWM::getDutyCyclePercent(){
unsigned int period_ns = this->getPeriod();
unsigned int duty_ns = this->getDutyCycle();
return 100.0f * (float)duty_ns/(float)period_ns;
}
int PWM::setPolarity(PWM::POLARITY polarity){
return write(this->path, PWM_POLARITY, polarity);
}
void PWM::invertPolarity(){
if (this->getPolarity()==PWM::ACTIVE_LOW) this->setPolarity(PWM::ACTIVE_HIGH);
else this->setPolarity(PWM::ACTIVE_LOW);
}
PWM::POLARITY PWM::getPolarity(){
if (atoi(read(this->path, PWM_POLARITY).c_str())==0) return PWM::ACTIVE_LOW;
else return PWM::ACTIVE_HIGH;
}
int PWM::calibrateAnalogMax(float analogMax){ //must be between 3.2 and 3.4
if((analogMax<3.2f) || (analogMax>3.4f)) return -1;
else this->analogMax = analogMax;
return 0;
}
int PWM::analogWrite(float voltage){
if ((voltage<0.0f)||(voltage>3.3f)) return -1;
this->setFrequency(this->analogFrequency);
this->setPolarity(PWM::ACTIVE_LOW);
this->setDutyCycle((100.0f*voltage)/this->analogMax);
return this->run();
}
int PWM::run(){
return write(this->path, PWM_RUN, 1);
}
bool PWM::isRunning(){
string running = read(this->path, PWM_RUN);
return (running=="1");
}
int PWM::stop(){
return write(this->path, PWM_RUN, 0);
}
PWM::~PWM() {}
} /* namespace exploringBB */#include "util.h"
#include<iostream>
#include<fstream>
#include<sstream>
using namespace std;
namespace exploringBB {
/**
* Helper write function that writes a single string value to a file in the path provided
* @param path The sysfs path of the file to be modified
* @param filename The file to be written to in that path
* @param value The value to be written to the file
* @return
*/
int write(string path, string filename, string value){
ofstream fs;
fs.open((path + filename).c_str());
if (!fs.is_open()){
perror("GPIO: write failed to open file ");
return -1;
}
fs << value;
fs.close();
return 0;
}
/**
* Helper read function that reads a single string value to a file from the path provided
* @param path The sysfs path of the file to be read
* @param filename Filename The file to be written to in that path
* @return
*/
string read(string path, string filename){
ifstream fs;
fs.open((path + filename).c_str());
if (!fs.is_open()){
perror("GPIO: read failed to open file ");
}
string input;
getline(fs,input);
fs.close();
return input;
}
/**
* Private write method that writes a single int value to a file in the path provided
* @param path The sysfs path of the file to be modified
* @param filename The file to be written to in that path
* @param value The int value to be written to the file
* @return
*/
int write(string path, string filename, int value){
stringstream s;
s << value;
return write(path,filename,s.str());
}
} /* namespace exploringBB */
--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to a topic in the Google Groups "BeagleBoard" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/beagleboard/u9We3y-yrZc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to beagleboard+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beagleboard/CAOCHtYjyeg16%3D_dK7Nkh2-R2gOEgE4x-hzEEzKT4i7FZW%2BPszw%40mail.gmail.com.