Page 1 of 1

mathematical calculations in the simulation and the real pro

Posted: Sun Sep 27, 2015 11:57 am
by siwo278
mathematical calculations in the simulation and the real program - different results

Hello

What is the difference between the simulation and the actual operation of the program in the CPU in mathematical calculations? In my program I set day of the week based on such date: 01.01. (20) 00 this Saturday. In the simulation FLOWCODE program it works correctly. After programming the operation of the processor PIC18F46K22 calculation differs from the real. What mistakes committed in the program?

obliczenia matematyczne w symulacji a realny program - różne wyniki

Witam

Jaka jest różnica pomiędzy symulacją a właściwym działaniem programu w procesorze w obliczeniach matematycznych? W moim programie wyznaczam dzień tygodnia na podstawie daty np: 01.01.(20)00 to sobota. W symulacji flowcode program działa poprawnie. Po zaprogramowaniu procesora PIC18F46K22 działanie obliczeń odbiega od realnych. Jakie błędy popełniłam w programie?

Natalia

Re: mathematical calculations in the simulation and the real

Posted: Sun Sep 27, 2015 12:50 pm
by kersing
What is the result on hardware and what are you expecting? Currently you seem to expect us to look at 25 macros and guess what the problem might be. Please provide more details as to what the error is and where we can find the calculations you are referring to.
Please do not forget you know what your program is supposed to do, we have to reverse engineer the code and guess what you expect to happen.

Re: mathematical calculations in the simulation and the real

Posted: Sun Sep 27, 2015 1:12 pm
by siwo278
Hello

I'm sorry not clarified questions. As for the calculation of the date of the macro "DZIEN_TYGODNIA" - a processing algorithm of calculating the day of the week based on the date. In the simulation, the algorithm correctly computes flowkode day of the week and the real program on the processor completely lost calculations - does not set correct day of the week. This algorithm which determines the day of the week by date http://www.algorytm.org/przetwarzanie-d ... odnia.html

Witam

Przepraszam nie doprecyzowałam pytania. Chodzi o obliczenia daty w makro "DZIEN_TYGODNIA" - jest to przeróbka algorytmu wyznaczania dnia tygodnia na podstawie daty. W symulacji flowkode algorytm poprawnie oblicza dzień tygodnia a w realnym programie na procesorze zupełnie gubi obliczenia - nie wyznacza poprawnie dnia tygodnia. To algorytm który wyznacza dzień tygodnia na podstawie daty http://www.algorytm.org/przetwarzanie-d ... odnia.html

Re: mathematical calculations in the simulation and the real

Posted: Sun Sep 27, 2015 1:23 pm
by medelec35
I have used:
Flowcode DOTW calculation.png
(1.54 KiB) Downloaded 9355 times
Month Code:
Monthcode.png
(3.7 KiB) Downloaded 9355 times
Year is just the last two digits of the year.
The Date-1 and Date+1 is for RTC I was using.
So thay can be removed of you want the results to be from 0 to 6 instead of 1 to 7
Works with Flowcode simulator and on hardware

Martin

Re: mathematical calculations in the simulation and the real

Posted: Sun Sep 27, 2015 1:57 pm
by siwo278
Hey

Cool algorithm. And could I bring it more mathematically?
Since my English is at the level of buying flowers. It is rather simple - Sunday? - Number Monday? - number

if so, I mean?

2015 years - (15 + 1) - year
27 days of the month - date
09 months - MonthCode

the extent to which year is this algorithm correct, could you bring me how to interpret tables Monthcode

my rtc is encoded as in the picture

Cześć

Fajny algorytm. A mógłbyś mi go bardziej przybliżyć matematycznie?
Ponieważ mój angielski jest na poziomie kupowania kwiatków. To raczej prosto - niedziela?- numer, poniedziałek? - numer

czy tak to mam rozumieć?

2015 rok - (00+1) - year
27 dzień miesiąca - date
09 miesiąc - MonthCode

w jakim zakresie lat jest ten algorytm prawidłowy, mogłbyś mi przybliżyć jak interpretować tabele Monthcode

mój rtc ma kodowanie jak na zdjęciu

Re: mathematical calculations in the simulation and the real

Posted: Sun Sep 27, 2015 5:03 pm
by medelec35
Hi siwo278,
siwo278 wrote:Cool algorithm.
Thanks.
If you remove all the 1's as stated in the previous email i.e.

Code: Select all

DayNum = (Date  + MonthCode + Year + (Year / 4)) MOD 7
Then Daynum will match what you have posted.
E.g Sun = 0, Mon = 1 ..........Sat = 6
You can use the switch component to convert month to MonthCode:
Monthcode.png
(12.1 KiB) Downloaded 4364 times
So if you have
27
09
15
then the 9 will be converted to 5 (just like in the JFMAMJJOSOND table I posted.

Note: The

Code: Select all

Year % 4 = 0
is just checking if the year is disable by 4.
Where % = Mod
If it is then it's a different branch for Jan & Feb.

Hope this helps

Re: mathematical calculations in the simulation and the real

Posted: Mon Sep 28, 2015 9:41 am
by siwo278
Hello

Replacing an algorithm that calculates the day of the week helped , now and simulation and realistic program calculate correctly . The above error dimmed further problems in the operation of the program. The problem is now interrupt TMR0 and faulty billing days during data input by the user. TMR0 is set to internal clock CLKO and has a value of 100Hz , and everything is driven quartz 3,2768MHz , if it's all good simulation runs in real time system interrupt it once does not start.
2.Wadliwe charging units days - in a user enters days by + and - keys . In the simulation work all the conditions of the top and bottom limit to the number of days for the month , in the real system as if they were not there . (Macro USTAWIANIE_ZEGARA )

Witam

Wymiana algorytmu obliczającego dzień tygodnia pomogła, teraz i symulacja i realny program obliczają poprawnie. Powyższy błąd zaćmił dalsze problemy w działaniu programu. Problemem są teraz przerwania od TMR0 i wadliwe naliczanie dni podczas wprowadzania danych przez użytkownika. TMR0 jest ustawione na wewnetrznym zegarze CLKO i ma wartość 100Hz, a wszystko jest napędzane kwarcem 3,2768MHz, o ile w symulacji to wszystko fajnie działa to w realnym układzie przerwanie to raz jest raz nie startuje.
2.Wadliwe naliczanie jednostek dni - w układzie użytkownik wprowadza dni poprzez klawisze + i -. W symulacji działaja wszystkie warunki od góry i dołu ograniczenia ilości dni dla danego miesiąca, w realnym układzie tak jak by ich nie było.(maCro USTAWIANIE_ZEGARA)

Re: mathematical calculations in the simulation and the real

Posted: Tue Sep 29, 2015 6:38 am
by siwo278
Hello

It works ! Cause trouble was bad code word processor , and two variables that introduce errors in the calculation day of the week , which varied ranges of numbers used in the program . Thank you all for your help, especially colleague " medelec35 " - (Algorithm - day of the week ) - for the attention that each algorithm can be simplified .

Witam

Działa! Przyczyna kłopotów było złe słowo kodowe procesora, i dwie zmienne, które wprowadzały błędy w obliczeniach dnia tygodnia, co zmieniało zakresy liczb używanych w programie. Dziękuję wszystkim za pomoc, szczególnie koledze "medelec35" - (algorytm - dzien tygodnia) - za zwrócenie uwagi że każdy algorytm można uprościć.

Natalia