Posible problem into GLCD _Library (GLCD_Line)???

General discussion on mikroBasic for dsPIC30/33 and PIC24.
Post Reply
Author
Message
Eduardo Picon
Posts: 46
Joined: 22 Jan 2007 20:18

Posible problem into GLCD _Library (GLCD_Line)???

#1 Post by Eduardo Picon » 07 Jul 2009 21:45

Mikro Team,

I am developing a project that does a graphic line on GLCD of ADC values in real-time.

Here, I attach an small test program that executes similar lines that my project program.

Code: Select all

' MCU: P30F6014A
' Xtal: 10 Mhz
' Setup: Standard project
' Development board: dsPICPRO4
'
program TestGraph

dim x1, x2  as byte
dim y1, y2  as word
dim ADCconv as word

' Program init
sub procedure Init_Main()
    ADPCFG = $FFFF
    Glcd_Init_dsPICPro3
    Glcd_Fill(0x00)
    delay_ms(200)

    ADPCFG  = $FBFF
    TRISB.10 = 1     ' RB10 as input pin
end sub

' Main procedure
main:
    Init_Main()

    X2 = 0
    Y1 = 32

    while true
       'Read AI
       ADCconv = Adc_Read(10)
       delay_us(10)
       'Line draw
       Y2 = ADCconv * 64 / 4096
       X1 = X2 - 1
       Glcd_Line(x2, 0, x2, 63, 0)
       Glcd_Line(x1, y1, x2, y2, 1)
       Y1 = Y2
       inc(X2)
       if X2 > 127 then
          X2 = 0
       end if
       delay_ms(10)
    wend
end.

The problem is:

- If is the value greater that 2048 it's draw correctly,
- if is the value smaller that 2048, only draw a line in the midle of GLCD,
- if is the value greater that 2048 and it increases, draw correctly, but if decreases, only a count, the program is blocked.

I don't know if is a library problem or some error in my program.

Please, I need someone can help me with this problem.

Thanks.

User avatar
slavisa.zlatanovic
mikroElektronika team
Posts: 1321
Joined: 07 Apr 2009 09:39

#2 Post by slavisa.zlatanovic » 08 Jul 2009 13:57

Hi!

Please, study this example code:

Code: Select all

' *
' * Project name:
'     ADCTest
' * Copyright:
'     (c) MikroElektronika, 2006.
' * Revision History:
'     20060515:
'       - Initial release
' * Description:
'     This program demonstrates how to use graphic LCD to show result of AD conversion.
' * Test configuration:
'     MCU:             dsPIC30F6014A
'     Dev.Board:       dsPICPRO4
'     Oscillator:      XT-PLL8, 10.000MHz
'     Ext. Modules:    None.
'     SW:              mikroBasic for dsPIC30/33 and PIC24 v4.0.0.0
' * NOTES:
'     - Turn the power off before placing GLCD on the board: (un-plug USB) put
'       and place GLCD in the socket. Then, turn the power on.
'     - For ADC, use on-board potentiometer P1 as input for channel 10.
' *
program ADCTest

dim txt1  as  string[23]
    txt2  as  string[5]
    adc_res  as  float
    measure  as  word

sub procedure Init
  ADPCFG = $FFFF      ' PORTB is digital

  '** dsPICPRO4
  Glcd_Init_dsPICPRO3
  
  Glcd_Fill(0x00)     ' clear screen
  Glcd_Set_Font(@FontSystem5x8, 5, 8, 32)
end sub

sub procedure DoMeasure
  ' We use PORTB for GLCD as well, so we have to set it to analogue input mode
  ADPCFG  = $FBFF
  measure = Adc_Read(10)
  adc_res = measure * 5.      ' note the constants are written as real
  adc_res = adc_res / 4096.   '   which avoids extra conversion from longint-float
end sub

sub procedure DoWriteResults
  if measure = 0 then   ' we do not need to call conversions if zero
    txt1 = "0.00000"
    txt2 = "    0"
  else
    FloatToStr(adc_res, txt1)
    WordToStr(measure, txt2)
  end if

  ADPCFG = $FFFF
  Glcd_Write_Text(txt1, 16, 1, 1) ' write on page 1 of GLCD
  Glcd_Write_Text(txt2, 10, 3, 1) ' write on page 3 of GLCD

  '** wait for the result to remain steady on screen
  Delay_ms(100)
end sub

'*******************************************************************************
'  sub procedure DoClearResults shows how to clear entire text row on GLCD. It is not
'    necessary to do it in this example, since the ADC will return range
'    0.00000 - 5.00000V. Therefore, the range for <adc_res> will never
'    shift the "." char to the right after the conversion to string.
'    In the case the result is larger than 9.99999 then  the "." will be
'    shifted one place to the right which will cause improper displaying of the results.
'  All the same, the sub procedure WordToStr right justifies the output and clearing
'    is not necessary too.
'********************************************************************************
sub procedure DoClearResults
dim i as  word
  '** clear entire page 1
  for i = 0 to 127
    Glcd_Set_Side(i)
    Glcd_Set_Page(1)
    Glcd_Set_X(i)
    Glcd_Write_Data(0) ' clear entire row
  next i
end sub

main:
  Init()

  while TRUE
    DoMeasure()
    DoWriteResults()
    DoClearResults()
  wend

end.
We're sure that it'll help you. All you have to do is modify the DoWriteResults() procedure to draw lines instead of writting numbers.

Note that GLCD uses some of PORTB pins so every time you want to write to GLCD you'll have to set ADPCFG = $FFFF and when you want to read from ADC you'll have to set ADPCFG = $FBFF. Your code is missing this!

Also, all parameters of the procedure Glcd_Line must be positive:

Code: Select all

sub procedure Glcd_Line(dim x_start, y_start, x_end, y_end as integer, dim color as word)


In your code X1 = X2 - 1 in first loop becomes -1. We suggest you to study the GLCD library help better.

Best regards
Slavisa

Eduardo Picon
Posts: 46
Joined: 22 Jan 2007 20:18

#3 Post by Eduardo Picon » 08 Jul 2009 14:48

Hi Slavisa,

I use your example code adapted to my situation, here is the modifyed code.

Code: Select all

dim txt1     as  string[23]
    txt2     as  string[5]
    adc_res  as  float
    measure  as  word
    x1, x2   as  integer
    y1, y2   as  integer
    yy2      as  float

sub procedure Init
  ADPCFG = $FFFF      ' PORTB is digital
  '** dsPICPRO4
  Glcd_Init_dsPICPRO3
  Glcd_Fill(0x00)     ' clear screen
  Glcd_Set_Font(@FontSystem5x8, 5, 8, 32)
end sub

sub procedure DoMeasure
  ' We use PORTB for GLCD as well, so we have to set it to analogue input mode
  ADPCFG  = $FBFF
  measure = Adc_Read(10)
  adc_res = measure * 5.      ' note the constants are written as real
  adc_res = adc_res / 4096.   '   which avoids extra conversion from longint-float
  yy2 = measure * 64.
  yy2 = yy2 / 4096.
  y2 =  integer(yy2)
  x1 = x2 - 1
end sub

sub procedure DoWriteResults
  if measure = 0 then   ' we do not need to call conversions if zero
    txt1 = "0.00000"
    txt2 = "    0"
  else
    FloatToStr(adc_res, txt1)
    WordToStr(measure, txt2)
  end if

  ADPCFG = $FFFF
  Glcd_Write_Text(txt1, 0, 0, 1) ' write on page 0 of GLCD
  Glcd_Write_Text(txt2, 0, 1, 1) ' write on page 1 of GLCD
  
  intToStr(integer(y2), txt1)
  Glcd_Write_Text(txt1, 45, 1, 1)' write on page 1 of GLCD
  ByteToStr(x1, txt2)
  Glcd_Write_Text(txt2, 95, 1, 1) ' write on page 1 of GLCD

  '** wait for the result to remain steady on screen
  Delay_ms(100)
end sub

sub procedure DoClearResults
dim i as  word
  '** clear entire page 1
  for i = 0 to 127
    Glcd_Set_Side(i)
    Glcd_Set_Page(1)
    Glcd_Set_X(i)
    Glcd_Write_Data(0) ' clear entire row
  next i
end sub
sub procedure DoGraph
  ADPCFG = $FFFF
  Glcd_Line(x2, 0, x2, 63, 0)
  Glcd_Line(x1, y1, x2, y2, 1)
  Y1 = Y2
  inc(X2)
  if X2 > 126 then
     X2 = 2
  end if
end sub
main:
  Init()

  X2 = 2
  Y1 = 32

  while TRUE
    DoMeasure()
    DoWriteResults()
'    DoClearResults()
    DoGraph
  wend

end.
Could you test it code and tell me, where is the problem now?.

Thanks.

Eduardo

Eduardo Picon
Posts: 46
Joined: 22 Jan 2007 20:18

#4 Post by Eduardo Picon » 08 Jul 2009 15:49

Hi Slavisa,

I was doing some tests with this program.

Code: Select all

sub procedure DoGraph
  ADPCFG = $FFFF
  Glcd_Line(x2, 0, x2, 63, 0)
  Glcd_dot(x2, y2, 1)
  Y1 = Y2
  inc(X2)
  if X2 > 126 then
     X2 = 2
  end if
end sub
Using GLCD_Dot, the program runs without problems. I don't know if GLCD_Dot function uses integer variables or not because the help of MBasic for dsPIC doesn't show that type of variables are used, but using this function runs well.

Is possible that exist a bug in the function GLCD_Line into the library to MBasic for dsPIC?.

I have used this function in MBasic 7.02 and runs perfectly, but in MBasic for dsPIC this problem exists. It want to use this function and not GLCD_Dot because the graphic is not the same.

Best regards.

Eduardo.

User avatar
slavisa.zlatanovic
mikroElektronika team
Posts: 1321
Joined: 07 Apr 2009 09:39

#5 Post by slavisa.zlatanovic » 09 Jul 2009 11:16

Hi!
Is possible that exist a bug in the function GLCD_Line into the library to MBasic for dsPIC?.
We're currently working on the complete revision of the mikroBasic for dsPIC30/33 and PIC24 compiler.
We'll check the GLCD_line procedure.
Thanks for your feedback.

BTW. We tried your code (with Glcd_dot()) and it's working great.

Best regards
Slavisa

Eduardo Picon
Posts: 46
Joined: 22 Jan 2007 20:18

Re: Posible problem into GLCD _Library (GLCD_Line)???

#6 Post by Eduardo Picon » 19 Mar 2010 20:06

Dear Slavisa,

I want to know what happened with the bug in GLCD_LINE funcion for MBasic dsPIC version.
Surely, you will tell me that convert my program to MBasic PRO dsPIC version...

After a lot of changes, I can convert it, but the new one doesn't run like the old version, and now I have new problems, not by the compiler, I know a little about the new version and I should use a lot of time learning, and at this moment I have't time to do it. I need to resolve this problem urgently.

I don't know what can you do to resolve this, in MBasic dsPIC version doesn't work well, only by the function GLCD_LINE bug, and the PRO dsPIC version it has a lot of problems and doesn't it do anything of it should do.

Surely, you don't give support to old versions, but I continue without finish my work.

I expect that you can give me an urgent answer.

Thanks.

Eduardo.

Eduardo Picon
Posts: 46
Joined: 22 Jan 2007 20:18

Re: Posible problem into GLCD _Library (GLCD_Line)???

#7 Post by Eduardo Picon » 19 Mar 2010 20:14

only by the function GLCD_LINE bug, and the PRO dsPIC version it has a lot of problems and doesn't it do anything of it should do.
Sorry, I wanted to write:

"only by the bug in GLCD_LINE function, and the program in PRO dsPIC version it has a lot of problems and doesn't it do anything of it should do."

Post Reply

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