<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="pl-pl">
<link rel="self" type="application/atom+xml" href="https://forum.atnel.pl/feed.php?f=4&amp;t=19461&amp;mode" />

<title>ATNEL tech-forum</title>
<link href="https://forum.atnel.pl/index.php" />
<updated>2017-11-03T14:09:51+01:00</updated>

<author><name><![CDATA[ATNEL tech-forum]]></name></author>
<id>https://forum.atnel.pl/feed.php?f=4&amp;t=19461&amp;mode</id>
<entry>
<author><name><![CDATA[wrobel111]]></name></author>
<updated>2017-11-03T14:09:51+01:00</updated>
<published>2017-11-03T14:09:51+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=19461&amp;p=198229#p198229</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=19461&amp;p=198229#p198229"/>
<title type="html"><![CDATA[Re: PCA9685 + ATmega8 problem]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=19461&amp;p=198229#p198229"><![CDATA[
Dzięki za pomoc, faktycznie adres to 0x80. Próbowałem już go nawet wcześniej lecz nie działało. Okazało się, że atmega miała wyłamana nóżkę od SCL i dlatego całość nie działała. Była w podstawce więc nie widziałem tego kompletnie.<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=870">wrobel111</a> — 3 lis 2017, o 14:09</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[Zealota]]></name></author>
<updated>2017-10-26T20:46:06+01:00</updated>
<published>2017-10-26T20:46:06+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=19461&amp;p=197805#p197805</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=19461&amp;p=197805#p197805"/>
<title type="html"><![CDATA[Re: PCA9685 + ATmega8 problem]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=19461&amp;p=197805#p197805"><![CDATA[
Prawdopodobnie to jest przyczyna Twoich kłopotów:<br /><br /><a href="https://obrazkiforum.atnel.pl/16487/8a6561c4996f8059df6e9f05d0f656e2.jpg"  class="postlink"><img src="https://obrazkiforum.atnel.pl/thumb/16487/8a6561c4996f8059df6e9f05d0f656e2.jpg" alt="Obrazek" /></a><br /><br />Podstawowy adres ( słowo 8 bit ) to jest <strong>0x80</strong>, a nie <strong>0x40</strong>.<br /><br />W tym obrazku jest też zaszyta jeszcze jedna ważna informacja: &quot;Hardware selectable&quot;.<br />Nie wnikałem w notę tego układu, ale pewnie jest możliwość ustawienia zworkami adresu urządzenia, tak by jedną szyną sterować większą matrycę takich układów.<br />Jesteś pewien, że u Ciebie to 000000?<br /><br />Aż się prosi, żeby użyć tego:<br /><!-- l --><a class="postlink-local" href="http://forum.atnel.pl/topic19430.html" >topic19430.html</a><!-- l --><br />by otrzymać potrzebne informacje tj właściwy adres Twojego urządzenia <img src="https://forum.atnel.pl/images/smilies/icon_e_smile.gif" alt=":)" title="Szczęśliwy" /><p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=16487">Zealota</a> — 26 paź 2017, o 20:46</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[wrobel111]]></name></author>
<updated>2017-10-26T17:06:24+01:00</updated>
<published>2017-10-26T17:06:24+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=19461&amp;p=197785#p197785</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=19461&amp;p=197785#p197785"/>
<title type="html"><![CDATA[PCA9685 + ATmega8 problem]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=19461&amp;p=197785#p197785"><![CDATA[
Witam wszystkich,<br />mam problem ze sterowaniem układem PCA9685 za pomocą atmegi 8. Gdy testuję ten układ za pomocą gotowej biblioteki pod arduino to wszystko działa poprawnie. Usiłowałem więc przenieść całość typowo pod atmegę 8 niestety z marnym skutkiem. Siedzę juz kilka dni nad tym i nadal nic <img src="https://forum.atnel.pl/images/smilies/icon_e_sad.gif" alt=":(" title="Smutny" />  Poniżej zamieszczam kod źródłowy. Pisałem na podstawie: <!-- m --><a class="postlink" href="http://www.ccsinfo.com/forum/viewtopic.php?t=47908" >http://www.ccsinfo.com/forum/viewtopic.php?t=47908</a><!-- m --> . Usiłowałem tez przerabiać bibliotekę adafruit z arduino (<a href="https://www.adafruit.com/product/815"  class="postlink">https://www.adafruit.com/product/815</a>) lecz także nie działało<br /><br />Pomóżcie proszę mi się z tym uporać.<br /><br />Adres mojego sterownika to 0x40, taki po przez arduino działa.<br /><br />Pozdrawiam<br /><br />main.c<br />[syntax=c]#define F_CPU 8000000UL  //definiujemy F_CPU na 8MHz <br />#include &lt;avr/io.h&gt;<br />#include &lt;util/delay.h&gt;<br />#include &lt;stdio.h&gt;<br />#include &quot;TWI.h&quot;<br />#include &quot;pca9685.h&quot;<br /><br />void main()<br />{<br />i2c_Init();<br />    pca9685_init(LEDDRV1);<br />    while(1)<br />    {<br />        _delay_ms(20);<br />for (uint16_t pwm = 0; pwm &lt;= 4096; pwm++) {<br />pca9685_send(LEDDRV1,pwm,0);<br />}<br /><br /><br />for (uint16_t pwm2 = 0; pwm2 &lt;= 4096; pwm2++) {<br />pca9685_send(LEDDRV1,pwm2,1);<br />}<br />      <br />        //PCA9685AllLedOff(LEDDRV1);<br />    }<br /><br />}[/syntax]<br /><br />TWI.h<br />[syntax=c]void i2c_Init()<br />{<br />DDRC&amp;= ~(1&lt;&lt;4);<br />DDRC&amp;= ~(1&lt;5); // input state for now<br /><br />PORTC &amp;= ~(1&lt;&lt;4);<br />PORTC &amp;= ~(1&lt;&lt;5); // disables pull up<br />// pull up resistors are external<br /><br />TWBR = 1;    <br />TWSR = 0b00000011; // prescale 64,<br />TWCR = 0b01000101; // i2c on, interrupt enable, ack enable<br /><br />//TWAR = 0b00111010; // slave address for accelerometer<br />// apparently this is only used for slave mode, but keep it here<br />}<br /><br />void i2c_Stop()<br />{<br />while ((TWCR &amp; _BV(TWINT)) == 0);<br />TWCR = _BV(TWINT) | _BV(TWSTO) | _BV(TWEN); // stop<br />}<br /><br />void i2c_Start()<br />{<br />while((TWCR &amp; _BV(TWINT)) == 0); // wait<br />TWCR = _BV(TWINT) | _BV(TWSTA) | _BV(TWEN); // start<br />}<br /><br />void i2c_SLA_R()<br />{<br />TWDR = 0b00111011;<br />while ((TWCR &amp; _BV(TWINT)) == 0);<br />TWCR = _BV(TWINT) | _BV(TWEN); // clear int to start transmission<br />}<br /><br />void i2c_SLA_W()<br />{<br />TWDR = 0b00111010;<br />while ((TWCR &amp; _BV(TWINT)) == 0);<br />TWCR = _BV(TWINT) | _BV(TWEN); // clear int to start transmission<br />}<br /><br />void i2c_Write(uint8_t data)<br />{<br />TWDR = data;<br />while ((TWCR &amp; _BV(TWINT)) == 0);<br />TWCR = _BV(TWINT) | _BV(TWEN); // clear int to start transmission<br />}<br /><br />void i2c_ReadStart()<br />{<br />while ((TWCR &amp; _BV(TWINT)) == 0);<br />TWCR = _BV(TWINT) | _BV(TWEN) | _BV(TWEA); // clear int to start transmission<br />}<br /><br />uint8_t i2c_Read()<br />{<br />while ((TWCR &amp; _BV(TWINT)) == 0);<br />return TWDR;<br />}[/syntax]<br /><br />pca9685.h<br />[syntax=c]/*<br /> * File:   pca9685.h<br /> * Author: DevXP<br /> *<br /> * GNU GENERAL PUBLIC LICENSE!<br /> * Created on April 2, 2012, 8:28 AM<br /> */<br /><br />//#use I2C(master, slow, i2c1, force_hw)<br />#include &quot;pca9685_reg.h&quot;<br /><br /><br />void pca9685_init(int address)<br />{<br />/********************************************/<br />/* Init code for the PCA9685                */<br />/* Input:&#91;address of the pc9685 to init&#93;    */<br />/* Output:&#91;void&#93;                            */<br />/********************************************/<br />    i2c_Start();                // Start<br />    i2c_Write(address);         // Slave address<br />    i2c_Write(MODE1);           // Mode 1 address<br />    i2c_Write(0b00110001);      // Setting mode to sleep so we can change teh default PWM frequency<br />    i2c_Stop();                 // Stop<br />    _delay_ms(1);                // Required 50 us delay<br />    i2c_Start();                // Start<br />    i2c_Write(address);         // Slave address<br />    i2c_Write(0xfe);            // PWM frequency PRE_SCALE address<br />    i2c_Write(0x04);            // osc_clk/(4096*update_rate) // 25000000/(4096*1500)= 4.069 ~4<br />    i2c_Stop();                 // Stop<br />    _delay_ms(1);                // delay at least 500 us<br />    i2c_Start();                // Start<br />    i2c_Write(address);         // Slave address<br />    i2c_Write(MODE1);           // Mode 1 register address<br />    i2c_Write(0xa1);            // Set to our prefered mode&#91; Reset, INT_CLK, Auto-Increment, Normal Mode&#93;<br />    i2c_Stop();                 // Stop<br />    _delay_ms(1);                // delay at least 500 us<br />    i2c_Start();                // Start<br />    i2c_Write(address);         // Slave Address<br />    i2c_Write(MODE2);           // Mode2 register address<br />    i2c_Write(0b00000100);      // Set to our prefered mode&#91;Output logic state not inverted, Outputs change on STOP,<br />    i2c_Stop();                 // totem pole structure, When OE = 1 (output drivers not enabled), LEDn = 0&#93;<br />}<br /><br />void pca9685_send_all(int address)<br />{<br />/********************************************/<br />/* Update all PWM register of PCA9685       */<br />/* Input:&#91;address of the pc9685 to update&#93;  */<br />/* Output:&#91;void&#93;                            */<br />/********************************************/<br />    int i = 0;                  // temp regiter for LEDCOUNT<br />    int pwm;                    // temp register for PWM<br />    for(i=0; i&lt;=LEDCOUNT; i++)  // cycle thru all 16 LED<br />    {<br />        i2c_Start();            // Start<br />        i2c_Write(address);     // write to selected pca9685<br />        i2c_Write(LED0 + 4 * i);// start from LED0 address, each pwm constructed from<br />        i2c_Write(0x00);        // 4 12bit register, LED_ON_L<br />        i2c_Write(0x00);        // LED_ON_H<br />        pwm = PWMData&#91;i&#93;;       // update selected LED data in the array<br />        i2c_Write(pwm);         // LED_OFF_L<br />        pwm = PWMData&#91;i&#93;&gt;&gt;8;    // updtae selected LED data in the array<br />        i2c_Write(pwm);         // LED_OFF_H<br />        i2c_Stop();             // Stop<br />    }<br />}<br /><br />void pca9685_send(int address, long value, int led)<br />{<br />/********************************************/<br />/* pca9685_send(long value, int led)        */<br />/* Send the 12 bit PWM data to the register */<br />/* Input&#91; 0 to 4095 pwm, 0 to 15LED channel&#93;    */<br />/* Output&#91;void&#93;                             */<br />/********************************************/<br />    int pwm;                    // temp variable for PWM<br />    if(value &gt; 4095)            // if larger than 4095 than full on<br />            value = 4095;       // cant be larger than 4095<br />    if(led &gt; 15)                // if LED larger than 15 than on other chip<br />            led = 15;           //***** need to implement to seleced next pcs9685<br />    i2c_Start();                // Start<br />    i2c_Write(address);         // Address of selected pca9685<br />    i2c_Write(LED0 + 4 * led);  // select slected LED address<br />    i2c_Write(0x00);            // LED_ON_L<br />    i2c_Write(0x00);            // LED_ON_H<br />    pwm = value;                // PWM value lo byte<br />    i2c_Write(pwm);             // LED_OFF_L<br />    pwm = value&gt;&gt;8;             // pwm 16 bit long, now shift upper 8 to lower 8<br />    i2c_Write(pwm);             // LED_OFF_H<br />    i2c_Stop();                 // STop<br />}<br /><br /><br />void pca9685_brightness(int address, int percent, int led)<br />{<br />/********************************************/<br />/* Calculate the register values for a      */<br />/* given percentage and dupdate pca9685     */<br />/* Input:&#91;address of the chip where LED is_ */<br />/* percent of PWM on period 0%to100%      _ */<br />/* LED to set brightness 0to15&#93;             */<br />/* Output:&#91;void&#93;                            */<br />/********************************************/<br />    long x;                             // temp variable<br />    float off;                          // temp variable<br />    const float onePercent = 40.96;<br />    if (percent &lt; 1) {                  // if % less than 1 than LED OFF<br />    PWMData&#91;led&#93; = PCA9685_LED_OFF&gt;&gt;8;  // update data in array in case we use update all LED next<br />    pca9685_send(address,0,led);        // update selected LED<br />    return;                             // return from function<br />    }<br />    if (percent &gt;= 100) {               // if % greather than 100 than LED ON<br />    PWMData&#91;led&#93; = PCA9685_LED_ON&gt;&gt;8;   // update data in array<br />    pca9685_send(address,4095,led);     // update selected LED<br />    return;                             // return from function<br />    }<br />    off = onePercent * percent;         // different aproach with float need to check if code faster than int32 way ?<br />//    off = (int32)4096 * percent;        // calculate percent (max*percent)/100<br />//    off = off / 100;                    // ex (4096*50%)=204800/100=2048<br />//    x = make16(off&gt;&gt;8,off);             // make 16 of 32 ?! why.. dont care at this time<br />    PWMData&#91;led&#93; = off;                 // update datat array in case we update all LED next<br />    pca9685_send(address,off,led);      // send it to pca9685<br />}<br />void PCA9685AllLedOff(int address)<br />{<br />    i2c_Start();                        // Start<br />    i2c_Write(address);                 // select pca9685<br />    i2c_Write(0xfc);// AllLED Off regiSter<br />    i2c_Write(0b00000000);              // data<br />    i2c_Write(0b00010000);              // data<br />    i2c_Stop();                         // Stop<br />}[/syntax]<br /><br />pca9685_reg.h<br />[syntax=c]/*<br /> * File:   pca9685_reg.h<br /> * Author: DevXP<br /> *<br /> * GNU GENERAL PUBLIC LICENSE<br /> * Created on April 2, 2012, 8:28 AM<br /> */<br /><br />#ifndef pca9685_H<br />#define pca9685_H<br />/* General registers */<br />#define PCA9685 0x40          // I2C address for PCA9865 with all inputs at zero<br />#define Reset   0x01  // Reset the device<br />#define MODE1   0x00          // 0x00 location for Mode1 register address<br />#define MODE2   0x01          // 0x01 location for Mode2 register address<br />#define LED0    0x06          // location for start of LED0 registers<br />#define LEDCOUNT 15           // number of LEDS to light 15 max<br />/* Devices */<br />#define LEDDRV1    0x40                // 1st PCA9685<br /><br />/* MODE1 bits */<br />#define PCA9685_RESTART 0x80<br />#define PCA9685_EXTCLK  0x40<br />#define PCA9685_AI      0x20<br />#define PCA9685_SLEEP   0x10<br />#define PCA9685_SUB1    0x08<br />#define PCA9685_SUB2    0x04<br />#define PCA9685_SUB3    0x02<br />#define PCA9685_ALLCALL 0x01<br /><br />/* MODE2 bits */<br />#define PCA9685_INVRT   0x10<br />#define PCA9685_OCH     0x08<br />#define PCA9685_OUTDRV  0x04<br />#define PCA9685_OUTNE1  0x02<br />#define PCA9685_OUTNE0  0x01<br /><br />/* LEDX_ON_H bits */<br />#define PCA9685_LED_ON 0x10<br /><br />/* LEDX_OFF_H bits */<br />#define PCA9685_LED_OFF 0x10<br />/* PWM data variables, 16bit vide, 12bit used*/<br />long PWMData&#91;16&#93;= {<br />    //MSB        LSB<br />    0b010000000000,    // Channel 0<br />    0b101000000000,    // Channel 1<br />    0b000011000000,    // Channel 2<br />    0b000001100000,    // Channel 3<br />    0b000001011010,    // Channel 4<br />    0b000000000000,    // Channel 5<br />    0b000000000000,    // Channel 6<br />    0b000000000000,    // Channel 7<br />    0b000000000000,    // Channel 8<br />    0b000000000000,    // Channel 9<br />    0b000000000000,    // Channel 10<br />    0b000000000000,    // Channel 11<br />    0b000000000000,    // Channel 12<br />    0b000000000000,    // Channel 13<br />    0b000000000000,    // Channel 14<br />    0b000000000000     // Channel 15<br />};<br />#endif[/syntax]<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=870">wrobel111</a> — 26 paź 2017, o 17:06</p><hr />
]]></content>
</entry>
</feed>