|
|
@ -7,7 +7,7 @@ Pca9685::Pca9685(i2c_ch1_pImpL* i2c, ErrorHandler* err)
|
|
|
|
errorHandling = err;
|
|
|
|
errorHandling = err;
|
|
|
|
m_isExternalClock = 0;
|
|
|
|
m_isExternalClock = 0;
|
|
|
|
m_oscillatorFreq = PCA9685_FREQUENCY_OSCILLATOR;
|
|
|
|
m_oscillatorFreq = PCA9685_FREQUENCY_OSCILLATOR;
|
|
|
|
setPwmFreq(200);
|
|
|
|
setPwmFreq(48);
|
|
|
|
m_currentLED = PCA9685_LED_PWM_REG_START;
|
|
|
|
m_currentLED = PCA9685_LED_PWM_REG_START;
|
|
|
|
|
|
|
|
|
|
|
|
errorHandling->addNewError(-1,__FILE__,"Selected duty cycle is too big",KILL);
|
|
|
|
errorHandling->addNewError(-1,__FILE__,"Selected duty cycle is too big",KILL);
|
|
|
@ -16,10 +16,13 @@ Pca9685::Pca9685(i2c_ch1_pImpL* i2c, ErrorHandler* err)
|
|
|
|
errorHandling->addNewError(-4,__FILE__,"Selected PWM frequency is too slow",SPARE);
|
|
|
|
errorHandling->addNewError(-4,__FILE__,"Selected PWM frequency is too slow",SPARE);
|
|
|
|
errorHandling->addNewError(-5,__FILE__,"Oscillator frequency can't be 0 or inferior to 0",KILL);
|
|
|
|
errorHandling->addNewError(-5,__FILE__,"Oscillator frequency can't be 0 or inferior to 0",KILL);
|
|
|
|
errorHandling->addNewError(-6,__FILE__,"Oscillator frequency cant't be higher than 50 MHz",KILL);
|
|
|
|
errorHandling->addNewError(-6,__FILE__,"Oscillator frequency cant't be higher than 50 MHz",KILL);
|
|
|
|
|
|
|
|
errorHandling->addNewError(-7,__FILE__,"On Duty Cyle if greater than alowed maximum of 4095",SPARE);
|
|
|
|
|
|
|
|
errorHandling->addNewError(-8,__FILE__,"Off Duty Cyle if greater than alowed maximum of 4095",SPARE);
|
|
|
|
|
|
|
|
errorHandling->addNewError(-9,__FILE__,"Cumulation of the On & Off Duty Cyle if greater than alowed maximum of 4095",SPARE);
|
|
|
|
|
|
|
|
errorHandling->addNewError(-10,__FILE__,"On & Off Duty Cyle can't be equal to each other",SPARE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*Refere to datasheet page 52
|
|
|
|
/*Refere to datasheet page 25
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* osc_clock
|
|
|
|
* osc_clock
|
|
|
@ -47,7 +50,7 @@ void Pca9685::setPwmFreq(uint16_t frequency)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
m_currentPrescale = (m_oscillatorFreq / ( 4096 * frequency) ) -1;
|
|
|
|
m_currentPrescale = (m_oscillatorFreq / ( 4096 * frequency) ) -1;
|
|
|
|
|
|
|
|
std::cout << "Prescaler is set to: " << unsigned(m_currentPrescale) << std::endl;
|
|
|
|
sleep();
|
|
|
|
sleep();
|
|
|
|
i2c_pca9685->writeWord(PCA9685_I2C_ADDRESS, PCA9685_REG_PRESCALE, m_currentPrescale);
|
|
|
|
i2c_pca9685->writeWord(PCA9685_I2C_ADDRESS, PCA9685_REG_PRESCALE, m_currentPrescale);
|
|
|
|
wakeup();
|
|
|
|
wakeup();
|
|
|
@ -61,20 +64,48 @@ void Pca9685::setDutyPercent(uint8_t ledNo, uint8_t on, uint8_t off)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void Pca9685::setDutyRaw(uint8_t ledNo, uint8_t on, uint8_t off)
|
|
|
|
void Pca9685::setDutyRaw(uint8_t ledNo, uint16_t on, uint16_t off)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
m_currentLED = PCA9685_LED_PWM_REG_START + (ledNo * PCA9685_LED_NEXT_OFFSET);
|
|
|
|
m_currentLED = PCA9685_LED_PWM_REG_START + (ledNo * PCA9685_LED_NEXT_OFFSET);
|
|
|
|
|
|
|
|
|
|
|
|
std::cout << "Led" <<unsigned(ledNo)<<" ON L : " << unsigned(m_currentLED) << std::endl;
|
|
|
|
if(on > 4095)
|
|
|
|
std::cout << "Led" <<unsigned(ledNo)<<" ON H : " << unsigned(m_currentLED+PCA9685_PWM_ON_H_OFFSET) << std::endl;
|
|
|
|
{
|
|
|
|
std::cout << "Led" <<unsigned(ledNo)<<" OFF L : " << unsigned(m_currentLED+PCA9685_PWM_OFF_L_OFFSET) << std::endl;
|
|
|
|
on = 4095;
|
|
|
|
std::cout << "Led" <<unsigned(ledNo)<<" 0FF H : " << unsigned(m_currentLED+PCA9685_PWM_OFF_H_OFFSET) << std::endl;
|
|
|
|
off = 0;
|
|
|
|
|
|
|
|
errorHandling->handleError(-7,__FILE__);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(off > 4095)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
off = 4095;
|
|
|
|
|
|
|
|
on = 0;
|
|
|
|
|
|
|
|
errorHandling->handleError(-8,__FILE__);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(on + off > 4095)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
off = 4095;
|
|
|
|
|
|
|
|
on = 0;
|
|
|
|
|
|
|
|
errorHandling->handleError(-9,__FILE__);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(on == off)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
off = 4095;
|
|
|
|
|
|
|
|
on = 0;
|
|
|
|
|
|
|
|
errorHandling->handleError(-10,__FILE__);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
i2c_pca9685->writeWord(PCA9685_I2C_ADDRESS, m_currentLED, on & 0xFF);
|
|
|
|
|
|
|
|
i2c_pca9685->writeWord(PCA9685_I2C_ADDRESS, m_currentLED + PCA9685_PWM_ON_H_OFFSET, on >> 8);
|
|
|
|
|
|
|
|
i2c_pca9685->writeWord(PCA9685_I2C_ADDRESS, m_currentLED + PCA9685_PWM_OFF_L_OFFSET, off & 0xFF);
|
|
|
|
|
|
|
|
i2c_pca9685->writeWord(PCA9685_I2C_ADDRESS, m_currentLED + PCA9685_PWM_OFF_H_OFFSET, off >> 8);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Pca9685::setDutyMicroSecond(uint8_t ledNo, uint16_t on, uint16_t off)
|
|
|
|
void Pca9685::setDutyMicroSecond(uint8_t ledNo, uint16_t on, uint16_t off)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Pca9685::setOnOff(uint8_t ledNo, bool onOff, bool invert)
|
|
|
|
void Pca9685::setOnOff(uint8_t ledNo, bool onOff, bool invert)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|