예제 #1
0
/***********************************************************************
 * rpiPWM1::rpiPWM1(double Hz, unsigned int cnts, double duty, unsigned int m)
 * This is the overloaded constructor. First, it mmaps the registers in 
 * Physical memory responsible for configuring GPIO, PWM and the PWM clock.
 * It then sets the frequency, PWM resolution, duty cycle & pwm mode as 
 * per the parameters provided.
 * 
 * It then calls configPWM1Pin() to configure GPIO18 to ALT5 to allow it to
 * output PWM1 waveforms. 
 * Finally  configPWM1() is called to configure the PWM1 peripheral
 * Parameters: - Hz (double) - Frequency
 *             - cnts (unsigned int) - PWM resolution (counts)
 *             - duty (double) - Duty Cycle as a percentage
 *             - m     (int) - PWM mode (can be either 1 for PWMMODE (rpiPWM1::PWMMODE) 
 *               or 2 for MSMODE (rpiPWM1::MSMODE) 
 ***********************************************************************/
rpiPWM1::rpiPWM1(double Hz, unsigned int cnts, double duty, int m)
{
  this->clk = mapRegAddr(CLOCK_BASE);
  this->gpio = mapRegAddr(GPIO_BASE);
  this->pwm = mapRegAddr(PWM_BASE);
  
   if( (cnts <= 0) || (cnts > UINT_MAX) ) {
   printf("counts value must be between 0-%d\n",UINT_MAX);
   exit(1);
  }
  
  if ((Hz < 1e-5) || (Hz > 19200000.0f)){
    printf("frequency value must be between 0-19200000\n");
    exit(1);
  }
  
  if( (duty < 1e-5) || (duty> 99.99999) ) {
    printf("dutyCycle value must be between 0-99.99999\n");
    exit(1);
  }
  
  if( (m != PWMMODE) && (m != MSMODE) ) {
    printf("mode must be either PWMMODE(1) or MSMODE(2)\n");
    exit(1);
  }
  
  this->frequency = Hz;
  this->counts = cnts;
  this->dutyCycle = duty;
  this->mode = m;
  configPWM1Pin();
  configPWM1();  
}
예제 #2
0
/***********************************************************************
 * rpiPWM1::rpiPWM1()
 * This is the Default constructor. First, it mmaps the registers in 
 * Physical memory responsible for configuring GPIO, PWM and the PWM clock.
 * It then sets the frequency to 1KHz, PWM resolution to 256, duty 
 * cycle to 50% & pwm mode to 'PWMMODE'
 * It then calls configPWM1Pin() to configure GPIO18 to ALT5 to allow it to
 * output PWM1 waveforms. 
 * Finally  configPWM1() is called to configure the PWM1 peripheral
 ***********************************************************************/
rpiPWM1::rpiPWM1()
{
  this->clk = mapRegAddr(CLOCK_BASE);// map PWM clock registers into memory
  this->pwm = mapRegAddr(PWM_BASE); //map PWM registers into memory
  this->gpio = mapRegAddr(GPIO_BASE);// map GPIO registers into memory 
  this->frequency = 1000.0; // set frequency
  this->counts = 256; //set PWM resolution
  this->dutyCycle = 50.0; //set duty cycle
  this->mode = PWMMODE; // set pwm mode
  configPWM1Pin(); //configure GPIO18 to ALT15 (PWM output)
  configPWM1();   // configure PWM1
}
예제 #3
0
/*******************************************************************
 * Default constructor....
 * Simply calls mapRegAddri() function to map the physical addresses
 * of the GPIO registers into local process memory
 * 
 * Parameters - None
 * Return Value - None
 *******************************************************************/
mmapGpio::mmapGpio(){
	this->gpio = mapRegAddr(GPIO_BASE);
}