Skip to content

Commit

Permalink
Added 2 channels to everything except frequency
Browse files Browse the repository at this point in the history
  • Loading branch information
clausqr committed Jun 17, 2012
1 parent ed362e1 commit f1724b0
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 33 deletions.
Binary file modified Debug/beaglebone-cpp-PWM
Binary file not shown.
Binary file modified Debug/cPWM.o
Binary file not shown.
Binary file modified Debug/main.o
Binary file not shown.
89 changes: 66 additions & 23 deletions cPWM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,43 @@ cPWM::cPWM(int id)
std::stringstream sysfsfile_dutyA;
std::stringstream sysfsfile_dutyB;
std::stringstream sysfsfile_period;
std::stringstream sysfsfile_polarity;
std::stringstream sysfsfile_run;
std::stringstream sysfsfile_request;
std::stringstream sysfsfile_polarityA;
std::stringstream sysfsfile_runA;
std::stringstream sysfsfile_requestA;
std::stringstream sysfsfile_polarityB;
std::stringstream sysfsfile_runB;
std::stringstream sysfsfile_requestB;

sysfsfile_dutyA << SYSFS_EHRPWM_PREFIX << id << SYSFS_EHRPWM_SUFFIX_A << "/" << SYSFS_EHRPWM_DUTY;
sysfsfile_dutyB << SYSFS_EHRPWM_PREFIX << id << SYSFS_EHRPWM_SUFFIX_B << "/" << SYSFS_EHRPWM_DUTY;
sysfsfile_period << SYSFS_EHRPWM_PREFIX << id << SYSFS_EHRPWM_SUFFIX_A << "/" << SYSFS_EHRPWM_PERIOD;
sysfsfile_polarity << SYSFS_EHRPWM_PREFIX << id << SYSFS_EHRPWM_SUFFIX_A << "/" << SYSFS_EHRPWM_POLARITY;
sysfsfile_run << SYSFS_EHRPWM_PREFIX << id << SYSFS_EHRPWM_SUFFIX_A << "/" << SYSFS_EHRPWM_RUN;
sysfsfile_request << SYSFS_EHRPWM_PREFIX << id << SYSFS_EHRPWM_SUFFIX_A << "/" << SYSFS_EHRPWM_REQUEST;
sysfsfile_polarityA << SYSFS_EHRPWM_PREFIX << id << SYSFS_EHRPWM_SUFFIX_A << "/" << SYSFS_EHRPWM_POLARITY;
sysfsfile_runA << SYSFS_EHRPWM_PREFIX << id << SYSFS_EHRPWM_SUFFIX_A << "/" << SYSFS_EHRPWM_RUN;
sysfsfile_requestA << SYSFS_EHRPWM_PREFIX << id << SYSFS_EHRPWM_SUFFIX_A << "/" << SYSFS_EHRPWM_REQUEST;
sysfsfile_polarityB << SYSFS_EHRPWM_PREFIX << id << SYSFS_EHRPWM_SUFFIX_B << "/" << SYSFS_EHRPWM_POLARITY;
sysfsfile_runB << SYSFS_EHRPWM_PREFIX << id << SYSFS_EHRPWM_SUFFIX_B << "/" << SYSFS_EHRPWM_RUN;
sysfsfile_requestB << SYSFS_EHRPWM_PREFIX << id << SYSFS_EHRPWM_SUFFIX_B << "/" << SYSFS_EHRPWM_REQUEST;

std::cout << "new PWM with id " << id << std::endl;
std::cout << "using DutyA file " << sysfsfile_dutyA.str() << std::endl;
std::cout << "using DutyB file " << sysfsfile_dutyB.str() << std::endl;
std::cout << "using period file " << sysfsfile_period.str() << std::endl;
std::cout << "using polarity file " << sysfsfile_polarity.str() << std::endl;
std::cout << "using run file " << sysfsfile_run.str() << std::endl;
std::cout << "using request file " << sysfsfile_request.str() << std::endl;
std::cout << "using Period file " << sysfsfile_period.str() << std::endl;
std::cout << "using PolarityA file " << sysfsfile_polarityA.str() << std::endl;
std::cout << "using RunA file " << sysfsfile_runA.str() << std::endl;
std::cout << "using RequestA file " << sysfsfile_requestA.str() << std::endl;
std::cout << "using PolarityB file " << sysfsfile_polarityB.str() << std::endl;
std::cout << "using RunB file " << sysfsfile_runB.str() << std::endl;
std::cout << "using RequestB file " << sysfsfile_requestB.str() << std::endl;

sysfsfid_dutyA.open(sysfsfile_dutyA.str().c_str());
sysfsfid_dutyB.open(sysfsfile_dutyB.str().c_str());
sysfsfid_period.open(sysfsfile_period.str().c_str());
sysfsfid_polarity.open(sysfsfile_polarity.str().c_str());
sysfsfid_run.open(sysfsfile_run.str().c_str());
sysfsfid_request.open(sysfsfile_request.str().c_str());
sysfsfid_polarityA.open(sysfsfile_polarityA.str().c_str());
sysfsfid_runA.open(sysfsfile_runA.str().c_str());
sysfsfid_requestA.open(sysfsfile_requestA.str().c_str());
sysfsfid_polarityB.open(sysfsfile_polarityB.str().c_str());
sysfsfid_runB.open(sysfsfile_runB.str().c_str());
sysfsfid_requestB.open(sysfsfile_requestB.str().c_str());


}
Expand Down Expand Up @@ -85,29 +97,60 @@ int cPWM::Period(int d)
return 1;
}

int cPWM::Polarity(int d)
int cPWM::PolarityA(int d)
{
std::cout << "PWM"<< id << ", polarity set to " << d << std::endl;
cPWM::polarity = d;
sysfsfid_polarity << d << std::endl;
std::cout << "PWMA"<< id << ", polarity set to " << d << std::endl;
cPWM::polarityA = d;
sysfsfid_polarityA << d << std::endl;
return 1;
}

int cPWM::Run()
int cPWM::RunA()
{
std::cout << "PWM"<< id << " started" << std::endl;
sysfsfid_run << "1" << std::endl;
std::cout << "PWMA"<< id << " started" << std::endl;
sysfsfid_runA << "1" << std::endl;
cPWM::runA = 1;
return 1;
}

int cPWM::Stop()
int cPWM::StopA()
{
std::cout << "PWM"<< id << " stopped" << std::endl;
sysfsfid_run << "0" << std::endl;
std::cout << "PWMA"<< id << " stopped" << std::endl;
sysfsfid_runA << "0" << std::endl;
cPWM::runA = 0;
return 1;
}

int cPWM::PolarityB(int d)
{
std::cout << "PWMB"<< id << ", polarity set to " << d << std::endl;
cPWM::polarityB = d;
sysfsfid_polarityB << d << std::endl;
return 1;
}

int cPWM::RunB()
{
std::cout << "PWMB"<< id << " started" << std::endl;
cPWM::runB = 1;
sysfsfid_runB << "1" << std::endl;
return 1;
}

int cPWM::StopB()
{
std::cout << "PWMB"<< id << " stopped" << std::endl;
cPWM::runB = 0;
sysfsfid_runB << "0" << std::endl;
return 1;
}

cPWM::~cPWM()
{
std::cout << "PWMA"<< id << " stopped" << std::endl;
sysfsfid_runA << "0" << std::endl;
std::cout << "PWMB"<< id << " stopped" << std::endl;
sysfsfid_runB << "0" << std::endl;
std::cout << "called cPWM destructor of cPWM " << id << std::endl;
}

Expand Down
23 changes: 16 additions & 7 deletions cPWM.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ class cPWM {
int dutyA;
int dutyB;
int period;
int polarity;
int polarityA;
int polarityB;
int runA;
int runB;
/*****************************************
ehrpwm.0:0
│   ├── duty_ns
Expand Down Expand Up @@ -48,9 +51,12 @@ std::stringstream sysfs_file;
std::ofstream sysfsfid_dutyA;
std::ofstream sysfsfid_dutyB;
std::ofstream sysfsfid_period;
std::ofstream sysfsfid_polarity;
std::ofstream sysfsfid_run;
std::ofstream sysfsfid_request;
std::ofstream sysfsfid_polarityA;
std::ofstream sysfsfid_runA;
std::ofstream sysfsfid_requestA;
std::ofstream sysfsfid_polarityB;
std::ofstream sysfsfid_runB;
std::ofstream sysfsfid_requestB;


public:
Expand All @@ -60,9 +66,12 @@ std::stringstream sysfs_file;
int DutyA(int d);
int DutyB(int d);
int Period(int d);
int Polarity(int d);
int Run();
int Stop();
int PolarityA(int d);
int RunA();
int StopA();
int PolarityB(int d);
int RunB();
int StopB();
};

} /* namespace cPWM */
Expand Down
27 changes: 24 additions & 3 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Created on: Jun 13, 2012
* Author: claus
*
*/
*/
#include "cPWM.h"
#include <iostream>
#include <unistd.h>
Expand All @@ -20,17 +20,38 @@ int main()
{
a[i] = new cPWM::cPWM(i);
}

/*
a[0]->Period(20000000);
a[0]->DutyA( 1000000);
a[0]->Polarity(1);
a[0]->Run();
usleep(100000); //pausa de 0.1s=100,000us
a[0]->DutyA( 1500000);
a[0]->Stop();
*/
for (int i=0; i<3; i++)
{
// delete(a[i]);
a[i]->Period(20000000);
//usleep(100000); //pausa de 0.1s=100,000us
a[i]->DutyA( 1000000);
//usleep(100000); //pausa de 0.1s=100,000us
a[i]->DutyB( 1000000);
//usleep(100000); //pausa de 0.1s=100,000us
a[i]->PolarityA(1);
//usleep(100000); //pausa de 0.1s=100,000us
a[i]->RunA();
//usleep(100000); //pausa de 0.1s=100,000us
a[i]->RunB();
//usleep(100000); //pausa de 0.1s=100,000us

}
usleep(10000000);
for (int i=0; i<3; i++)
{
delete(a[i]);
a[i]->StopA();
a[i]->StopB();
//usleep(100000); //pausa de 0.1s=100,000us
}

return 0;
Expand Down

0 comments on commit f1724b0

Please sign in to comment.