0

I would like to control the speed of various motors using a PIC and PCA9685

This following code allow me to start the rotation but it does not reduce the speed

void pca9685_Set_rate(int address, int rate)
{   
   i2c_start();      
   i2c_write(address);
   i2c_write(MODE1);    
   i2c_write(Sleep);
   i2c_stop();

   i2c_start();      
   i2c_write(address);
   i2c_write(PreScale);
   i2c_write(rate);  
   i2c_stop();

   i2c_start();     
   i2c_write(address);
   i2c_write(MODE1);
   i2c_write(PCA9685AI);       // Set MODE1 back to INT_CLK, AutoIncrement, Normal
   i2c_stop();

   __delay_us(500);              // required for PCA oscillator startup
} 

void pca9685_Set_speed(int address, int line, int speed)
{
    unsigned int on_count  = 0; 
    unsigned int off_count = speed; 

    i2c_start();
    i2c_write(address);
    i2c_write((line*4)+6);
    i2c_write(on_count);           //Writing 8 LSB bits of ON count
    i2c_write(on_count>>8);        //Writing 4 MSB bits of ON count
    i2c_write(off_count);          //Writing 8 LSB bits of OFF count
    i2c_write(off_count>>8);       //Writing 4 MSB bits of ON count    
    i2c_stop();
}

in the main()

enter code here
pca9685_Set_rate(0x80, 0x03); // 1600
ledn = 1;
    pca9685_Set_speed(0x80, ledn, 4095);
    DelayMs(500);
    DelayMs(500);
    DelayMs(500);
    DelayMs(500);
    pca9685_Set_speed(0x80, ledn, 3500);
    DelayMs(500);
    DelayMs(500);
    DelayMs(500);
    DelayMs(500);
    pca9685_Set_speed(0x80, ledn, 3000);
    DelayMs(500);
    DelayMs(500);
    DelayMs(500);
    DelayMs(500);
    pca9685_Set_speed(0x80, ledn, 2500);
    DelayMs(500);
    DelayMs(500);
    DelayMs(500);
    DelayMs(500);
    pca9685_Set_speed(0x80, ledn, 2000);

I am using a single mosfet on PCA9685 out to convert the level to 12V

Could be this the problem ? I must use a tb6612 or a DRV8833 ?

j08691
  • 204,283
  • 31
  • 260
  • 272
  • Have you put an oscilloscope on pin 7 to see if the pulse train looks correct? Did you really intend to write to LED1, and not LED0 (pin 6)? I suppose if it is turning on at all, then the connections are OK. – Tim Roberts Aug 25 '23 at 18:09
  • If I connect a led with a 470ohm in series on the pca9685 out led1, I see a different values of light and I can measure dc voltage from 4.24, 3.6 ... 0.5 but the motor connected after the mosfet work only when the voltage is 4.24. – andrea ciuffoli Aug 25 '23 at 19:35
  • But this is supposed to be a PWM, right? It's not a DAC. It should be a fixed voltage with a varying duty cycle. – Tim Roberts Aug 25 '23 at 21:38

1 Answers1

0

Solved, adding a 2k2 + TIP120 on any output so for each 12v dc fan

The code is ok