* * *

Author Topic: PicPas, Pascal compiler for Microchip PIC  (Read 25624 times)

Edson

  • Hero Member
  • *****
  • Posts: 831
Re: PicPas, Pascal compiler for Microchip PIC
« Reply #135 on: January 13, 2018, 05:19:24 am »

Code: Pascal  [Select]
  1.     0x005 bcf PORTB, 5

In case if 1 on PORTB.4, output PORTB.5 will make fast pulsation? Is it right?
I think will be right to make any changes in result only AFTER checking of input value.
Tried to simulate in Proteus, and found my laptop have not enough power to simulate this fast pulsation  :(
Am I right?

PS We can see it in ASM Debugger if we change the string to PORTB.5 := not PORTB.4;
PORTB.5 blinking because there bcf PORTB, 5 before btfss PORTB, 4

You are right. The code to copy bit PORTB.4 to PORTB.5:

    0x005 bcf PORTB, 5
    0x006 btfsc PORTB, 4
    0x007 bsf PORTB, 5

Could cause a fast pulse on PORTB.5.
It's usually not important, but It could be problematic in some cases.

This code was generated to be fast and smaller, considering that there are not instructions to copy bits. A more secure code will use more instructions.

But if you have a good proposal, I can include it in the code generator. Or maybe you can modify the source. It's in the method TGenCod.ROB_bit_asig_bit() in the unit GenCod.pas.

I think It can be defined as an additional optimization parameter that in mode "fast" use this algorithm and in mode "slow" can use a more secure code.
« Last Edit: January 13, 2018, 05:24:15 am by Edson »
Lazarus 1.6 - FPC 3.0.0 - x86_64-win64 on  Windows 7

AnthonyTekatch

  • New member
  • *
  • Posts: 22
Re: PicPas, Pascal compiler for Microchip PIC
« Reply #136 on: January 13, 2018, 01:31:59 pm »

You are right. The code to copy bit PORTB.4 to PORTB.5:

    0x005 bcf PORTB, 5
    0x006 btfsc PORTB, 4
    0x007 bsf PORTB, 5

Could cause a fast pulse on PORTB.5.
It's usually not important, but It could be problematic in some cases.

...

I think It can be defined as an additional optimization parameter that in mode "fast" use this algorithm and in mode "slow" can use a more secure code.

If that code was in a loop, then there would be a constant "pulsing" which would result in a pulse width modulated output and lower average voltage.

Maybe something like this which only adds one instruction:
    0x001 btfsc PORTB, 4
    0x002 bsf PORTB, 5
    0x003 btfss PORTB, 4
    0x004 bcf PORTB, 5

I think this should be the normal operation. And, an optimization switch could be to enable your original method of speed while sacrificing output consistency.

Edson

  • Hero Member
  • *****
  • Posts: 831
Re: PicPas, Pascal compiler for Microchip PIC
« Reply #137 on: January 13, 2018, 06:12:52 pm »
If that code was in a loop, then there would be a constant "pulsing" which would result in a pulse width modulated output and lower average voltage.

Maybe something like this which only adds one instruction:
    0x001 btfsc PORTB, 4
    0x002 bsf PORTB, 5
    0x003 btfss PORTB, 4
    0x004 bcf PORTB, 5

I think this should be the normal operation. And, an optimization switch could be to enable your original method of speed while sacrificing output consistency.

Good code. I will check to include.

Just note that this is a problem only when using bit assigment in external PORT.
Lazarus 1.6 - FPC 3.0.0 - x86_64-win64 on  Windows 7

bigbo

  • New member
  • *
  • Posts: 8
Re: PicPas, Pascal compiler for Microchip PIC
« Reply #138 on: January 22, 2018, 07:22:34 pm »
Code: Pascal  [Select]
  1. var
  2.   a, b : byte;
  3. begin
  4.   a:=1;
  5.   b:= a div 0;
  6. end.

No error in this case.

Code: Pascal  [Select]
  1. var
  2.   a, b : byte;
  3. begin
  4.   a:=0;
  5.   b:= 1 div a;
  6. end.

No error in this case.

Code: Pascal  [Select]
  1. var
  2.   a, b : byte;
  3. begin
  4.   b:= 1 div 0;
  5. end.

The error is appears. I mean "Cannot divide by zero."
« Last Edit: January 22, 2018, 07:33:34 pm by bigbo »

Edson

  • Hero Member
  • *****
  • Posts: 831
Re: PicPas, Pascal compiler for Microchip PIC
« Reply #139 on: Today at 01:18:18 am »
The case:

Code: Pascal  [Select]
  1.     var
  2.       a, b : byte;
  3.     begin
  4.       a:=1;
  5.       b:= a div 0;
  6.     end.
  7.  

Must give error in compialtion time. I will fix.

But the case:

Code: Pascal  [Select]
  1.     var
  2.       a, b : byte;
  3.     begin
  4.       a:=0;
  5.       b:= 1 div a;
  6.     end.
  7.  

Is a Runtime error. The compiler doesn't generate Runtime checking routines. The memory of the PIC is too small, and there is not a secure way to inform this error.
Lazarus 1.6 - FPC 3.0.0 - x86_64-win64 on  Windows 7

Edson

  • Hero Member
  • *****
  • Posts: 831
Re: PicPas, Pascal compiler for Microchip PIC
« Reply #140 on: Today at 03:23:33 pm »
Fixed the case:

Code: Pascal  [Select]
  1.     var
  2.       a, b : byte;
  3.     begin
  4.       a:=1;
  5.       b:= a div 0;
  6.     end.

Now it generates error in compilation time.   :)
Lazarus 1.6 - FPC 3.0.0 - x86_64-win64 on  Windows 7

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus