Home
Prox / RFID
Verichips
Ladder Logic
[interfacing] †
Tube Joints
Key Code From Photo
SolveSpace (3d CAD)
SketchFlat (2d CAD)
Photographs
Miscellany
Resume / Consulting
Contact Me

LDmicro Forum - A problem with substracting 2 values

(you are viewing a thread; or go back to list of threads)

A problem with substracting 2 values (by MGP)
Can someone look at this or try it or simulate it in Proton?

I have been programming a wheelchair motor controller for a month now and every time when the joystick was converted something went wrong .

Now I have found the following problem.

The compiler cannot calculate rung 6, everything works normally in the simulator but when I program the pic (16F886) the value stays at zero.
Also with a 16F1827 I get the same problem and I think the problem is in the compiler.

Or is there something I do wrong? because when adding it works.
Thu Feb 27 2020, 08:27:40, download attachment Calc_16F886_testV2.ld
(no subject) (by Paulino)
for MGP, if you subtract 100 to 50 you have 50 left. If you subtract 99 to 50 you have 49 left, I mean that the result will give you 50-1 = 49.
we have to take into account that LDMicro does not do decimals
MOV duty 50
SUb duty 200
duty sera = 150

por MGP, si resta 100 a 50 te quedan 50. si se resta 99 a 50 te quedan 49, quiero decir que el resultado te dará 50-1=49.
devemos tener en cuenta que no hace LDMicro decimales,
MOV duty 50
SUb duty 200
duty sera = 150
Thu Feb 27 2020, 09:16:46
(no subject) (by Paulino)
Your program is giving the same result if you subtract as if you do not subtract since the result will always be 50.
  Example: 50-100 = 50 which is the same 100-50 = 50.

do this test: MOV duty 100
                  SUb duty 100
the result duty = 0

Conclusion: the subtraction must never be greater than the operand.

do this test: MOV duty 100
                  SUb duty 50
the result duty = 50

Tu programa esta dando el mismo resultado si restas como si no restas ya que el resultado siempre sera 50.
Ejemplo: 50-100=50 que es lo mismo 100-50=50.

haz esta prueba: MOV duty 100
SUb duty 100
el resultado duty =0

Conclusión: nunca debe ser la resta mayor que el operando.

haz esta prueba: MOV duty 100
SUb duty 50
el resultado duty =50
Thu Feb 27 2020, 09:34:06
(no subject) (by MGP)
You can replace 'duty' by any number <100 and it still does not work.
The result is always zero.
I know that LDmicro can calculate only with integer numbers and I dont use decimals in this example.


It works in the simulator, why not in real?
Thu Feb 27 2020, 10:12:30
(no subject) (by MGP)
If you change the SUB instruction in an ADD instruction the result in real is 200, in the simulator it is 150 as it should be.
Thu Feb 27 2020, 10:45:25
(no subject) (by Paulino)
I think you have the error in the internal filter test with an external filter, I have had according to what software since it gave me errors, but other software in PIC have worked for me, interference noise (Emi filters).
it becomes like the forum that blames the LDmicro for errors and then it turns out that the error is in proteus etc.

If the simulation in LDmicro is correct, the error is external to

Try to place an external glass and cancel the internal one, I think it will work for you.

but it works for you to communicate it and I will continue checking.

Creo que el error lo tienes en el filtro interno prueba con un filtro externo, yo he tenido en según que software ya que me daba errores, pero otros software en PIC me han funcionado, los ruidos interferencias (filtros Emi).
viene a ser como en el foro que culpan al LDmicro los errores y luego resulta que el error esta en proteus etc.

si la simulacion en LDmicro la ves correcta, el error es externo a

Prueba a colocar un cristal externo y anula el interno, creo que te funcionara.

sino te funciona comunicarlo y seguiré verificando.
Thu Feb 27 2020, 13:03:52
(no subject) (by MGP)
Paulino ..seriously .... (☉_☉)

To Ihor:

To come back to my problem again.

That program was now tested on a 16F628a with 20MHz crystal and the errors remain.

Multiplication and division work perfectly.

100 x duty(50) = 5000
100 / duty(50) = 2

Addition and subtraction are wrong.
100 + duty(50) = 200
100 - duty(50) = 0

I suspect the compiler.

attachment = addition.
Fri Feb 28 2020, 07:32:08, download attachment P1020536.JPG
(no subject) (by MGP)
Now the multiplication.
Fri Feb 28 2020, 07:33:08, download attachment P1020539.JPG
(no subject) (by MGP)
Attached the 16F628a addition program.
Fri Feb 28 2020, 07:40:26, download attachment Calc_16F628a_ADD_test.ld
por MGP) (by Paulino)
Pass me the program in .LD and you: hex.
and I will do the tests and if I see the error I will tell you since this weekend I will be free and I will be able to try it live.
If for any circusntacia you do not want to load it through this forum, [email protected]
Fri Feb 28 2020, 07:42:50
(no subject) (by Ihor Nehrutsa)
There is a bug.

Addition and subtraction are wrong.
100 + duty(50) = 200
100 - duty(50) = 0

The issue is created.
https://github.com/LDmicro/LDmicro/issues/214

Will fixed.

Thanks for the good explanation of the bug.
Fri Feb 28 2020, 13:41:53
(no subject) (by MGP)
Ok, thanks for the reply.
Fri Feb 28 2020, 15:57:44
hex (by Paulino)
If it is wrong, because in version 2 it is done correctly, I attach a .hex file for you to try.
MPG try this .hex and tell me if it works for me it works well for me.
Sat Feb 29 2020, 07:59:38, download attachment Calc_16F628a_ADD_test.hex
(no subject) (by MGP)
I tested it this morning with different versions of LDmicro that worked well then, in version 3540 it works as it should and from version 4430 on it no longer works.
Sat Feb 29 2020, 09:11:18
(no subject) (by Paulino)
OK perfect ihor will solve it in the next version as they persist in atmega8. Thanks for your support.
I know it's not a good solution but sometimes you have to use previous versions to see where the error is.

OK perfecto ihor ya lo solucionara en loa próxima versión como el persisten en atmega8. gracias por vuestro apoyo.
ya se que no es buena solución pero a veces hay que usar versiones anteriores para ver donde esta el error.
Sat Feb 29 2020, 10:18:05
Para ihor (by Paulino)
Hello, I saw how the sum is solved, I think it is because of the cycle that is done in different lines if it is placed on the same line it works correctly.
I attached the 2 .LD
This is correct

Hola ya vi como se soluciona la suma, creo que es por el ciclo que se hace en lineas diferentes si se coloca en la misma linea funciona correcto.
te adjunto las 2 .LD
este es correcto
Sat Feb 29 2020, 11:45:41, download attachment Calc_16F628a_ADD_testpaulino.ld
ihor (by Paulino)
This are different lines of the .LD. By MPG
This is the wrong one that fails once compiled, it is curious since in LDMicro with the Simulation it gives it correct.
greetings Paulino

Este son lineas diferentes del .LD. Por MPG
este es el incorrecto el que da fallo una vez copilado, es curioso ya que en LDMicro con la Simulación lo da correcto.
saludos Paulino
Sat Feb 29 2020, 11:50:46, download attachment Calc_16F628a_ADD_test.ld
Post a reply to this comment:
Your Name:
Your Email:
Subject:
(no HTML tags; use plain text, and hit Enter for a line break)
Attached file (if you want, 5 MB max):