CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

PCA9685
Goto page Previous  1, 2, 3, 4  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Oct 16, 2019 3:59 am     Reply with quote

Sterngleiter wrote:

I do not understand what you want. The library is running.
I just add new function as well as described above.

They want you to post the main() function for your program. An example
is shown below. Also, if you have a main.h with the #fuses in it, post
that too.

Example:
Code:

#include <main.h>
#include <pca9685.h>

void main()
{
int16 pwm = 0;

pca9685_init(LEDDRV1);
pca9685_brightness(LEDDRV1,22,0);

while(true)
  {
   output_toggle(PIN_D5);
   delay_ms(5);

   if(pwm < 4095)
     {
      pwm += 5;
     }
   else
     {
      pwm = 0;
     }

   pca9685_send(LEDDRV1,pwm,1);
  }
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Oct 18, 2019 11:38 pm     Reply with quote

It looks like he gave up. I made it work. I bought a cheap clone of the
Adafruit PCA9685 board on Amazon at this link:
https://www.amazon.com/gp/product/B01D1D0CX2/ref=ppx_yo_dt_b_asin_title_o04_s00?ie=UTF8&psc=1

Hardware connections to the 6-pin connector on the PCA9685 board:
Code:

PCA9685
Board
Pin     Connected to this signal on the PIC board:

GND.....Ground 
OE......Ground
SCL.....SCL1 (RB4) on 16F1847 (pin 10 on DIP pkg)
SDA.....SDA1 (RB1) on 16F1847 (pin 7 on DIP pkg)
VCC.....+5v
V+......No Connection

Board schematic: https://imgur.com/a/gyB5d85

I only have one green LED connected to the PCA9685 board, as follows:
Code:

                                Anode    Cathode
PWM0 pin on PCA9685 board ------------>|-----------
                                      LED         |
                                                -----
                                                 ---
                                                  -

The board has built-in 220 ohm series resistors, one for each PWM output.
There are 16 separate PWM outputs on this board. They are on the
yellow header strips.

In the program below, LED0 turns on for 500ms and then turns off for
500ms, continuously. His claim is that if he called the All LEDS off function
then the leds would never go on again. That's not true for my test.
It works fine. It blinks the LED at a 1 Hz rate continuously.
Code:
#include <16F1847.h>
#fuses NOWDT
#use delay(internal=4M)

#include <pca9685.h>

//=================================
void main()
{

pca9685_init(PCA9685);

while(TRUE)
  {
   pca9685_send(PCA9685, 3072, 0);   // 75% duty cycle
   delay_ms(500); 
 
   PCA9685AllLedOff(PCA9685);
   delay_ms(500); 
  }

Ttelmah



Joined: 11 Mar 2010
Posts: 19481

View user's profile Send private message

PostPosted: Sat Oct 19, 2019 12:35 am     Reply with quote

Well done.

I have a strong suspicion that he doesn't actually have a working program,
but has 'partial' operation because of mis-configuration.....
Sterngleiter



Joined: 07 Jan 2013
Posts: 90

View user's profile Send private message

PostPosted: Wed Oct 23, 2019 1:23 am     Reply with quote

I have the same board. The same attitude. I say for the thousandth time that everything is going to turn on again after all. I'm not a beginner either.
Sterngleiter



Joined: 07 Jan 2013
Posts: 90

View user's profile Send private message

PostPosted: Wed Oct 23, 2019 1:25 am     Reply with quote

of course I have a program. In the library is also a main () if you read more closely.
Ttelmah



Joined: 11 Mar 2010
Posts: 19481

View user's profile Send private message

PostPosted: Wed Oct 23, 2019 2:12 am     Reply with quote

Yes, there is a main, _but not a processor configuration_. A main will not
run properly without this.
Sterngleiter



Joined: 07 Jan 2013
Posts: 90

View user's profile Send private message

PostPosted: Wed Oct 23, 2019 2:22 am     Reply with quote

If the configuration was wrong, the i2c would still work. I said, extra for you, it all works when I address the led's individually but as soon as I switch off with allledoff, nothing works anymore.
Ttelmah



Joined: 11 Mar 2010
Posts: 19481

View user's profile Send private message

PostPosted: Wed Oct 23, 2019 2:57 am     Reply with quote

The point is that you have to be doing something wrong. Show us.
Show us the header you are using, and the code you are using.

PCM_programmer has tested the function, and it is working for him. This
implies there has to be something wrong either in the hardware or software
that you are using that causes the issue. We cannot help unless you show
us exactly what you are using. Functions used, PIC setup, and
hardware details.
temtronic



Joined: 01 Jul 2010
Posts: 9217
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Oct 23, 2019 4:34 am     Reply with quote

As others have said, we, need your small, complete, compilable program. We need this so we can 'cut/paste'compile and test' your EXACT code.
It's the only way we can 100% debug and correct whatever's wrong.

Same as someone saying 'I have car trouble' and they say batteries good, radio works, it starts and other things BUT it's ONLY when you SEE the complete car, you SEE the parking brake is ON.

I'm thinking you've got a simple syntax or typing error (I'm GREAT making those, even after 2 decades...) as PCM_P has coded/compiled/tested the 'all/on/off' functions and they work for him. Since the I2C Scanner program works, it shouldn't be hardware and you've said the LEDs operate fine in other modes. I don't know if it's a 'white space' or 'ghost code' issue, again that will ONLY show up if we have YOUR code.

Jay
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Oct 23, 2019 1:38 pm     Reply with quote

Jay, we can't get anything coherent out of this guy.

Here he says everything turns on.
Sterngleiter wrote:

I say for the thousandth time that everything is going to turn on again after all.

Here he says he can't turn anything on.
Sterngleiter wrote:
My problem is why can i not turn all led on, after all off.

Complete total opposite phrases.

Here Ttelmah asks him for his code that shows the #include line for the PIC
and the #fuses, and the main().
Ttelmah wrote:

Show us _your_ code that gives the chip setup, and calls the library functions.

He replies:
Sterngleiter wrote:
I do not understand what you want.


Here he says:
Sterngleiter wrote:
If the configuration was wrong, the i2c would still work.

Wrong. If there is no oscillator fuse, the PIC will typically not run.
If it's not running, there is no i2c.

We are not going to get anything useful out of this guy.
PrinceNai



Joined: 31 Oct 2016
Posts: 478
Location: Montenegro

View user's profile Send private message

PostPosted: Wed Oct 23, 2019 2:03 pm     Reply with quote

To all the guys that replied on this topic: you are all extremely patient, way beyond normal.

To OP: those guys here are so full of knowledge that I'd be more than happy with 1% of that. For my needs, I'd consider myself a good enough programmer. On top of that, they are willing to share that knowledge. Every day, on every topic. They answer and try to help everyone. But I have never seen somebody on this forum that practically demands help and on the other hand makes it so difficult for them. Argues, even.

Waste of time.
Sterngleiter



Joined: 07 Jan 2013
Posts: 90

View user's profile Send private message

PostPosted: Mon Nov 04, 2019 11:34 am     Reply with quote

Hello again. I did not think that this topic would trigger such a discussion. First I have to apologize for my English. More than half is Google Tranlator. Of course I share my code. I did not find it necessary because the PCM Programmer has already posted similar. I do not want to offend anyone here. My program is running. I can control the LEDs individually and switch off all at the same time. After I run the command PCA9685AllLedOff (PCA9685); PCA9685 does not react to the commands either individually

Code main.h
Code:

#include <18F45K80.h>
//#device ADC=16

#FUSES NOWDT                    //No Watch Dog Timer

#use delay(internal=8MHz)
#use i2c(Master,Fast,sda=PIN_C4,scl=PIN_C3)

Code main.c
Code:

#include <main.h>
#include <pca9685.h>

void main()
 {
  port_a_pullups(0xFF);
  port_b_pullups(0xFF);
  pca9685_init(LEDDRV1);
  pca9685_brightness(LEDDRV1,100,15);
  pca9685_brightness(LEDDRV1,100,0);
  long pwm = 0;
 
  while(true)
     {
      output_toggle(PIN_D5);
      delay_ms(5);
       
      // pca9685_send_all(LEDDRV1);
      /* if (!input(pin_b0)){
            pca9685_brightness(LEDDRV1,22,0);
            pca9685_send(LEDDRV1,pwm,1);
            pca9685_send(LEDDRV1,500,2);
            pca9685_send(LEDDRV1,2000,3);} */

      if (!input(pin_b0)){
         pca9685_brightness(LEDDRV1,25,15);
         pca9685_brightness(LEDDRV1,25,0);
         }
 
      if (!input(pin_b1)){
         pca9685_brightness(LEDDRV1,50,15);
         pca9685_brightness(LEDDRV1,50,0);
         }
     
      /* if (!input(pin_b2)){
            PCA9685AllLedOn(LEDDRV1);
         } */
           
      if (!input(pin_b3)){
           PCA9685AllLedOff(LEDDRV1);
         }
     }
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19481

View user's profile Send private message

PostPosted: Mon Nov 04, 2019 12:53 pm     Reply with quote

What are your pull-up resistors on the I2C bus?.
To run 'fast', may be a problem if your pullups are too large.
Sterngleiter



Joined: 07 Jan 2013
Posts: 90

View user's profile Send private message

PostPosted: Mon Nov 04, 2019 1:04 pm     Reply with quote

ok, I could try with 4k7. I ask my question better with PCA9685AllLedOff (LEDDRV1); I turn off all LEDs. how do I have to write all-led-on registers so that they glow with 50%, for example, or do I have to control them individually? But there is a register with all-led-on address FA and FB
temtronic



Joined: 01 Jul 2010
Posts: 9217
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Nov 04, 2019 4:19 pm     Reply with quote

OK, I don't have the chip but read the datasheet
From that I'd try
FA 0b01111111
FB 0b00001111

On page 25, I see that address FA is the upper 8 bits of the 'intensity' of ALL LEDS, and the lower 4 bits of address of the 'intensity'.
FB, bit 4 is the ALL ON FULL bit, it needs to be '0' ,zero, off .

If this does work, then you can 'cut code' to take any 12 bit 'intensity' and put into the 2 registers as needed.

Hope this works

Jay
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2, 3, 4  Next
Page 3 of 4

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group