6 if (strcmp(DEVICE_TYPE, "ramips") == 0) {
7 gpio = new FastGpioOmega2();
9 gpio = new FastGpioOmega();
13 FastPwm::FastPwm(int freq, int duty, unsigned int cycles)
18 _SetupPeriods(freq, duty, cycles);
20 //Instantiate the GPIO object
22 if (strcmp(DEVICE_TYPE, "ramips") == 0) {
23 gpio = new FastGpioOmega2();
25 gpio = new FastGpioOmega();
29 FastPwm::~FastPwm(void)
34 void FastPwm::Reset(void)
40 void FastPwm::_SetupPeriods(int frequency, int duty, unsigned int cycles)
44 // convert the datatypes
45 freq = (double) frequency;
46 dutyCycle = (double)duty / 100.0f;
48 // find the period (in ms)
49 period = (1.0f/freq) * 10000; // 1000
51 // find the low and high periods based on the duty-cycle
52 periodHigh = period * dutyCycle;
53 periodLow = period - periodHigh; //can also be: period * (1.0f - dutyCycle);
55 if ( cycles != 0 ) myCycles = cycles; else myCycles = 0;
57 // note that setup has occured
60 if (verbosityLevel > 0) {
61 printf ( "PWM Setup:: frequency = %d, duty-cycle = %d%%\nperiod = %.2f, period hi = %.2f, period lo = %.2f\n",
71 void FastPwm::Pwm (int pinNum)
74 _SetupPeriods(DEFAULT_FREQ, DEFAULT_DUTY_CYCLE, 0);
81 void FastPwm::Pwm (int pinNum, int freq, int duty, unsigned int cycles)
83 _SetupPeriods(freq, duty, cycles);
89 void FastPwm::_Pwm (int pinNum)
91 // set the pin to output
92 gpio->SetDirection(pinNum, 1);
97 if ( myCycles != 0 ) myCycles --;
98 if ( myCycles == 1 ) break;
100 //// HIGH part of cycle
101 gpio->Set(pinNum, 1);
105 gpio->Set(pinNum, 0);
110 void FastPwm::_Sleep (double length)
112 // sleep function uses microseconds
113 int value = (int)(length * 1000);