Question about MikroBasic for dsPIC 1.0

General discussion on mikroBasic for dsPIC30/33 and PIC24.
Post Reply
Author
Message
perseus
Posts: 5
Joined: 31 Oct 2005 11:07

Question about MikroBasic for dsPIC 1.0

#1 Post by perseus » 02 Nov 2005 10:16

I'm very interested to buy this powerful compiler, but I have some questions. I'm working with the free evaluation copy of the program and
I've some problem to compile a program with the dsPIC30F4011, while the dsPIC30F4013 works well. So I look inside the program directory and I found that the p30F4011def.dbas (in the DEFS directory) is completely different from the p30F4013def.dbas and other definition files: why?
If I buy the program, I will have the new unlocked and correct program or I buy only the licence?
Another question: in the Project setup, the clock value is the crystal frequency, or the real frequency after the PLL (computed by...me?) I note that the execution time (computed by the simulator) is determined thru the "clock" frequency and not the "clock x PLL" . But the compiler knows very well the PLL multiplication factor...(specified in the project properties).
Someone can answer to me?
Thanks
Ivano

User avatar
zristic
mikroElektronika team
Posts: 6608
Joined: 03 Aug 2004 12:59
Contact:

Re: Question about MikroBasic for dsPIC 1.0

#2 Post by zristic » 02 Nov 2005 12:43

perseus wrote:I've some problem to compile a program with the dsPIC30F4011, while the dsPIC30F4013 works well. So I look inside the program directory and I found that the p30F4011def.dbas (in the DEFS directory) is completely different from the p30F4013def.dbas and other definition files: why?
These are two completely different chips. What is the error message you get?
If I buy the program, I will have the new unlocked and correct program or I buy only the licence?
You will get a key which will unlock the program you have already downloaded. Later upgrades are free.
Another question: in the Project setup, the clock value is the crystal frequency, or the real frequency after the PLL (computed by...me?) I note that the execution time (computed by the simulator) is determined thru the "clock" frequency and not the "clock x PLL" . But the compiler knows very well the PLL multiplication factor...(specified in the project properties).
You have to specify working frequncy of the chip (not divided by four). If for example, you use 10MHz crystal with p30F4013 and you enable EC_8xPLL option, then you have to setup 80MHz in compiler.

For your information, the next release of mikroPascal and mikroBasic for dsPIC is just about to be released. We added DSP support so now you can use FFT, IFFT, FIR, IIR etc. Here is the example how FFT works in realtime on 4013:

Image

The example compiles below 6Kbytes which means you can try it out without buying a licence.

perseus
Posts: 5
Joined: 31 Oct 2005 11:07

#3 Post by perseus » 02 Nov 2005 13:42

This simple program is compiled with dsPIC30F4013 but not with dsPIC30F4011 (it generates a lot of errors,
in the p30F4011def.dbas). It can be that in my evaluation copy of the program there are some errors, 'cause the def sections are structurally too much different...look inside in the DEFS directory in the evaluation copy.
If I want to install the program in my desktop computer and in my notebook (of course I use them one at a time and not simultaneously) I have to buy two keys?
The answer is important for the right choose of the compiler...
Thanks a lot for the quick answers

Ivano

perseus
Posts: 5
Joined: 31 Oct 2005 11:07

#4 Post by perseus » 02 Nov 2005 13:44

I' ve forgotten the "simple program"...
Here it is.
Bye

1 program try
2 dim var as integer
3 main:
4 var=10
5 end.

User avatar
zristic
mikroElektronika team
Posts: 6608
Joined: 03 Aug 2004 12:59
Contact:

#5 Post by zristic » 02 Nov 2005 14:23

The def file for 4011 should look like this:

Code: Select all

module p30F4011def

include "p30F4011"
include "system"
include "math"
include "math_double"
include "strings"
include "trigonometry"
include "delays"
include "uart_calc"
include "eeprom"
include "flash_mcu"
include "conv"
include "keypad4x4"
include "adc"
include "i2c"
include "spi_const"
include "spi1"
include "spi2"
include "mmc"
include "uart_consts"
include "uart1"
include "uart2"
include "soft_i2c"
include "soft_spi"
include "soft_uart"
include "lcd_consts"
include "lcd_4bit"
include "lcd_8bit"     ' add here new libraries
include "images"
include "glcd30"
include "compact_flash"
include "ps2"
include "button"
include "pwm_calc"
include "pwm"
'include "mmc_fat16"
include "sound"


implements

end.

perseus
Posts: 5
Joined: 31 Oct 2005 11:07

#6 Post by perseus » 02 Nov 2005 14:57

Okay, the file in my free demo is corrupted. I try to download it again but...you can try to check it, also.
Important: if I want to install the program in my desktop computer and in my notebook (of course I use them one at a time and not simultaneously) I have to buy two keys?
Bye
Ivano

anton
Posts: 807
Joined: 23 Sep 2004 09:16
Location: South-Africa
Contact:

#7 Post by anton » 02 Nov 2005 22:12

Okay, the file in my free demo is corrupted. I try to download it again but...you can try to check it, also.
Important: if I want to install the program in my desktop computer and in my notebook (of course I use them one at a time and not simultaneously) I have to buy two keys?
:cry: yes, you have to

Anton
Another proud user of LV 24-33A Development System and mikroPascal PRO for dsPIC :)
PortA not working? Add CMCON := 7; PortD not working? Add ADCON1 := 6;
To paste code on the forum, please use the [b] Code [/b] button !! ;)

OT
Posts: 581
Joined: 19 May 2005 05:08
Location: Fairbanks, Alaska

Re: Question about MikroBasic for dsPIC 1.0

#8 Post by OT » 03 Nov 2005 04:08

zristic wrote:
For your information, the next release of mikroPascal and mikroBasic for dsPIC is just about to be released. We added DSP support so now you can use FFT, IFFT, FIR, IIR etc. Here is the example how FFT works in realtime on 4013:

Image

The example compiles below 6Kbytes which means you can try it out without buying a licence.
Now it is starting to look like some real fun... :mrgreen: :mrgreen: :mrgreen:
What throughput frequency/sample size can you make it at?
Last edited by OT on 03 Nov 2005 05:35, edited 1 time in total.

OT
Posts: 581
Joined: 19 May 2005 05:08
Location: Fairbanks, Alaska

#9 Post by OT » 03 Nov 2005 05:34

However one solution that has been mentioned is to install the compiler on a portable laptop drive or a USB flash device (latter is slow). The licence is keyed to the media, thus it will travel with the portable drive.
I can confirm I have tested this now with a full licence of dsPIC Pascal, and it works. I even have additional fre licences installed on the C drives, which can be used with demo limit in case the laptop drive is left behind.
Last edited by OT on 23 Nov 2005 08:46, edited 1 time in total.

User avatar
zristic
mikroElektronika team
Posts: 6608
Joined: 03 Aug 2004 12:59
Contact:

Re: Question about MikroBasic for dsPIC 1.0

#10 Post by zristic » 03 Nov 2005 09:20

OT wrote:Now it is starting to look like some real fun...
What throughput frequency/sample size can you make it at?
Here is the source code in mikroPascal:

Code: Select all

program FFTDemo;

uses FFTLib, BitReverseComplex, TwiddleFactors;

var Samples : array[512] of word; absolute $1800;  // Y data space
    Written : array[128] of word;
    freq    : word;
    txt     : string[5];


procedure InitAdc;
begin
  ADPCFG := 0;
  ADCON1 := $00E0;  // internal counter ends conversion
  ADCHS  := 10;     // connect RBxx/ANxx as CH10 input
  ADCSSL := 0;
  ADCON3 := $1F3F;  // sample time = 31 Tad.
  ADCON2 := 0;
  ADCON1 := $83E0;  // turn ADC ON, fractional result

  TRISB.10 := 1;
end;

procedure Init;
var i: word;
begin
  for i := 0 to 127 do
    begin
      Written[i] := 255;
    end;

  Glcd_Init(LATD.8, LATD.9, LATD.10, LATD.3, LATG.12, LATD.11, LATB);
  Glcd_Set_Font(@FontSystem5x8, 5, 8, 32);
  Glcd_Fill(0xAA);

  Delay_ms(500);
  Glcd_Fill(0x00); // clear screen

  InitAdc;
  txt := ' Hz';
  Glcd_Write_Text(txt, 100, 0, 1);
end;

function Fract2Float(input: integer): real;
begin
   if (input < 0) then
     input := - input;
   result := input/32768.;
end;

procedure WriteData;
var Re, Im, tmpw,
    j, k, l, max      : word;
    Rer, Imr, tmpR    : real;
begin
  ADPCFG := $FFFF; // PORTB is digital
  j := 2;
  k := 0;
  max := 0;
  freq := 0;
  while k <= 62 do
    begin
      re := Samples[j];
      inc(j);

      im := Samples[j];
      inc(j);

      Rer := Fract2Float(re);
      Imr := Fract2Float(im);

      tmpR := Rer * Rer;
      Rer  := tmpR;
      tmpR := Imr * Imr;
      Imr  := tmpR;
      tmpR := sqrt(Rer + Imr);

      Rer := tmpR*512.;

      re := Rer;
      re := re and $FF;

      if Re > 63 then
        re := Written[k-1]; // k = 0?
        
      if Re > max then
        begin
          max := re;
          freq := k;
        end;

      tmpw := Written[k];
      if tmpw <> Re then
        begin
          l := 64 - tmpw;
          while l <= 63 do
           begin
             Glcd_Dot(k, l, 0);
             inc(l);
            end;

           l := 64 - Re;
           while l <= 63 do
             begin
               Glcd_Dot(k, l, 1);
               inc(l);
              end;
           Written[k] := Re;
        end;
      inc(k);
     end;
end;

function readadc: word;
begin
  ADCON1.1 := 1; // start conversion
  while ADCON1.0 = 0 do nop;
  result := ADCBUF0;
end;

procedure SampleInput;
var i: integer;
begin
  // We use PORTB for GLCD as well, so we have to set it to analogue input mode
  ADPCFG  := $0000;
  TRISB.10 := 1;

  i :=0;
  while i <= 511 do
    begin
       Samples[i] := readadc;
       inc(i);
       Samples[i] := 0;
       inc(i);
    end;
end;

begin
  Init;
  while true do
    begin
      freq := 0;
      SampleInput;

      FFT(8, @TwiddleCoeff_256, Samples);
      BitReverseComplex(8, Samples);

      WriteData;
      freq := freq * 100;
      WordToStr(freq, txt);
      Glcd_Write_Text(txt, 70, 0, 1);
  end;
end.
There is an equivalent to it in mikroBasic that does the same. The code is slighly modified in order to show the frequency of max peak.

The maximum frequency measured here is 6kHz, but this is not the limit, because the slowest sampling for ADC is used (Tack = 31Tad). Therefore, it should be possible to sample signals up to 20kHz.
The signal is sampled at 256 points and FFT returns 128 real/complex pairs. The pairs are used to calc amplitude as sqrt(Re^2 + Im^2).

The whole program fits in less than 6Kbytes of flash and runs in realtime without problems (P30f6014 has 144kbytes of flash!).

xor
Posts: 5465
Joined: 18 May 2005 00:59
Location: NYC
Contact:

Re: Question about MikroBasic for dsPIC 1.0

#11 Post by xor » 14 Nov 2005 03:12

zristic wrote:The example compiles below 6Kbytes which means you can try it out without buying a licence.
Is the demo-limit 6K with dsBasic?
[color=darkred][b]xor[/b][/color]
[url=http://circuit-ed.com]CircuitED -[/url]

User avatar
zristic
mikroElektronika team
Posts: 6608
Joined: 03 Aug 2004 12:59
Contact:

Re: Question about MikroBasic for dsPIC 1.0

#12 Post by zristic » 14 Nov 2005 09:16

xor wrote:Is the demo-limit 6K with dsBasic?
Yes, it is.

xor
Posts: 5465
Joined: 18 May 2005 00:59
Location: NYC
Contact:

#13 Post by xor » 17 Nov 2005 04:44

  • Another really technical question Zoran.....those nice little single pin jumpers in the picture.....how did you guys come by those? Are they breakaway inverted SIP's?
[color=darkred][b]xor[/b][/color]
[url=http://circuit-ed.com]CircuitED -[/url]

User avatar
zristic
mikroElektronika team
Posts: 6608
Joined: 03 Aug 2004 12:59
Contact:

#14 Post by zristic » 17 Nov 2005 09:51

xor wrote:
  • Another really technical question Zoran.....those nice little single pin jumpers in the picture.....how did you guys come by those? Are they breakaway inverted SIP's?
Yes, simply I just cut them with small pliers and soldered a wire.

Post Reply

Return to “mikroBasic for dsPIC30/33 and PIC24 General”