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

<title>ATNEL tech-forum</title>
<link href="https://forum.atnel.pl/index.php" />
<updated>2014-03-08T16:40:48+01:00</updated>

<author><name><![CDATA[ATNEL tech-forum]]></name></author>
<id>https://forum.atnel.pl/feed.php?f=4&amp;t=6265&amp;mode</id>
<entry>
<author><name><![CDATA[tomasz1987]]></name></author>
<updated>2014-03-08T16:40:48+01:00</updated>
<published>2014-03-08T16:40:48+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=6265&amp;p=73439#p73439</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=6265&amp;p=73439#p73439"/>
<title type="html"><![CDATA[Re: [atmega8][USART] Problem z odbieraniem danych]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=6265&amp;p=73439#p73439"><![CDATA[
Jak odremuje te 2 linie to ta instrukcja nie jest brana pod uwagę więc nie może być tu problemem.<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=1096">tomasz1987</a> — 8 mar 2014, o 16:40</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[programek]]></name></author>
<updated>2014-03-08T16:28:03+01:00</updated>
<published>2014-03-08T16:28:03+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=6265&amp;p=73438#p73438</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=6265&amp;p=73438#p73438"/>
<title type="html"><![CDATA[Re: [atmega8][USART] Problem z odbieraniem danych]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=6265&amp;p=73438#p73438"><![CDATA[
No właśnie dzisiaj rano jeszcze oglądałem filmik na YouTube jak o tym mówiłeś <img src="https://forum.atnel.pl/images/smilies/icon_e_biggrin.gif" alt=":D" title="Bardzo szczęśliwy" /><p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=1526">programek</a> — 8 mar 2014, o 16:28</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[tomasz1987]]></name></author>
<updated>2014-03-08T15:58:24+01:00</updated>
<published>2014-03-08T15:58:24+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=6265&amp;p=73431#p73431</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=6265&amp;p=73431#p73431"/>
<title type="html"><![CDATA[Re: [atmega8][USART] Problem z odbieraniem danych]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=6265&amp;p=73431#p73431"><![CDATA[
Faktycznie miałem usunąć te zaremowane linie.<br />Po usunięciu nic się nie zmieniło- program działa tak samo czyli nie zawsze odbiera zmienioną temperaturę.<br /><br />Edit<br /><br />może nie usunąć całkiem tylko od remować bo ta &quot;struktura&quot;  zabezpiecza mnie przed moją sklerozą<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=1096">tomasz1987</a> — 8 mar 2014, o 15:58</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[mirekk36]]></name></author>
<updated>2014-03-08T14:50:00+01:00</updated>
<published>2014-03-08T14:50:00+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=6265&amp;p=73415#p73415</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=6265&amp;p=73415#p73415"/>
<title type="html"><![CDATA[Re: [atmega8][USART] Problem z odbieraniem danych]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=6265&amp;p=73415#p73415"><![CDATA[
<div class="quotetitle">programek napisał(a):</div><div class="quotecontent"><br />Nie stosuj tego zapisu, Mirek wiele razy o tym mówił<br /></div><br /><br />Dzięki programek - bo mi już jak widzisz ręce opadają od przypominania o takich podstawowych BABOLACH - pomimo że i w poradnikach video o tym trąbię <img src="https://forum.atnel.pl/images/smilies/icon_e_sad.gif" alt=":(" title="Smutny" /><p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=54">mirekk36</a> — 8 mar 2014, o 14:50</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[programek]]></name></author>
<updated>2014-03-08T13:06:19+01:00</updated>
<published>2014-03-08T13:06:19+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=6265&amp;p=73405#p73405</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=6265&amp;p=73405#p73405"/>
<title type="html"><![CDATA[Re: [atmega8][USART] Problem z odbieraniem danych]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=6265&amp;p=73405#p73405"><![CDATA[
Nie stosuj tego zapisu, Mirek wiele razy o tym mówił <img src="https://forum.atnel.pl/images/smilies/icon_e_wink.gif" alt=";)" title="Puszcza oko" /><br />[syntax=c]#define F_CPU   8000000UL    // 8 MHz - turn on external resonator (fuse bits)[/syntax]<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=1526">programek</a> — 8 mar 2014, o 13:06</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[tomasz1987]]></name></author>
<updated>2014-03-08T12:38:36+01:00</updated>
<published>2014-03-08T12:38:36+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=6265&amp;p=73404#p73404</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=6265&amp;p=73404#p73404"/>
<title type="html"><![CDATA[Re: [atmega8][USART] Problem z odbieraniem danych]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=6265&amp;p=73404#p73404"><![CDATA[
Wstawiam poprawiony kod mam nadzieje że teraz już wszystko gra. A przede wszystkim uda się rozwiązać problem z odbieraniem przez program nowych nastaw temperatury.<br /><br /><br /><br />[syntax=c]//#ifndef F_CPU  <br />#define F_CPU   8000000UL    // 8 MHz - turn on external resonator (fuse bits)<br />//#endif<br /><br /><br /><br /><br />/*This file has been prepared for Doxygen automatic documentation generation.*/  <br />/*! \file *********************************************************************  <br />*  <br />* \brief Example of use of general PID implementation for AVR.  <br />*  <br />* Example of how to setup and use the general PID implementation in pid.c.  <br />*  <br />* - File:               main.c  <br />* - Compiler:           IAR EWAAVR 4.11A  <br />* - Supported devices:  All AVR devices can be used.  <br />* - AppNote:            AVR221 - Discrete PID controller  <br />*  <br />* \author               Atmel Corporation: http://www.atmel.com \n  <br />*                       Support email: avr@atmel.com  <br />*  <br />* $Name: RELEASE_1_0 $  <br />* $Revision: 1.1 $  <br />* $RCSfile: main.c,v $  <br />* $Date: 2006/02/16 11:46:13 $  <br />*****************************************************************************/  <br /><br />#include &lt;avr/io.h&gt;<br />#include &lt;stdlib.h&gt;<br />#include &lt;util/delay.h&gt;<br />#include &lt;inttypes.h&gt;<br />#include &lt;avr/interrupt.h&gt;<br />#include &lt;avr/pgmspace.h&gt;<br />#include &lt;avr/eeprom.h&gt;<br />#include &quot;pid.h&quot;<br />#include &quot;pomiar.h&quot;<br />#include &quot;pwm_lib.h&quot;<br />#include &quot;uart.h&quot;<br /><br />// ---- UART ----//<br />#define USART0_BAUD 9600<br />#define __UBRR0 ((F_CPU+USART0_BAUD*8UL) / (16UL*USART0_BAUD)-1)//do not change<br />// ---- UART ----<br /><br />/*! \brief P, I and D parameter values  <br />*  <br />* The K_P, K_I and K_D values (P, I and D gains)  <br />* need to be modified to adapt to the application at hand  <br />*/  <br />//! \xrefitem todo &quot;Todo&quot; &quot;Todo list&quot;  <br />#define K_P    0.55772 //////0.6<br />//! \xrefitem todo &quot;Todo&quot; &quot;Todo list&quot;  <br />#define K_I     0.028822//////////0.05<br />//! \xrefitem todo &quot;Todo&quot; &quot;Todo list&quot;  <br />#define K_D    0.14958//////////0.8<br /><br /><br /><br />#define cbi(sfr, bit) (_SFR_BYTE(sfr) &amp;= ~_BV(bit))<br />#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))<br /><br />#define set_high(port) sbi(port)<br />#define set_low(port)  cbi(port)<br />#define set_on(port)   sbi(port)<br />#define set_off(port)  cbi(port)<br /><br />#define is_low(port)   (bit_is_clear(port))<br />#define is_high(port)  (bit_is_set(port))<br />#define is_on(port)    (bit_is_clear(port))<br />#define is_off(port)   (bit_is_set(port))<br /><br /><br />/************************************************************************************<br />*                                              USART0 receiver                                             *<br />************************************************************************************/<br />#define RX0_BUFFER_SIZE 16<br />#define RX0_BUFFER_MASK (RX0_BUFFER_SIZE-1)//do not change<br /><br />/************************************************************************************<br />*                                              USART0 transmitter                                          *<br />************************************************************************************/<br />#define TX0_BUFFER_SIZE 16<br />#define TX0_BUFFER_MASK (TX0_BUFFER_SIZE-1)//do not change<br /><br /><br /><br /><br />/*! \brief Flags for status information  <br />*/  <br />struct GLOBAL_FLAGS {  <br />//! True when PID control loop should run one time  <br />uint8_t pidTimer:1;  <br />uint8_t dummy:7;  <br />} gFlags = {0, 0};  <br /><br />//! Parameters for regulator  <br />struct PID_DATA pidData;  <br /><br />/*! \brief Sampling Time Interval  <br />*  <br />* Specify the desired PID sample time interval  <br />* With a 8-bit counter (255 cylces to overflow), the time interval value is calculated as follows:  <br />* TIME_INTERVAL = ( desired interval &#91;sec&#93; ) * ( frequency &#91;Hz&#93; ) / 255  <br />*/  <br />//! \xrefitem todo &quot;Todo&quot; &quot;Todo list&quot;  <br /><br /><br /><br /><br />// Set up timer, enable timer/counte 0 overflow interrupt  <br />void  timer0_init(void);<br /><br /><br />void Init(void)  <br />void Set_Input(int16_t inputValue)  <br />int16_t Get_Measurement(void) <br />int16_t Get_ADC(void)  <br /><br /><br /><br /><br />char work_buffer0&#91;RX0_BUFFER_SIZE&#93;;<br />unsigned char  inf&#91;33&#93; = &quot;program do akwizycji danych PID: &quot;;<br /><br />volatile uint16_t Timer1, Timer2, Timer3, Timer4;<br />int16_t nastaw= 50;<br />int16_t referenceValue=0 , measurementValue=0 , inputValue=0,  measurementADC;  <br /><br />int main(void)  <br />{  <br /><br />DDRD =  0b11111111; //0 = wejście 1 = wyjscie<br />PORTD=  0b11111111; //1 = podciaganie<br />DDRC =  0b11011111; //0 = wejście 1 = wyjscie<br />PORTC=  0b11111111; //1 = podciaganie<br />DDRB =  0b11111111; //0 = wejście 1 = wyjscie<br />PORTB=  0b11111111; //1 = podciaganie///7 6 5 4 3 2 1 0<br /><br /><br />timer0_init();  <br />Init();  <br />PomiarInit();<br />pwm_init();<br /><br />uart_init(0, __UBRR0);<br />sei();<br /><br /><br />while(1){  <br /><br /><br />if(UCSRA &amp; _BV(RXC)){<br />//Timer1=200;//125co 500 msekunde<br />uart_get_string(0, work_buffer0);<br />PORTD^= (1&lt;&lt;PD6);<br />nastaw=atoi( work_buffer0);<br /><br />}  <br /><br /><br /><br />/*! \brief Timer interrupt to control the sampling interval  <br />*/<br /><br />if(!Timer1){<br />Timer1=250;//125co 500 msekunde<br />gFlags.pidTimer = TRUE;<br /><br />}  <br /><br /><br /><br /><br />// Run PID calculations once every PID timer timeout  <br />if(gFlags.pidTimer)  <br />{  <br /><br />referenceValue = nastaw; <br />measurementValue = Get_Measurement();<br />measurementADC = Get_ADC();<br /><br />inputValue = pid_Controller(referenceValue, measurementValue, &amp;pidData);  <br />Set_Input(inputValue);  <br />gFlags.pidTimer = FALSE;  <br /><br />if(!Timer2){<br /><br />Timer2=500;//co 1 sekunde      <br />// uart_put_string(0,&quot;temp : &quot;);<br />uart_put_int(0,measurementValue);<br />//uart_put_int(0,measurementADC);<br />//uart_put_string(0,&quot;\r\n&quot;);<br />uart_put_char(0,' ');<br />uart_put_int(0,inputValue);<br />uart_put_string(0,&quot;\r\n&quot;);<br /><br />}<br />}<br />}  <br />}  <br /><br /><br /><br /><br />/*! \mainpage  <br />* \section Intro Introduction  <br />* This documents data structures, functions, variables, defines, enums, and  <br />* typedefs in the software for application note AVR221.  <br />*  <br />* \section CI Compilation Info  <br />* This software was written for the IAR Embedded Workbench 4.11A.  <br />*  <br />* To make project:  <br />* &lt;ol&gt;  <br />* &lt;li&gt; Add the file main.c and pid.c to project.  <br />* &lt;li&gt; Under processor configuration, select desired Atmel AVR device.  <br />* &lt;li&gt; Enable bit definitions in I/O include files  <br />* &lt;li&gt; High optimization on speed is recommended for best performance  <br />* &lt;/ol&gt;  <br />*  <br />* \section DI Device Info  <br />* The included source code is written for all Atmel AVR devices.  <br />*  <br />* \section TDL ToDo List  <br />* \todo Put in own code in:  <br />* \ref Get_Reference(void), \ref Get_Measurement(void) and \ref Set_Input(int16_t inputValue)  <br />*  <br />* \todo Modify the \ref K_P (P), \ref K_I (I) and \ref K_D (D) gain to adapt to your application  <br />* \todo Specify the sampling interval time \ref TIME_INTERVAL  <br />*/<br /><br /><br /><br />void timer0_init(void){<br />TCCR0|=(1&lt;&lt;CS00)|(1&lt;&lt;CS01);  /// prescaler na 64<br />TIMSK|= 1&lt;&lt;TOIE0; ///właczenie przerwania od przepełnienia<br />TCNT0=131;        /// wartość początkowa rejestru<br /><br />}<br /><br /><br /><br />ISR(TIMER0_OVF_vect){<br />uint16_t n;<br />n=Timer1;<br />if(n) Timer1 = --n;<br />n=Timer2;<br />if(n) Timer2 = --n;<br />n=Timer3;<br />if(n) Timer3 = --n;<br />n=Timer4;<br />if(n) Timer4 = --n;<br /><br />}<br /><br /><br /><br /><br />/*! \brief Init of PID controller demo  <br />*/  <br />void Init(void)  <br />{  <br />pid_Init(K_P * SCALING_FACTOR, K_I * SCALING_FACTOR , K_D * SCALING_FACTOR , &amp;pidData);  <br /><br />} <br /><br /><br /><br />/*! \brief Read system process value  <br />*  <br />* This function must return the measured ADC<br />*/  <br />int16_t Get_ADC(void)  <br />{   <br />int16_t TempValue;<br />TempValue = PomiarADC();<br /><br /><br />return TempValue;  <br />}  <br /><br /><br /><br />/*! \brief Read system process value  <br />*  <br />* This function must return the measured data  <br />*/  <br />int16_t Get_Measurement(void)  <br />{   <br />int16_t TempValue;<br />TempValue = PomiarTemp();<br /><br /><br />return TempValue;  <br />}<br /><br />/*! \brief Set control input to system  <br />*  <br />* Set the output from the controller as input  <br />* to system.  <br />*/  <br />void Set_Input(int16_t inputValue)  <br />{  <br />if(inputValue&gt;32767) inputValue=32767;<br />if(inputValue&lt;1) inputValue=0;<br />pwm_set_a(inputValue);  <br />}  <br /><br />/*! \brief PID control algorithm.  <br />*  <br />*  Calculates output from setpoint, process value and PID status.  <br />*  <br />*  \param setPoint  Desired value.  <br />*  \param processValue  Measured value.  <br />*  \param pid_st  PID status struct.  <br />*/  <br />int16_t pid_Controller(int16_t setPoint, int16_t processValue, struct PID_DATA *pid_st)  <br />{  <br />int16_t error, p_term, d_term;  <br />int32_t i_term, ret, temp;  <br /><br />error = setPoint - processValue;  <br /><br />// Calculate Pterm and limit error overflow  <br />if (error &gt; pid_st-&gt;maxError){  <br />p_term = MAX_INT;  <br />}  <br />else if (error &lt; -pid_st-&gt;maxError){  <br />p_term = -MAX_INT;  <br />}  <br />else{  <br />p_term = pid_st-&gt;P_Factor * error;  <br />}  <br /><br />// Calculate Iterm and limit integral runaway  <br />temp = pid_st-&gt;sumError + error;  <br />if(temp &gt; pid_st-&gt;maxSumError){  <br />i_term = MAX_I_TERM;  <br />pid_st-&gt;sumError = pid_st-&gt;maxSumError;  <br />}  <br />else if(temp &lt; -pid_st-&gt;maxSumError){  <br />i_term = -MAX_I_TERM;  <br />pid_st-&gt;sumError = -pid_st-&gt;maxSumError;  <br />}  <br />else{  <br />pid_st-&gt;sumError = temp;  <br />i_term = pid_st-&gt;I_Factor * pid_st-&gt;sumError;  <br />}  <br /><br />// Calculate Dterm  <br />d_term = pid_st-&gt;D_Factor * (pid_st-&gt;lastProcessValue - processValue);  <br /><br />pid_st-&gt;lastProcessValue = processValue;  <br /><br />ret = (p_term + i_term + d_term) / SCALING_FACTOR;  <br />if(ret &gt; MAX_INT){  <br />ret = MAX_INT;  <br />}  <br />else if(ret &lt; -MAX_INT){  <br />ret = -MAX_INT;  <br />}  <br /><br />return((int16_t)ret);  <br />}[/syntax]<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=1096">tomasz1987</a> — 8 mar 2014, o 12:38</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[tomasz1987]]></name></author>
<updated>2014-03-07T22:13:43+01:00</updated>
<published>2014-03-07T22:13:43+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=6265&amp;p=73370#p73370</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=6265&amp;p=73370#p73370"/>
<title type="html"><![CDATA[Re: [atmega8][USART] Problem z odbieraniem danych]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=6265&amp;p=73370#p73370"><![CDATA[
Ok się poprawi, kod uporządkuję jak tylko znajdę czas. <br />Ogólnie to była to tylko Praca na zaliczenie dla kolegi więc jakoś specjalnie się nie przykładałem uruchomiłem sterownik P I D ściągnięty z Atmela a że potem jeszcze chciał żeby można było w terminalu zmienić temperaturę, więc mu to na szybko dodałem. Mimo tego że praca jest oddana to z ciekawości chciałbym wiedzieć czemu to nie zmienia temperatury zawszę<br /><br />nastaw jest zmieniany tutaj<br />[syntax=c]if(UCSRA &amp; _BV(RXC)){<br />//Timer1=200;//125co 500 msekunde<br />uart_get_string(0, work_buffer0);<br />        PORTD^= (1&lt;&lt;PD6);<br />nastaw=atoi( work_buffer0);[/syntax]<br /><br />Bez tej części wszystko działało dobrze a po jej dodaniu nic się nie zmieniło tylko nie zmienia zawsze temperatury. Oczywiście jeżeli już wejdzie do tego &quot;if'a&quot; to temperatura zmienia się poprawnie.<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=1096">tomasz1987</a> — 7 mar 2014, o 22:13</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[mirekk36]]></name></author>
<updated>2014-03-07T21:27:16+01:00</updated>
<published>2014-03-07T21:27:16+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=6265&amp;p=73362#p73362</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=6265&amp;p=73362#p73362"/>
<title type="html"><![CDATA[Re: [atmega8][USART] Problem z odbieraniem danych]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=6265&amp;p=73362#p73362"><![CDATA[
<div class="quotetitle">tomasz1987 napisał(a):</div><div class="quotecontent"><br />Na początek bardzo przepraszam za &quot;burdel&quot; w kodzie siądę jeszcze do niego i to poprawie.<br /></div><br /><br />Sorry ale takie posty powinny być kasowane od razu - już wyjaśniam dlaczego i dlaczego tym razem nie skasowałem<br /><br />1. słownictwo &quot;burdel&quot; nie ma nic wspólnego z tym o czym piszemy na tym forum<br />2. jeśli już taki bałaganiarski kod napisałeś - a to JEST GŁÓWNYM powodem tego że ci nie działa - to po co katujesz innych takim czymś<br />3. wklejanie takiego bałaganiarsko napisanego kodu z obietnicą że później poprawisz - pokazuje tylko jak mocno masz gdzieś tych do których zwracasz się z pytaniem<br />4. co to w ogóle za pytania na forum - polegające na wklejeniu 4 kilogramów bezładnego kodu, i do tego pytanie - &quot;dlaczego nie działa?&quot; .... toż to jakieś masakryczne podejście <img src="https://forum.atnel.pl/images/smilies/icon_e_sad.gif" alt=":(" title="Smutny" /> zero jakiejś własnej analizy, zwrócenia uwagi na to co sprawia ci problem, próby wyizolowania tego problemu - TOTALNY brak szacunku dla innych - niestety <img src="https://forum.atnel.pl/images/smilies/icon_e_sad.gif" alt=":(" title="Smutny" /><br /><br />---------------<br /><br />dlaczego nie skasowałem ? .... bo mam nadzieję, że po tych podpowiedziach wyżej kolega się poprawi na przyszłość i będzie inaczej zadawał pytania ok ?<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=54">mirekk36</a> — 7 mar 2014, o 21:27</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[siddawid]]></name></author>
<updated>2014-03-07T20:54:35+01:00</updated>
<published>2014-03-07T20:54:35+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=6265&amp;p=73356#p73356</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=6265&amp;p=73356#p73356"/>
<title type="html"><![CDATA[Re: [atmega8][USART] Problem z odbieraniem danych]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=6265&amp;p=73356#p73356"><![CDATA[
wklej tekst w syntex<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=2604">siddawid</a> — 7 mar 2014, o 20:54</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[tomasz1987]]></name></author>
<updated>2014-03-07T21:59:30+01:00</updated>
<published>2014-03-07T19:56:58+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=6265&amp;p=73350#p73350</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=6265&amp;p=73350#p73350"/>
<title type="html"><![CDATA[[atmega8][USART] Problem z odbieraniem danych]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=6265&amp;p=73350#p73350"><![CDATA[
Na początek bardzo przepraszam za nieład w kodzie siądę jeszcze do niego i to poprawie. Teraz jednak najważniejsze jest to dlaczego nie działa on tak chciałem.<br /><br />Problem jest z odbieraniem. Wysyłam z terminala nowy nastaw regulatora i niestety trzeba go prosić kilkukrotnie żeby załapał.<br />Potrafi ktoś wytłumaczyć gdzie popełniłem błąd?<br /><br /><br /><br /><br />[syntax=c]//#ifndef F_CPU  <br />  #define F_CPU   8000000UL    // 8 MHz - turn on external resonator (fuse bits)<br />//#endif<br />#include &lt;util/delay.h&gt;<br /><br /><br /><br /><br />/*This file has been prepared for Doxygen automatic documentation generation.*/   <br />/*! \file *********************************************************************  <br /> *  <br /> * \brief Example of use of general PID implementation for AVR.  <br /> *  <br /> * Example of how to setup and use the general PID implementation in pid.c.  <br /> *  <br /> * - File:               main.c  <br /> * - Compiler:           IAR EWAAVR 4.11A  <br /> * - Supported devices:  All AVR devices can be used.  <br /> * - AppNote:            AVR221 - Discrete PID controller  <br /> *  <br /> * \author               Atmel Corporation: http://www.atmel.com \n  <br /> *                       Support email: avr@atmel.com  <br /> *  <br /> * $Name: RELEASE_1_0 $  <br /> * $Revision: 1.1 $  <br /> * $RCSfile: main.c,v $  <br /> * $Date: 2006/02/16 11:46:13 $  <br /> *****************************************************************************/   <br />   <br />#include &lt;avr/io.h&gt;<br />#include &lt;stdlib.h&gt;<br />#include &lt;util/delay.h&gt;<br /><br /><br />#include &lt;inttypes.h&gt;<br />#include &lt;avr/interrupt.h&gt;<br />#include &lt;avr/pgmspace.h&gt;<br />#include &lt;avr/eeprom.h&gt;<br />#include &quot;pid.h&quot; <br />#include &quot;pomiar.h&quot; <br />#include &quot;pwm_lib.h&quot; <br />#include &quot;uart.h&quot; <br /><br />// ---- UART ----//<br /><br />unsigned char  inf&#91;33&#93; = &quot;program do akwizycji danych PID: &quot;;<br />//////////////////////////////#define UART_BAUD       9600           //prędkość transmisji<br />///////////////////////////#define UART_CONST      (F_CPU/(16ul*UART_BAUD)-1)<br /><br />#define USART0_BAUD 9600<br />#define __UBRR0 ((F_CPU+USART0_BAUD*8UL) / (16UL*USART0_BAUD)-1)//do not change<br /> <br />void USART_Init( unsigned int ubrr);<br />void USART_Transmit(char data);<br />volatile unsigned char i=0; <br />void wyslij             (char numer);<br />void wyslij_tab (uint8_t* data,uint8_t nBytes);<br />void dodaj(uint8_t* data,uint8_t nBytes);<br />void wyslij_tab_w (char* tablica, unsigned char k);<br /><br />unsigned char RS_RxD                            = 0;    // znacznik że odebrano znak<br />unsigned char RS_RxD_char                       = 0;    // odebrany znak<br /><br />// ---- UART ----<br /><br /> char temp_ASCII&#91;10&#93;; //do zamiany int na asci <br />  <br />void usat_pstr(char *s);<br />   <br />/*! \brief P, I and D parameter values  <br /> *  <br /> * The K_P, K_I and K_D values (P, I and D gains)  <br /> * need to be modified to adapt to the application at hand  <br /> */   <br />//! \xrefitem todo &quot;Todo&quot; &quot;Todo list&quot;   <br />#define K_P    0.55772 //////0.6<br />//! \xrefitem todo &quot;Todo&quot; &quot;Todo list&quot;   <br />#define K_I     0.028822//////////0.05<br />//! \xrefitem todo &quot;Todo&quot; &quot;Todo list&quot;   <br />#define K_D    0.14958//////////0.8<br /><br /><br /><br />#define cbi(sfr, bit) (_SFR_BYTE(sfr) &amp;= ~_BV(bit))<br />#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))<br /><br /><br /><br />#define diode_1 PORTD,PD6<br />#define diode_2 PORTD,PD7<br /><br />//makrodefinicje przyciskow<br />//#define Input_0  PINC, PC0<br />//#define Input_1  PINC, PC1<br /><br />#define set_high(port) sbi(port)<br />#define set_low(port)  cbi(port)<br />#define set_on(port)   sbi(port)<br />#define set_off(port)  cbi(port)<br /><br />#define is_low(port)   (bit_is_clear(port))<br />#define is_high(port)  (bit_is_set(port))<br />#define is_on(port)    (bit_is_clear(port))<br />#define is_off(port)   (bit_is_set(port))<br /><br /><br /><br /><br /><br />   <br />/*! \brief Flags for status information  <br /> */   <br />struct GLOBAL_FLAGS {   <br />  //! True when PID control loop should run one time   <br />  uint8_t pidTimer:1;   <br />  uint8_t dummy:7;   <br />} gFlags = {0, 0};   <br />   <br />//! Parameters for regulator   <br />struct PID_DATA pidData;   <br />   <br />/*! \brief Sampling Time Interval  <br /> *  <br /> * Specify the desired PID sample time interval  <br /> * With a 8-bit counter (255 cylces to overflow), the time interval value is calculated as follows:  <br /> * TIME_INTERVAL = ( desired interval &#91;sec&#93; ) * ( frequency &#91;Hz&#93; ) / 255  <br /> */   <br />//! \xrefitem todo &quot;Todo&quot; &quot;Todo list&quot;   <br />   <br />volatile uint16_t Timer1, Timer2, Timer3, Timer4;<br />int16_t  liczba;<br />int16_t nastaw= 50, nastaw2;<br /><br /><br />  // Set up timer, enable timer/counte 0 overflow interrupt   <br />void  timer0_init(void); <br />   <br />   <br />/*! \brief Init of PID controller demo  <br /> */   <br />void Init(void)   <br />{   <br />  pid_Init(K_P * SCALING_FACTOR, K_I * SCALING_FACTOR , K_D * SCALING_FACTOR , &amp;pidData);   <br />   <br /> <br />}   <br />   <br />/*! \brief Read reference value.  <br /> *  <br /> * This function must return the reference value.  <br /> * May be constant or varying  <br /> */   <br />int16_t Get_Reference(void)   <br />{  ;<br />  return nastaw;   <br />}   <br />   <br />/*! \brief Read system process value  <br /> *  <br /> * This function must return the measured data  <br /> */   <br />int16_t Get_Measurement(void)   <br />{   int16_t TempValue;<br />TempValue = PomiarTemp();<br /><br /><br />  return TempValue;   <br />}  <br /><br /><br />/*! \brief Read system process value  <br /> *  <br /> * This function must return the measured ADC <br /> */   <br />int16_t Get_ADC(void)   <br />{   int16_t TempValue;<br />TempValue = PomiarADC();<br /><br /><br />  return TempValue;   <br />}  <br />   <br />/*! \brief Set control input to system  <br /> *  <br /> * Set the output from the controller as input  <br /> * to system.  <br /> */   <br />void Set_Input(int16_t inputValue)   <br />{   <br />if(inputValue&gt;32767) inputValue=32767;<br />if(inputValue&lt;1) inputValue=0;<br />  pwm_set_a(inputValue);   <br />}   <br /><br />void zamien_na_ASCII (unsigned int liczba);<br /><br /><br />// int x=100;  <br />/*! \brief Demo of PID controller  <br /> */   <br /><br /><br />/************************************************************************************<br /> *                                              USART0 receiver                                             *<br /> ************************************************************************************/<br />#define RX0_BUFFER_SIZE 16<br />#define RX0_BUFFER_MASK (RX0_BUFFER_SIZE-1)//do not change<br /> <br />/************************************************************************************<br /> *                                              USART0 transmitter                                          *<br /> ************************************************************************************/<br />#define TX0_BUFFER_SIZE 16<br />#define TX0_BUFFER_MASK (TX0_BUFFER_SIZE-1)//do not change<br /><br /> char work_buffer0&#91;RX0_BUFFER_SIZE&#93;;<br /><br /><br /><br />int main(void)   <br />{   <br /><br /><br /><br /><br />DDRD =  0b11111111; //0 = wejście 1 = wyjscie<br />PORTD=  0b11111111; //1 = podciaganie<br />DDRC =  0b11011111; //0 = wejście 1 = wyjscie<br />PORTC=  0b11111111; //1 = podciaganie<br />DDRB =  0b11111111; //0 = wejście 1 = wyjscie<br />PORTB=  0b11111111; //1 = podciaganie///7 6 5 4 3 2 1 0<br /><br /><br /><br /><br /><br /><br /><br />  timer0_init();  <br />  Init();  <br />  PomiarInit(); <br /> pwm_init(); <br /><br /> uart_init(0, __UBRR0);<br />        sei();<br /><br />/////////////////////////////////////////////////////USART_Init(UART_CONST); // inicjalizacja portu szeregowego <br />//USART_int_enable;<br />  ///////////////////////////////////////////////////// sei(); // odblokowanie przerwan <br />  ///////////////////////////////////////////////// wyslij_tab_w(inf,32);<br /><br />   <br /><br />int16_t referenceValue=0 , measurementValue=0 , inputValue=0,  measurementADC;  <br /><br />  while(1){   <br />   <br /><br />if(UCSRA &amp; _BV(RXC)){<br />//Timer1=200;//125co 500 msekunde<br />uart_get_string(0, work_buffer0);<br />PORTD^= (1&lt;&lt;PD6);<br />nastaw=atoi( work_buffer0);<br /><br />}  <br /><br /><br /><br />   /*! \brief Timer interrupt to control the sampling interval  <br /> */<br />    <br />if(!Timer1){<br />Timer1=250;//125co 500 msekunde<br />gFlags.pidTimer = TRUE;<br /><br />}  <br /><br /><br /><br /><br />    // Run PID calculations once every PID timer timeout   <br />    if(gFlags.pidTimer)   <br />    {   <br /><br />      referenceValue = Get_Reference();   <br />      measurementValue = Get_Measurement();<br />  measurementADC = Get_ADC();<br />    <br />   <br />      inputValue = pid_Controller(referenceValue, measurementValue, &amp;pidData);   <br />   <br />      Set_Input(inputValue);   <br />   <br />      gFlags.pidTimer = FALSE;   <br /><br />  if(!Timer2){<br />  <br />Timer2=500;//co 1 sekunde<br /> // uart_put_string(0,&quot;temp : &quot;);<br />uart_put_int(0,measurementValue);<br />//uart_put_int(0,measurementADC);<br /><br />//uart_put_string(0,&quot;\r\n&quot;);<br /><br /><br />uart_put_char(0,' ');<br />uart_put_int(0,inputValue);<br />uart_put_string(0,&quot;\r\n&quot;);<br />} <br />    } <br /><br /><br /><br /><br />  <br />  }   <br />}   <br /> <br /> <br /><br /> <br />/*! \mainpage  <br /> * \section Intro Introduction  <br /> * This documents data structures, functions, variables, defines, enums, and  <br /> * typedefs in the software for application note AVR221.  <br /> *  <br /> * \section CI Compilation Info  <br /> * This software was written for the IAR Embedded Workbench 4.11A.  <br /> *  <br /> * To make project:  <br /> * &lt;ol&gt;  <br /> * &lt;li&gt; Add the file main.c and pid.c to project.  <br /> * &lt;li&gt; Under processor configuration, select desired Atmel AVR device.  <br /> * &lt;li&gt; Enable bit definitions in I/O include files  <br /> * &lt;li&gt; High optimization on speed is recommended for best performance  <br /> * &lt;/ol&gt;  <br /> *  <br /> * \section DI Device Info  <br /> * The included source code is written for all Atmel AVR devices.  <br /> *  <br /> * \section TDL ToDo List  <br /> * \todo Put in own code in:  <br /> * \ref Get_Reference(void), \ref Get_Measurement(void) and \ref Set_Input(int16_t inputValue)  <br /> *  <br /> * \todo Modify the \ref K_P (P), \ref K_I (I) and \ref K_D (D) gain to adapt to your application  <br /> * \todo Specify the sampling interval time \ref TIME_INTERVAL  <br /> */<br /><br /><br /><br />void timer0_init(void){<br />TCCR0|=(1&lt;&lt;CS00)|(1&lt;&lt;CS01);  /// prescaler na 64<br />TIMSK|= 1&lt;&lt;TOIE0; ///właczenie przerwania od przepełnienia<br />TCNT0=131;        /// wartość początkowa rejestru<br />}<br /><br /><br /><br />ISR(TIMER0_OVF_vect){<br />uint16_t n;<br />n=Timer1;<br />if(n) Timer1 = --n;<br />n=Timer2;<br />if(n) Timer2 = --n;<br />n=Timer3;<br />if(n) Timer3 = --n;<br />n=Timer4;<br />if(n) Timer4 = --n;<br /><br /><br /> <br /><br /><br /><br /><br />}<br /><br /><br /><br /><br /><br /><br />/*! \brief PID control algorithm.  <br /> *  <br /> *  Calculates output from setpoint, process value and PID status.  <br /> *  <br /> *  \param setPoint  Desired value.  <br /> *  \param processValue  Measured value.  <br /> *  \param pid_st  PID status struct.  <br /> */   <br />int16_t pid_Controller(int16_t setPoint, int16_t processValue, struct PID_DATA *pid_st)   <br />{   <br />  int16_t error, p_term, d_term;   <br />  int32_t i_term, ret, temp;   <br />   <br />  error = setPoint - processValue;   <br />   <br />  // Calculate Pterm and limit error overflow   <br />  if (error &gt; pid_st-&gt;maxError){   <br />    p_term = MAX_INT;   <br />  }   <br />  else if (error &lt; -pid_st-&gt;maxError){   <br />    p_term = -MAX_INT;   <br />  }   <br />  else{   <br />    p_term = pid_st-&gt;P_Factor * error;   <br />  }   <br />   <br />  // Calculate Iterm and limit integral runaway   <br />  temp = pid_st-&gt;sumError + error;   <br />  if(temp &gt; pid_st-&gt;maxSumError){   <br />    i_term = MAX_I_TERM;   <br />    pid_st-&gt;sumError = pid_st-&gt;maxSumError;   <br />  }   <br />  else if(temp &lt; -pid_st-&gt;maxSumError){   <br />    i_term = -MAX_I_TERM;   <br />    pid_st-&gt;sumError = -pid_st-&gt;maxSumError;   <br />  }   <br />  else{   <br />    pid_st-&gt;sumError = temp;   <br />    i_term = pid_st-&gt;I_Factor * pid_st-&gt;sumError;   <br />  }   <br />   <br />  // Calculate Dterm   <br />  d_term = pid_st-&gt;D_Factor * (pid_st-&gt;lastProcessValue - processValue);   <br />   <br />  pid_st-&gt;lastProcessValue = processValue;   <br />   <br />  ret = (p_term + i_term + d_term) / SCALING_FACTOR;   <br />  if(ret &gt; MAX_INT){   <br />    ret = MAX_INT;   <br />  }   <br />  else if(ret &lt; -MAX_INT){   <br />    ret = -MAX_INT;   <br />  }   <br />   <br />  return((int16_t)ret);   <br />}[/syntax]<br /><br /><span style="color: #FF0000">[ kod źródłowy wklejamy w znaczniki [ syntax = c ] .... wyedytuj proszę ten swój post i zobacz jak się to robi - mirekk36 ]</span><p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=1096">tomasz1987</a> — 7 mar 2014, o 19:56</p><hr />
]]></content>
</entry>
</feed>