* * *

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

Edson

  • Hero Member
  • *****
  • Posts: 840
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: 840
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: 840
Re: PicPas, Pascal compiler for Microchip PIC
« Reply #139 on: January 23, 2018, 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: 840
Re: PicPas, Pascal compiler for Microchip PIC
« Reply #140 on: January 23, 2018, 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

CaptBill

  • Sr. Member
  • ****
  • Posts: 435
Re: PicPas, Pascal compiler for Microchip PIC
« Reply #141 on: February 14, 2018, 04:36:19 am »
PicPas has been updated to the version 0.6.0  :D. All bit operation implemented, more optimization code included, tree syntax improved, parameters of procedures implemented, interfaz modified,  and many other features more.

Very nice!! You've been busy!

What is the graphical emulator you are using in the background? Is that a third party tool?

The debugger is fantastic. What more could you want?

Bravo!

CaptBill

  • Sr. Member
  • ****
  • Posts: 435
Re: PicPas, Pascal compiler for Microchip PIC
« Reply #142 on: February 14, 2018, 04:51:44 am »
I know it's not a good question, but I often wonder why people use PIC controllers. What keeps you using them?

They aren't really cheap, and the architecture is not suited for compilers or humans.
Some say they are great for noisy environments, but anything running that slow will work in a noisy environment.

Creating a compiler for it is a great feat for sure. So kudos for the project  :)

Probably because, in reality, these chips comprise something like 90% of real world application in actual products. It is your basic, no frills workhorse of a microcontroller. The fact that it is a well established RISC design makes it very easy to fully understand by one person. It's staying power is it's great simplicity.

CaptBill

  • Sr. Member
  • ****
  • Posts: 435
Re: PicPas, Pascal compiler for Microchip PIC
« Reply #143 on: February 14, 2018, 07:04:59 am »
Hi Edson,
Here is a translation to English of the excellent UART example. Hope it helps.

« Last Edit: February 14, 2018, 07:44:15 am by CaptBill »

Edson

  • Hero Member
  • *****
  • Posts: 840
Re: PicPas, Pascal compiler for Microchip PIC
« Reply #144 on: February 14, 2018, 05:01:42 pm »
What is the graphical emulator you are using in the background? Is that a third party tool?

The debugger is fantastic. What more could you want?

Bravo!
Thanks.

* The emulator is just a front-end to my library: https://github.com/t-edson/PicUtils
* The graphical interfaz is implemented using my library: https://github.com/t-edson/ogEditGraf

All third party libraries used in PicPas are mines, by now.  :-X

PicUtils is a library that define a complete class modeling a PIC device, and some routines to facilitate the compiling, emulation and memory management of the MidRange PIC devices. In fact when compiling using PicUtils, it compiles directly to the FLASH memory of the  model, so emulate the execution is so simple as execute the method pic.Exec().

ogEditGraf is a library that implement a graphical Editor with objects, and the common operations like move, select, delete, highlight, zoom, ... It's more complex that it appears here. The graphical interfaz of the PicPas emulator is still very simple.
Lazarus 1.6 - FPC 3.0.0 - x86_64-win64 on  Windows 7

Edson

  • Hero Member
  • *****
  • Posts: 840
Re: PicPas, Pascal compiler for Microchip PIC
« Reply #145 on: February 14, 2018, 09:52:33 pm »
Hi Edson,
Here is a translation to English of the excellent UART example. Hope it helps.

Updated in the GitHub.

Thanks
Lazarus 1.6 - FPC 3.0.0 - x86_64-win64 on  Windows 7

CaptBill

  • Sr. Member
  • ****
  • Posts: 435
Re: PicPas, Pascal compiler for Microchip PIC
« Reply #146 on: February 15, 2018, 08:37:27 pm »
Hi Edson,

Do you plan on implementing the set type or are sets to high level for the PIC?
« Last Edit: February 15, 2018, 09:03:14 pm by CaptBill »

Edson

  • Hero Member
  • *****
  • Posts: 840
Re: PicPas, Pascal compiler for Microchip PIC
« Reply #147 on: February 16, 2018, 04:31:48 am »
Hi Edson,

Do you plan on implementing the set type or are sets to high level for the PIC?

Yes it's in my plans. Probably it will take some time. First I have to finish implementing arrays and pointers.
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