<?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=3003&amp;mode" />

<title>ATNEL tech-forum</title>
<link href="https://forum.atnel.pl/index.php" />
<updated>2013-05-26T12:52:40+01:00</updated>

<author><name><![CDATA[ATNEL tech-forum]]></name></author>
<id>https://forum.atnel.pl/feed.php?f=4&amp;t=3003&amp;mode</id>
<entry>
<author><name><![CDATA[paladyn]]></name></author>
<updated>2013-05-26T12:52:40+01:00</updated>
<published>2013-05-26T12:52:40+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=3003&amp;p=37723#p37723</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=3003&amp;p=37723#p37723"/>
<title type="html"><![CDATA[Re: Prośba o sprawdzenie kodu - przetwornik ADC]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=3003&amp;p=37723#p37723"><![CDATA[
Witam po dłużej przerwie.  <img src="https://forum.atnel.pl/images/smilies/icon_e_smile.gif" alt=":)" title="Szczęśliwy" />  <br /><br />Zrobiłem nowe PCB jak to pisałem we wcześniejszym poście. Schemat wygląda tak: <a href="http://paladyn.elektroda.eu/img/schemat.png"  class="postlink">http://paladyn.elektroda.eu/img/schemat.png</a><br /><br />Natomiast kod tak:<br /><br />[syntax=c]/*<br /> * main.c<br /> *<br /> *  Created on: 04-04-2013<br /> *      Author: tomek<br /> */<br /><br /><br />#include &lt;avr/io.h&gt;<br />#include &quot;main.h&quot;<br /><br /><br />int main(void)<br />{<br />//Init<br />DDRC &amp;= ~(CELL1V_PIN | CELL2V_PIN | CELL3V_PIN | CURRENT_PIN); //input<br />DDRC |= (CELL1BYPASS_PIN | CELL2BYPASS_PIN); //output<br />DDRB |= (CELL3BYPASS_PIN); //output<br />DDRD |= (LEDREADY_PIN); //output<br /><br />//ADC<br />ADMUX |= (1&lt;&lt;REFS0) | (1&lt;&lt;REFS1); //internal 2,56V<br />ADCSRA |= (1&lt;&lt;ADEN) | (1&lt;&lt;ADPS0) | (1&lt;&lt;ADPS1); // ADC ON, prescaler 8, 125kHz<br /><br /><br />while(1)<br />{<br />//adc = read_adc(PC0);<br />cell1vol = read_adc(PC0)*(V_REF/1024)*CELL1_Ku;<br /><br />if(cell1vol&gt;12.6)<br />CELL1BYPASS_ON;<br />else<br />CELL1BYPASS_OFF;<br /><br />//adc = read_adc(PC1);<br />cell2vol = read_adc(PC1)*(V_REF/1024)*CELL2_Ku;<br /><br />if(cell2vol&gt;8.4)<br />CELL2BYPASS_ON;<br />else<br />CELL2BYPASS_OFF;<br /><br />//adc = read_adc(PC2);<br />cell3vol = read_adc(PC2)*(V_REF/1024)*CELL3_Ku;<br /><br />if(cell3vol&gt;4.2)<br />CELL3BYPASS_ON;<br />else<br />CELL3BYPASS_OFF;<br /><br />//adc = read_adc(PC3);<br />current =  (read_adc(PC3)*(V_REF/1024)/(R_MES*CURRENT_Ku));<br /><br />if(current&lt;=ENDCHARGE)<br />LEDREADY_OFF;<br />else<br />LEDREADY_ON;<br /><br />//CELL1BYPASS_OFF;<br />//CELL2BYPASS_OFF;<br />//CELL3BYPASS_OFF;<br /><br />}<br /><br />}<br /><br />uint16_t read_adc(uint8_t channel)<br />{<br />ADMUX = ((ADMUX &amp; 0xF8) | channel); //set input to adc<br />ADCSRA |= (1&lt;&lt;ADSC); //start mes<br />while(ADCSRA &amp; (1&lt;&lt;ADSC)); // waiting for convert<br />return ADCW; // return 16 bit<br /><br /><br />}[/syntax]<br /><br />[syntax=c]/*<br /> * main.h<br /> *<br /> *  Created on: 04-04-2013<br /> *      Author: tomek<br /> */<br /><br />#ifndef MAIN_H_<br />#define MAIN_H_<br /><br />uint16_t read_adc(uint8_t channel);<br />uint16_t adc;<br />float cell1vol;<br />float cell2vol;<br />float cell3vol;<br />float current;<br /><br /><br /><br />#define CELL1_Ku 5.7<br />#define CELL2_Ku 4<br />#define CELL3_Ku 2<br />#define CURRENT_Ku 11<br />#define V_REF 2.56<br />#define R_MES 0.1<br />#define ENDCHARGE 0.3 //0.3A<br /><br />#define CELL1V_PIN (1&lt;&lt;PC0)<br />#define CELL2V_PIN (1&lt;&lt;PC1)<br />#define CELL3V_PIN (1&lt;&lt;PC2)<br /><br />#define CURRENT_PIN (1&lt;&lt;PC3)<br /><br /><br />#define CELL1BYPASS_PIN (1&lt;&lt;PC5)<br />#define CELL2BYPASS_PIN (1&lt;&lt;PC4)<br />#define CELL3BYPASS_PIN (1&lt;&lt;PB1)<br /><br />#define CELL1BYPASS_OFF (PORTC |= CELL1BYPASS_PIN)<br />#define CELL2BYPASS_OFF (PORTC |= CELL2BYPASS_PIN)<br />#define CELL3BYPASS_OFF (PORTB |= CELL3BYPASS_PIN)<br /><br />#define CELL1BYPASS_ON (PORTC &amp;= ~CELL1BYPASS_PIN)<br />#define CELL2BYPASS_ON (PORTC &amp;= ~CELL2BYPASS_PIN)<br />#define CELL3BYPASS_ON (PORTB &amp;= ~CELL3BYPASS_PIN)<br /><br />#define LEDREADY_PIN (1&lt;&lt;PD1)<br />#define LEDREADY_ON (PORTD |= LEDREADY_PIN)<br />#define LEDREADY_OFF (PORTD &amp;= ~LEDREADY_PIN)<br /><br /><br /><br /><br /><br /><br />#endif /* MAIN_H_ */[/syntax]<br /><br /><br />Problemy są następujące:<br /><br />Mimo, że napięcia z dzielników napięciowych są w okolicach 2,10V czy nawet 2,18 to uC nie wysterowywuje tranzystorów.<br />Po przekroczeniu 2,1V z dzielnika napięciowego uC powinien bazy tranzystorów NPN podciągnąć do GND. Natomiast cały czas jest tam stan wysoki.<br /><br />Dioda, która ma sygnalizować zakończenie ładowania mruga. Nie mam pojęcia jak to możliwe, ale zachowuje się jak by była sterowana PWM. Jednak pod koniec ładowania mruga coraz wolniej aż zgaśnie.<br /><br /><br />Ponowie doradźcie coś bo skończyły mi się już pomysły.  Normalnie zachowanie uC ma się nijak do kodu programu...<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=468">paladyn</a> — 26 maja 2013, o 12:52</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[paladyn]]></name></author>
<updated>2013-05-04T23:58:35+01:00</updated>
<published>2013-05-04T23:58:35+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=3003&amp;p=36138#p36138</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=3003&amp;p=36138#p36138"/>
<title type="html"><![CDATA[Re: Prośba o sprawdzenie kodu - przetwornik ADC]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=3003&amp;p=36138#p36138"><![CDATA[
Z tego co widzę konfiguracja ADC jest taka sama jak u mnie. Najprawdopodobniej ADC działa prawidłowo, a błąd jest w hardware. Muszę zrobić lepszej jakości PCB i sprawdzę jeszcze raz.<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=468">paladyn</a> — 4 maja 2013, o 23:58</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[Paul Dirac]]></name></author>
<updated>2013-05-03T22:02:22+01:00</updated>
<published>2013-05-03T22:02:22+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=3003&amp;p=36028#p36028</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=3003&amp;p=36028#p36028"/>
<title type="html"><![CDATA[Re: Prośba o sprawdzenie kodu - przetwornik ADC]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=3003&amp;p=36028#p36028"><![CDATA[
Nie wiem czy to pomoże. NIe dawno robiłem obsługe 2ADC. Program nie jest jakiś full wypas, ale działa:<br />ADC.c:<br />[syntax=c]/*<br /> * adc_init.c<br /> *<br /> *  Created on: 2013-04-17<br /> *      Author: karolek<br /> */<br />#include &quot;adc_init.h&quot;<br /><br />void init_adc(void)<br />{<br />/*wybanie napiecia odniesienia*/<br />ADMUX |= ((1&lt;&lt;REFS0) | (1&lt;&lt;REFS1) ); //2,56<br />/*wlaczenie ADC*/<br />ADCSRA |= (1&lt;&lt;ADEN);<br />/*wybor preskalera  = 64*/<br />ADCSRA |= ( (1&lt;&lt;ADPS2) | (1&lt;&lt;ADPS1));<br />//zezwolenie na przerwanie<br />ADCSRA |= (1&lt;&lt;ADIE);<br /><br />}<br />uint16_t pomiar(uint8_t kanal)<br />{<br />uint16_t zmienna=0;<br />//ustawienie wybranego kanalu<br />ADMUX = (ADMUX &amp; 0xE0) | kanal ;<br />//start pomiaru<br />ADCSRA |= (1&lt;&lt;ADSC);<br />//oczekiwanie na koniec pomaru na wybranym kanale<br />while(ADCSRA &amp;(1&lt;&lt;ADSC));<br />//najpierw czytamy ADCL<br />zmienna = ADCL ;<br />zmienna |= (ADCH &amp; 0x03)&lt;&lt;8;<br /><br />return zmienna;<br /><br /><br />}[/syntax]<br />ADC.h:<br />[syntax=c]/*<br /> * adc_init.h<br /> *<br /> *  Created on: 2013-04-17<br /> *      Author: karolek<br /> */<br /><br />#ifndef ADC_INIT_H_<br />#define ADC_INIT_H_<br /><br />#include &lt;inttypes.h&gt;<br />#include &lt;avr/io.h&gt;<br /><br />void init_adc(void);<br />uint16_t pomiar(uint8_t kanal);<br /><br />#endif /* ADC_INIT_H_ */[/syntax]<br /><br />i main.c:<br />[syntax=c]/*<br /> * main.c<br /> *<br /> *  Created on: 2013-04-17<br /> *      Author: karolek<br /> */<br /><br />#include &lt;avr/io.h&gt;<br />#include &lt;util/delay.h&gt;<br />#include &lt;avr/interrupt.h&gt;<br />#include &lt;string.h&gt;<br /><br />#include &quot;lcd.h&quot;<br />#include &quot;adc_init.h&quot;<br /><br />volatile double volt1;<br />volatile double volt2;<br /><br />volatile uint8_t volt1_calk;<br />volatile uint8_t volt1_ncalk;<br /><br />volatile uint8_t volt2_calk;<br />volatile uint8_t volt2_ncalk;<br /><br />volatile uint32_t pwm1;<br />volatile uint32_t pwm2;<br /><br />volatile uint16_t pomiar1;<br />volatile uint16_t pomiar2;<br />//przerwanie wywolane kiedy konwersja ukonczona<br />ISR( ADC_vect )<br />{<br />pwm1 = 25 * pomiar1 ;<br />volt1_calk = pwm1/10000;<br />volt1_ncalk = (pwm1/100)%100;<br />pwm2 = 25 * pomiar2 ;<br />volt2_calk = pwm2/10000;<br />volt2_ncalk = (pwm2/100)%100;<br />lcd_set_xy(0,1);<br />printf(&quot;%d.%d&quot;, volt2_calk, volt2_ncalk);<br />lcd_set_xy(0,0);<br />printf(&quot;%d.%d&quot;, volt1_calk, volt1_ncalk);<br /><br />}<br /><br /><br />int main(void)<br />{<br />DDRA |= ((1&lt;&lt;PA2) | (1&lt;&lt;PA3) | (1&lt;&lt;PA4) | (1&lt;&lt;PA5) | (1&lt;&lt;PA6) | (1&lt;&lt;PA7))  ; //jako wyjscie<br />DDRA &amp;= ~((1&lt;&lt;PA0) | (1&lt;&lt;PA1));<br />//PORTA = 0x00;<br />lcd_init();<br />stdout=&amp;mystdout;<br />printf(&quot;LCD OK!&quot;);<br />_delay_ms(500);<br />lcd_clear();<br /><br />init_adc(); //inicjalizacja adc<br />_delay_ms(1000);<br />sei();<br />while(1)<br />{<br /><br />pomiar1 = pomiar(0);<br />pomiar2 = pomiar(1);<br /><br />}<br /><br />return 0;<br />}[/syntax]<br /><br />sam siedziałem na tym chyba cały dzień i nawet znalezłem bład z tym ADMUX, który jak sie okazało był juz wykryty przez któregoś bystrzaka.<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=1035">Paul Dirac</a> — 3 maja 2013, o 22:02</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[paladyn]]></name></author>
<updated>2013-05-03T21:07:09+01:00</updated>
<published>2013-05-03T21:07:09+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=3003&amp;p=36021#p36021</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=3003&amp;p=36021#p36021"/>
<title type="html"><![CDATA[Re: Prośba o sprawdzenie kodu - przetwornik ADC]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=3003&amp;p=36021#p36021"><![CDATA[
Zrobiłem lekką modyfikacje kodu jednak przetwornik nadal nie działa jak powinien.<br /><br />Kod wygląda tak:<br /><br />main.c<br /><br />[syntax=c]/*<br /> * main.c<br /> *<br /> *  Created on: 04-04-2013<br /> *      Author: tomek<br /> */<br /><br /><br />#include &lt;avr/io.h&gt;<br />#include &quot;main.h&quot;<br /><br /><br />int main(void)<br />{<br />//Init<br />DDRC &amp;= ~(CELL1V_PIN | CELL2V_PIN | CELL3V_PIN | CURRENT_PIN); //input<br />DDRC |= (CELL1BYPASS_PIN | CELL2BYPASS_PIN); //output<br />DDRD |= (CELL3BYPASS_PIN | LEDREADY_PIN); //output<br /><br />//ADC<br />ADMUX |= (1&lt;&lt;REFS0) | (1&lt;&lt;REFS1); //internal 2,56V<br />ADCSRA |= (1&lt;&lt;ADEN) | (1&lt;&lt;ADPS0) | (1&lt;&lt;ADPS1); // ADC ON, prescaler 8, 125kHz<br /><br /><br />while(1)<br />{<br />adc = read_adc(PC0);<br />cell1vol = adc*(V_REF/1024)*CELL1_Ku;<br /><br />adc = read_adc(PC1);<br />cell2vol = adc*(V_REF/1024)*CELL2_Ku;<br /><br />adc = read_adc(PC2);<br />cell3vol = adc*(V_REF/1024)*CELL3_Ku;<br /><br />adc = read_adc(PC3);<br />current =  (adc*(V_REF/1024)/(R_MES*CURRENT_Ku));<br /><br /><br />if(cell1vol&gt;=12.6)<br />CELL1BYPASS_ON;<br />else<br />CELL1BYPASS_OFF;<br /><br /><br />if(cell2vol&gt;=8.4)<br />CELL2BYPASS_ON;<br />else<br />CELL2BYPASS_OFF;<br /><br /><br />if(cell3vol&gt;=4.2)<br />CELL3BYPASS_ON;<br />else<br />CELL3BYPASS_OFF;<br /><br />if(current&lt;=ENDCHARGE)<br />LEDREADY_ON;<br />else<br />LEDREADY_OFF;<br /><br />//CELL1BYPASS_ON;<br />//CELL2BYPASS_OFF;<br />//CELL3BYPASS_OFF;<br /><br />}<br /><br />}<br /><br />uint16_t read_adc(uint8_t channel)<br />{<br />ADMUX = (ADMUX &amp; 0xF8) | channel; //set input to adc<br />ADCSRA |= (1&lt;&lt;ADSC); //start mes<br />while(ADCSRA &amp; (1&lt;&lt;ADSC)); // waiting for convert<br />return ADC; // return 16 bit<br /><br /><br />}[/syntax]<br /><br /><br />main.h<br /><br />[syntax=c]/*<br /> * main.h<br /> *<br /> *  Created on: 04-04-2013<br /> *      Author: tomek<br /> */<br /><br />#ifndef MAIN_H_<br />#define MAIN_H_<br /><br />uint16_t read_adc(uint8_t channel);<br />uint16_t adc;<br />double cell1vol;<br />double cell2vol;<br />double cell3vol;<br />double current;<br /><br /><br /><br /><br /><br /><br />#define CELL1_Ku 5.7<br />#define CELL2_Ku 4<br />#define CELL3_Ku 2<br />#define CURRENT_Ku 11<br />#define V_REF 2.56<br />#define R_MES 0.1<br />#define ENDCHARGE 0.3 //0.3A<br /><br />#define CELL1V_PIN (1&lt;&lt;PC0)<br />#define CELL2V_PIN (1&lt;&lt;PC1)<br />#define CELL3V_PIN (1&lt;&lt;PC2)<br /><br />#define CURRENT_PIN (1&lt;&lt;PC3)<br /><br /><br />#define CELL1BYPASS_PIN (1&lt;&lt;PC4)<br />#define CELL2BYPASS_PIN (1&lt;&lt;PC5)<br />#define CELL3BYPASS_PIN (1&lt;&lt;PD0)<br /><br />#define CELL1BYPASS_OFF (PORTC |= CELL1BYPASS_PIN)<br />#define CELL2BYPASS_OFF (PORTC |= CELL2BYPASS_PIN)<br />#define CELL3BYPASS_OFF (PORTD |= CELL3BYPASS_PIN)<br /><br />#define CELL1BYPASS_ON (PORTC &amp;= ~CELL1BYPASS_PIN)<br />#define CELL2BYPASS_ON (PORTC &amp;= ~CELL2BYPASS_PIN)<br />#define CELL3BYPASS_ON (PORTD &amp;= ~CELL3BYPASS_PIN)<br /><br />#define LEDREADY_PIN (1&lt;&lt;PD1)<br />#define LEDREADY_ON (PORTD |= LEDREADY_PIN)<br />#define LEDREADY_OFF (PORTD &amp;= ~LEDREADY_PIN)<br /><br /><br /><br /><br /><br /><br />#endif /* MAIN_H_ */[/syntax]<br /><br /><br />Możecie powiedzieć czy kod jest prawidłowy? Za Chiny ludowe nie mogę odpalić pomiaru prądu. Schemat układu wygląda tak:<br /><a href="http://tomzb.w.interia.pl/schemat.png"  class="postlink">http://tomzb.w.interia.pl/schemat.png</a><br /><br />Bocznik to rezystor 0.1oma przy przepływie prądu 1,5A odkłada się 150mV. Wzmacniacz operacyjny ma wzmocnić napięcie 11 razy po czym zostaje odczytane przez ADC.<br /><br />Panowie pomóżcie, dopiero raczkuje z uC <img src="https://forum.atnel.pl/images/smilies/icon_e_wink.gif" alt=";)" title="Puszcza oko" /><p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=468">paladyn</a> — 3 maja 2013, o 21:07</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[Krauser]]></name></author>
<updated>2013-05-03T19:54:39+01:00</updated>
<published>2013-05-03T19:54:39+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=3003&amp;p=36005#p36005</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=3003&amp;p=36005#p36005"/>
<title type="html"><![CDATA[Re: Prośba o sprawdzenie kodu - przetwornik ADC]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=3003&amp;p=36005#p36005"><![CDATA[
To bez znaczenia. Chodzi o to, że PC0, PC1, PC2 i PC3 to liczby 0, 1, 2 i 3. Działanie 1&lt;&lt;PCx da w efekcie 1, 2, 4, 8. Natomiast argumentem read_adc ma być liczba 0...7. Tak bym to rozwiązał:<br /><br />[syntax=c]#define CELL1V PC0<br />#define CELL1V PC1<br />#define CELL1V PC2<br />#define CELL1V PC3<br /><br />#define CELL1V_PIN (1&lt;&lt;CELL1V)<br />#define CELL2V_PIN (1&lt;&lt;CELL2V)<br />#define CELL3V_PIN (1&lt;&lt;CELL3V)<br /> <br />#define CURRENT_PIN (1&lt;&lt;CURRENT)<br /><br />adc = read_adc(CELL1V);<br />adc = read_adc(CELL2V);<br />adc = read_adc(CELL3V;<br />adc = read_adc(CURRENT);[/syntax]<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=465">Krauser</a> — 3 maja 2013, o 19:54</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[paladyn]]></name></author>
<updated>2013-05-02T20:24:56+01:00</updated>
<published>2013-05-02T20:24:56+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=3003&amp;p=35918#p35918</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=3003&amp;p=35918#p35918"/>
<title type="html"><![CDATA[Re: Prośba o sprawdzenie kodu - przetwornik ADC]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=3003&amp;p=35918#p35918"><![CDATA[
Tak będzie działało ? [syntax=c]uint16_t read_adc(char channel)[/syntax]<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=468">paladyn</a> — 2 maja 2013, o 20:24</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[Krauser]]></name></author>
<updated>2013-05-02T20:07:32+01:00</updated>
<published>2013-05-02T20:07:32+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=3003&amp;p=35914#p35914</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=3003&amp;p=35914#p35914"/>
<title type="html"><![CDATA[Re: Prośba o sprawdzenie kodu - przetwornik ADC]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=3003&amp;p=35914#p35914"><![CDATA[
<div class="quotetitle">paladyn napisał(a):</div><div class="quotecontent"><br />[syntax=c]adc = read_adc(CELL1V_PIN);<br />#define CELL1V_PIN (1&lt;&lt;PC0)[/syntax]<br /></div><br />Argumentem read_adc ma być liczba 0...7. A wykorzystując przesunięcie kolejne liczby będą znacznie większe.<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=465">Krauser</a> — 2 maja 2013, o 20:07</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[paladyn]]></name></author>
<updated>2013-05-02T13:36:47+01:00</updated>
<published>2013-05-02T13:36:47+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=3003&amp;p=35879#p35879</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=3003&amp;p=35879#p35879"/>
<title type="html"><![CDATA[Prośba o sprawdzenie kodu - przetwornik ADC]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=3003&amp;p=35879#p35879"><![CDATA[
Witam.<br /><br />Próbuje rozwiązać problem z balanserem do ładowarki li-ion i niestety coś nie idzie po mojej myśli. Był bym wdzięczny jeśli rzucilibyście okiem na kod programu czy nie znajduję się w nim jakiś błąd.<br /><br /><br />uC Atmega8, 1MHz<br /><br /><br /><strong>Plik main.c</strong><br />[syntax=c]/*<br /> * main.c<br /> *<br /> *  Created on: 04-04-2013<br /> *      Author: tomek<br /> */<br /><br /><br />#include &lt;avr/io.h&gt;<br />#include &quot;main.h&quot;<br /><br /><br />int main(void)<br />{<br />//Init<br />DDRC &amp;= ~(CELL1V_PIN | CELL2V_PIN | CELL3V_PIN | CURRENT_PIN); //input<br />DDRC |= (CELL1BYPASS_PIN | CELL2BYPASS_PIN); //output<br />DDRD |= (CELL3BYPASS_PIN | LEDREADY_PIN); //output<br /><br />//ADC<br />ADMUX |= (1&lt;&lt;REFS0) | (1&lt;&lt;REFS1); //internal 2,56V<br />ADCSRA |= (1&lt;&lt;ADEN) | (1&lt;&lt;ADPS0) | (1&lt;&lt;ADPS1); // ADC ON, prescaler 8, 125kHz<br /><br /><br />while(1)<br />{<br />adc = read_adc(CELL1V_PIN);<br />cell1vol = (adc*V_REF*CELL1_Ku)/1024;<br /><br />adc = read_adc(CELL2V_PIN);<br />cell2vol = (adc*V_REF*CELL2_Ku)/1024;<br /><br />adc = read_adc(CELL3V_PIN);<br />cell3vol = (adc*V_REF*CELL3_Ku)/1024;<br /><br />adc = read_adc(CURRENT_PIN);<br />current = (adc*V_REF)/(1024 *CURRENT_Ku*R_MES);<br /><br /><br />if(cell1vol&gt;=12.0)<br />CELL1BYPASS_ON;<br />else<br />CELL1BYPASS_OFF;<br /><br /><br />if(cell2vol&gt;=8.3)<br />CELL2BYPASS_ON;<br />else<br />CELL2BYPASS_OFF;<br /><br /><br />if(cell3vol&gt;=4.2)<br />CELL3BYPASS_ON;<br />else<br />CELL3BYPASS_OFF;<br /><br />if(current&lt;=ENDCHARGE)<br />LEDREADY_ON;<br />else<br />LEDREADY_OFF;<br /><br />//CELL1BYPASS_ON;<br />//CELL2BYPASS_ON;<br />//CELL3BYPASS_ON;<br /><br />}<br /><br />}<br /><br />uint16_t read_adc(uint8_t channel)<br />{<br />ADMUX = (ADMUX &amp; 0xF8) | channel; //set input to adc<br />ADCSRA |= (1&lt;&lt;ADSC); //start mes<br />while(ADCSRA &amp; (1&lt;&lt;ADSC)); // waiting for convert<br />return ADCW; // return 16 bit<br /><br /><br />}[/syntax]<br /><br /><strong>Plik main.h</strong><br /><br />[syntax=c]/*<br /> * main.h<br /> *<br /> *  Created on: 04-04-2013<br /> *      Author: tomek<br /> */<br /><br />#ifndef MAIN_H_<br />#define MAIN_H_<br /><br />uint16_t read_adc(uint8_t channel);<br />uint16_t adc;<br />double cell1vol;<br />double cell2vol;<br />double cell3vol;<br />double current;<br /><br /><br /><br /><br /><br /><br />#define CELL1_Ku 5.7<br />#define CELL2_Ku 4<br />#define CELL3_Ku 2<br />#define CURRENT_Ku 11<br />#define V_REF 2.56<br />#define R_MES 0.1<br />#define ENDCHARGE 0.150<br /><br />#define CELL1V_PIN (1&lt;&lt;PC0)<br />#define CELL2V_PIN (1&lt;&lt;PC1)<br />#define CELL3V_PIN (1&lt;&lt;PC2)<br /><br />#define CURRENT_PIN (1&lt;&lt;PC3)<br /><br /><br />#define CELL1BYPASS_PIN (1&lt;&lt;PC4)<br />#define CELL2BYPASS_PIN (1&lt;&lt;PC5)<br />#define CELL3BYPASS_PIN (1&lt;&lt;PD0)<br /><br />#define CELL1BYPASS_OFF (PORTC |= CELL1BYPASS_PIN)<br />#define CELL2BYPASS_OFF (PORTC |= CELL2BYPASS_PIN)<br />#define CELL3BYPASS_OFF (PORTD |= CELL3BYPASS_PIN)<br /><br />#define CELL1BYPASS_ON (PORTC &amp;= ~CELL1BYPASS_PIN)<br />#define CELL2BYPASS_ON (PORTC &amp;= ~CELL2BYPASS_PIN)<br />#define CELL3BYPASS_ON (PORTD &amp;= ~CELL3BYPASS_PIN)<br /><br />#define LEDREADY_PIN (1&lt;&lt;PD1)<br />#define LEDREADY_ON (PORTD |= LEDREADY_PIN)<br />#define LEDREADY_OFF (PORTD &amp;= ~LEDREADY_PIN)<br /><br /><br /><br /><br /><br /><br />#endif /* MAIN_H_ */[/syntax]<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=468">paladyn</a> — 2 maja 2013, o 13:36</p><hr />
]]></content>
</entry>
</feed>