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

<title>ATNEL tech-forum</title>
<link href="https://forum.atnel.pl/index.php" />
<updated>2014-11-14T13:06:40+01:00</updated>

<author><name><![CDATA[ATNEL tech-forum]]></name></author>
<id>https://forum.atnel.pl/feed.php?f=4&amp;t=9232&amp;mode</id>
<entry>
<author><name><![CDATA[MirkoT]]></name></author>
<updated>2014-11-14T13:06:40+01:00</updated>
<published>2014-11-14T13:06:40+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=9232&amp;p=103930#p103930</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=9232&amp;p=103930#p103930"/>
<title type="html"><![CDATA[Re: Sterownik PID kompilacja/ błędy w programie]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=9232&amp;p=103930#p103930"><![CDATA[
Te błędy oznaczają wielkrotną definicję<br />Sprawdź we wszystkich plikach czy nie masz <br />użytych tych samych nazw<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=189">MirkoT</a> — 14 lis 2014, o 13:06</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[Gonzales1891]]></name></author>
<updated>2014-11-14T12:48:52+01:00</updated>
<published>2014-11-14T12:48:52+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=9232&amp;p=103926#p103926</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=9232&amp;p=103926#p103926"/>
<title type="html"><![CDATA[Re: Sterownik PID kompilacja/ błędy w programie]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=9232&amp;p=103926#p103926"><![CDATA[
funkcję main mam w innym pliku źródłowym, faktycznie przeoczyłem deklarację funkcji DS18b20.<br /><br />W dalszym ciągu kompilator wyrzuca <br />Building target: pid.elf<br />Invoking: AVR C Linker<br />avr-gcc -Wl,-Map,pid.map -mmcu=atmega8 -o &quot;pid.elf&quot;  ./ds18b20.o ./hd44780.o ./kbd4x4.o ./main.o ./pid.o ./pid_an.o ./pid_cy.o   <br /><br />./pid_cy.o: In function `__vector_9':<br />pid_cy.c:(.text+0x0): multiple definition of `__vector_9'<br />./pid_cy.o:(.bss+0x0): multiple definition of `gFlags'<br />./pid_cy.o: In function `Set_Input':<br />pid_cy.c:(.text+0x4e): multiple definition of `Set_Input'<br />./pid_an.o:pid_an.c:(.text+0xd2): first defined here<br />./pid_cy.o: In function `Get_Measurement':<br />pid_cy.c:(.text+0x66): multiple definition of `Get_Measurement'<br />./pid_cy.o: In function `Get_Reference':<br />pid_cy.c:(.text+0xd6): multiple definition of `Get_Reference'<br />./pid_cy.o: In function `Init':<br />pid_cy.c:(.text+0xde): multiple definition of `Init'<br />make: *** [pid.elf] Error 1<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=6173">Gonzales1891</a> — 14 lis 2014, o 12:48</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[MichalXY]]></name></author>
<updated>2014-11-13T21:17:35+01:00</updated>
<published>2014-11-13T21:17:35+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=9232&amp;p=103858#p103858</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=9232&amp;p=103858#p103858"/>
<title type="html"><![CDATA[Re: Sterownik PID kompilacja/ błędy w programie]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=9232&amp;p=103858#p103858"><![CDATA[
Cześć!<br /><br />Tak analizując kod na szybko poraziła mnie ta funkcja a raczej obsługa przerwania wg. kompilatora IAR<br /><br />[syntax=c]__interrupt void TIMER0_OVF_ISR( void )<br />{<br />  static uint16_t i = 0;<br />  if(i &lt; TIME_INTERVAL)<br />    i++;<br />  else{<br />    gFlags.pidTimer = TRUE;<br />    i = 0;<br />  }<br />}[/syntax]<br /><br />Powinno być tak: <br /><br />[syntax=c]ISR(TIMER0_OVF_vect)<br />{<br />static uint16_t i = 0;<br />  if(i &lt; TIME_INTERVAL)<br />    i++;<br />  else{<br />    gFlags.pidTimer = TRUE;<br />    i = 0;<br />}[/syntax]<br /><br />Oczywiście już nie wnikam czy ciało obsługi przerwania jest poprawne... <br /><br />Dalej [syntax=c]__enable_interrupt();[/syntax] zamienić na polecenie sei(); <br /><br />Kolejny problem to brak pętli głównej programu int main(void) ty masz jakaś funkcję i kompilator za choinkę nie wie gdzie jest owa pętla główna <br /><br />czyli winno być tak: <br /><br />[syntax=c]int main(void)<br />{<br /> Init();<br />  sei();<br /><br /> <br /> <br />  while(1)<br />  {<br />    // Run PID calculations once every PID timer timeout<br />    if(gFlags.pidTimer)<br />    {<br />      referenceValue = Get_Reference();<br />      measurementValue = Get_Measurement();<br /> <br />      inputValue = pid_Controller(referenceValue, measurementValue, &amp;pidData);<br /> <br />      Set_Input(inputValue);<br /> <br />      gFlags.pidTimer = FALSE;<br />    }<br />  }<br />}[/syntax]<br /><br />Co do reszty to nie wypowiadam się bo nie analizowałem dogłębnie bibliotek atmela do PIDa. <br />Pozdrawiam!<br /><br />P.S nie widzę nigdzie deklaracji funkcji odpowiedzialnych za obsługę DS18B20 z którego korzystasz w programie a o to też kompilator krzyczy<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=226">MichalXY</a> — 13 lis 2014, o 21:17</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[Gonzales1891]]></name></author>
<updated>2014-11-13T20:28:12+01:00</updated>
<published>2014-11-13T20:28:12+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=9232&amp;p=103829#p103829</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=9232&amp;p=103829#p103829"/>
<title type="html"><![CDATA[Sterownik PID kompilacja/ błędy w programie]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=9232&amp;p=103829#p103829"><![CDATA[
Witam szanownych kolegów <br /><br />Borykam się od pewnego czasu z regulatorem PID na Atmege8. Atmel dostarcza biblioteki ale wymagają one przeróbek, po dokonaniu kilku okazało się że coś jest nie tak i program się nie kompiluje (gdzieś tkwi błąd), prześledziłem kod i może ktoś bardziej obeznany z językiem będzie w stanie pomóc i wyłapać błąd.<br /><strong>pid_cy.c</strong><br />[syntax=c]#include &lt;avr/io.h&gt;<br />#include &lt;avr/interrupt.h&gt;<br />#include &lt;util/delay.h&gt;<br />#include &lt;avr/iom8.h&gt;<br />#include &quot;stdint.h&quot;<br />#include &quot;pid.h&quot;<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     1.00<br />//! \xrefitem todo &quot;Todo&quot; &quot;Todo list&quot;<br />#define K_I     0.00<br />//! \xrefitem todo &quot;Todo&quot; &quot;Todo list&quot;<br />#define K_D     0.00<br /><br /><br /> int16_t referenceValue, measurementValue, inputValue;<br />/*! brief Flags for status information<br /> */<br />struct GLOBAL_FLAGS<br />{<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 />#define TIME_INTERVAL   3922 // zmieniłem ze 157 po obliczeniach 3922<br /><br />/*! \brief Timer interrupt to control the sampling interval<br /> */<br />#pragma vector = TIMER0_OVF_vect<br />__interrupt void TIMER0_OVF_ISR( void )<br />{<br />  static uint16_t i = 0;<br />  if(i &lt; TIME_INTERVAL)<br />    i++;<br />  else{<br />    gFlags.pidTimer = TRUE;<br />    i = 0;<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 />  // Set up timer, enable timer/counte 0 overflow interrupt<br />  TCCR0 = (1&lt;&lt;CS00);<br />  TIMSK = (1&lt;&lt;TOIE0);<br />  TCNT0 = 0;<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 />temp_zad();<br />  return 8;<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 />double temp;                  // temp przechowuje aktualną temperaturę<br />unsigned char ds18b20_pad&#91;9&#93;; // w tablicy ds18b20 są przechowywane dane z czujnika<br />if (ds18b20_ConvertT())<br />{<br />_delay_ms(750);   // 750ms czas konwersji<br />ds18b20_Read(ds18b20_pad);// Odczyt z układu ds18b20 i zapis dwóch bajtów do tablicy ds18b20_pad<br />temp = ((ds18b20_pad&#91;1&#93; &lt;&lt; 8) + ds18b20_pad&#91;0&#93;)/16.0;<br />measurementValue=temp;//TUTAJ WYNIK ( WARTOSC CYFROWEGO CZUJNIKA TEMPERATURY)<br />}<br />return 4;<br />}<br /><br />/*! \brief Set control input to system<br /> *<br /> * Set the output from the controller as input<br /> * to system. wyjcie z kontrolera wejciem do obiektu czyli sygnał PWM<br /> */<br />void Set_Input(int16_t inputValue)<br />{<br />DDRB |=(1&lt;&lt;PB1);<br />TCCR1A |= (1&lt;&lt;WGM10);// tryb fast PWM<br />TCCR1A |= (1&lt;&lt;COM1A1);<br />TCCR1B |= (1&lt;&lt;CS10); // preskaler na 1 fpwm=3,9kHz przy f_cpu 1MHz<br />OCR2=inputValue  ;<br />}<br /><br /><br />/*! \brief Demo of PID controller<br /> */<br />void pid_cy(void)<br />{<br /><br />  Init();<br />  __enable_interrupt();<br />  <br /><br />  while(1)<br />  {<br />    // Run PID calculations once every PID timer timeout<br />    if(gFlags.pidTimer)<br />    {<br />      referenceValue = Get_Reference();<br />      measurementValue = Get_Measurement();<br /><br />      inputValue = pid_Controller(referenceValue, measurementValue, &amp;pidData);<br /><br />      Set_Input(inputValue);<br /><br />      gFlags.pidTimer = FALSE;<br />    }<br />  }<br />}[/syntax]<br /><br /><br /><strong>pid.c</strong><br />[syntax=c]#include &quot;pid.h&quot;<br />#include &quot;stdint.h&quot;<br /><br />/*! \brief Initialisation of PID controller parameters.<br /> *<br /> *  Initialise the variables used by the PID algorithm.<br /> *<br /> *  \param p_factor  Proportional term.<br /> *  \param i_factor  Integral term.<br /> *  \param d_factor  Derivate term.<br /> *  \param pid  Struct with PID status.<br /> */<br />void pid_Init(int16_t p_factor, int16_t i_factor, int16_t d_factor, struct PID_DATA *pid)<br />// Set up PID controller parameters<br />{<br />  // Start values for PID controller<br />  pid-&gt;sumError = 0;<br />  pid-&gt;lastProcessValue = 0;<br />  // Tuning constants for PID loop<br />  pid-&gt;P_Factor = p_factor;<br />  pid-&gt;I_Factor = i_factor;<br />  pid-&gt;D_Factor = d_factor;<br />  // Limits to avoid overflow<br />  pid-&gt;maxError = MAX_INT / (pid-&gt;P_Factor + 1);<br />  pid-&gt;maxSumError = MAX_I_TERM / (pid-&gt;I_Factor + 1);<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 />}<br /><br />/*! \brief Resets the integrator.<br /> *<br /> *  Calling this function will reset the integrator in the PID regulator.<br /> */<br />void pid_Reset_Integrator(pidData_t *pid_st)<br />{<br />  pid_st-&gt;sumError = 0;<br />}[/syntax]<br /><br /><strong>pid.h</strong><br />[syntax=c]#ifndef PID_H<br />#define PID_H<br /><br />#include &quot;stdint.h&quot;<br /><br />#define SCALING_FACTOR  128<br /><br />/*! \brief PID Status<br /> *<br /> * Setpoints and data used by the PID control algorithm<br /> */<br />typedef struct PID_DATA{<br />  //! Last process value, used to find derivative of process value.<br />  int16_t lastProcessValue;<br />  //! Summation of errors, used for integrate calculations<br />  int32_t sumError;<br />  //! The Proportional tuning constant, multiplied with SCALING_FACTOR<br />  int16_t P_Factor;<br />  //! The Integral tuning constant, multiplied with SCALING_FACTOR<br />  int16_t I_Factor;<br />  //! The Derivative tuning constant, multiplied with SCALING_FACTOR<br />  int16_t D_Factor;<br />  //! Maximum allowed error, avoid overflow<br />  int16_t maxError;<br />  //! Maximum allowed sumerror, avoid overflow<br />  int32_t maxSumError;<br />} pidData_t;<br /><br />/*! \brief Maximum values<br /> *<br /> * Needed to avoid sign/overflow problems<br /> */<br />// Maximum value of variables<br />#define MAX_INT         INT16_MAX<br />#define MAX_LONG        INT32_MAX<br />#define MAX_I_TERM      (MAX_LONG / 2)<br /><br />// Boolean values<br />#define FALSE           0<br />#define TRUE            1<br /><br />void pid_Init(int16_t p_factor, int16_t i_factor, int16_t d_factor, struct PID_DATA *pid);<br />int16_t pid_Controller(int16_t setPoint, int16_t processValue, struct PID_DATA *pid_st);<br />void pid_Reset_Integrator(pidData_t *pid_st);<br /><br />#endif[/syntax]<br /><br />wynik z konsoli <br />warning: ignoring #pragma vector <br />../pid_cy.c:67: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'void'<br />../pid_cy.c: In function 'Get_Reference':<br />../pid_cy.c:97: warning: implicit declaration of function 'temp_zad'<br />../pid_cy.c: In function 'Get_Measurement':<br />../pid_cy.c:109: warning: implicit declaration of function 'ds18b20_ConvertT'<br />../pid_cy.c:112: warning: implicit declaration of function 'ds18b20_Read'<br />make: *** [pid_cy.o] Error 1<br /><br /><br />niepokoi mnie fragment <strong>#pragma vector = TIMER0_OVF_vect<br />__interrupt void TIMER0_OVF_ISR( void )<br /></strong><br />jak się domyślam jest to związane z przerwaniem tyle że w tej czerwonej linii eclips wskazuje błąd. <br />Kolejnym pytaniem jest zezwolenie na przerwanie jak się ono odbywa ( linia __enable interrupt ?). <br /><br /><br />Mam nadzieję że ktoś z was jest w stanie mi pomóc z tym niechlujnym (przez to że jestem nowicjuszem) kodem <br /><br />Pozdrawiam<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=6173">Gonzales1891</a> — 13 lis 2014, o 20:28</p><hr />
]]></content>
</entry>
</feed>