after all ... PBP is not so bad ...


Closed Thread
Results 1 to 24 of 24

Hybrid View

  1. #1
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Alain,

    That all is interesting but I have a question.

    Why did you modify someones post to post your test?

    I always hate it when a post has a major edit because there is not any notification of the edit. Doing a major edit to another s post is really out there.
    Dave
    Always wear safety glasses while programming.

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Default Just for you Dave ...

    As requested ...


    want proof ??? Ok ... let's go !

    1St attempt : Mikrobasic 7.2 ...


    Code:
    program Gouvernail                                                                                                        ' program PiloteAT50
    '************************************************* ****************************
     ' microcontroleur : 16F819 sur EasyPic 5
     '
    ' Projet : PPE 2010
     '
    ' En entree : A0 Up3 = entree analogique
     '
     ' En sortie : portB Affichage des consignes "Babord et Tribord" sur lcd
     '
     '************************************************* ****************************
     'program PiloteAT50
     symbol Up3 = PORTA.0 ' tension analogique (<5V)
    ' déclaration des variables
     dim result  as word
     
     dim tension as longint
     dim angle   as longint
     
     dim text    as string[9]
     dim valeur  as string[11]
     
     const Vref = 5000
     
     '******************************************************************************
     sub Procedure Init ' Initialisation
     
     'CMCON = 7
     
     trisb = %00000000 ' portB en sortie
     trisa = %11111111 ' portA en entrée
     
    Delay_ms(500)
    Lcd_Config(PORTB, 3, 2, 1, 0, PORTB, 4, 6, 5) ' Initialize LCD connected to PORTB
     'LCD_init(PORTB) ' initialisation Lcd sur PortB
     
     Lcd_Cmd(lcd_Clear)
     Lcd_Cmd(lcd_cursor_off)
     
     end sub
     
    '*******************************************************************************
     main: ' ********* Principal *********
    '*******************************************************************************
     Init ' config. et init. du PIC
     
     while true ' début de la boucle
     
         result = adc_read(0)
         tension = result *  Vref /1024  ' en mv !!!
     
         '**************************************************************************
         ' < ou > 4.02 v ???    ( 1024 * 4.02/5 = 823 !!! )
     
         if tension < 4020 then
     
            text = " Tribord "
         else
            Text = "  Babord "
     
         end if
     '*****************************************************************************
     ' Calcul de l'angle
     
            angle = 3133 * Fabs(tension - 4020) / 120000
     '*****************************************************************************
     ' Affichage
     
            LongintTostr(angle,valeur)
     
            Lcd_out(1, 1, text)
     
            Lcd_out(2,1,valeur)
     
             delay_ms(100)
     
     wend
    end.
    1:1 E-0 Linker error: NOT ENOUGH ROM

    NOTA: 2504 Words compiled for a 16F877A

    2nd Attempt : MikroBasic 7.2 ... NOT USING Fabs () ... = PbP ABS()

    Code:
    program Gouvernail                                                                                                        ' program PiloteAT50
    '************************************************* ****************************
     ' microcontroleur : 16F877A sur EasyPic 5
     '
    ' Projet : PPE 2010
     '
    ' En entree : A0 Up3 = entree analogique
     '
     ' En sortie : portB Affichage des consignes "Babord et Tribord" sur lcd
     '
     '************************************************* ****************************
     'program PiloteAT50
     symbol Up3 = PORTA.0 ' tension analogique (<5V)
    ' déclaration des variables
     dim result  as word
     
     dim tension as longint
     dim angle   as longint
     
     dim text    as string[9]
     dim valeur  as string[11]
     
     const Vref = 5000
     
     '******************************************************************************
     sub Procedure Init ' Initialisation
     
    ' CMCON = 7
     
     trisb = %00000000 ' portB en sortie
     trisa = %11111111 ' portA en entrée
     
    Delay_ms(500)
    Lcd_Config(PORTB, 3, 2, 1, 0, PORTB, 4, 6, 5) ' Initialize LCD connected to PORTB
     'LCD_init(PORTB) ' initialisation Lcd sur PortB
     
     Lcd_Cmd(lcd_Clear)
     Lcd_Cmd(lcd_cursor_off)
     
     end sub
     
    '*******************************************************************************
     main: ' ********* Principal *********
    '*******************************************************************************
     Init ' config. et init. du PIC
     
     while true ' début de la boucle
     
         result = adc_read(0)
         tension = result *  Vref /1024  ' en mv !!!
     
         '**************************************************************************
         ' < ou > 4.02 v ???    ( 1024 * 4.02/5 = 823 !!! )
     
         if tension < 4020 then
     
            text = " Tribord "
            angle = 3133 * (4020 - tension ) / 120000
         else
            Text = "  Babord "
            angle = 3133 * (tension - 4020) / 120000
     
         end if
     '*****************************************************************************
     ' Calcul de l'angle
     
    '        angle = 3133 * Fabs(tension - 4020) / 120000
     '*****************************************************************************
     ' Affichage
     
            LongintTostr(angle,valeur)
     
            Lcd_out(1, 1, text)
     
            Lcd_out(2,1,valeur)
     
             delay_ms(100)
     
     wend
    end.
    0:0 S-100 Success (Release build) - Timestamp: 10:15:57
    0:0 W-101 Used ROM: 1774 (86%) Used RAM: 80 (31%)
    0:0 W-102 Free ROM: 273 (14%) Free RAM: 176 (69%)

    a small bit better ...

    3rd attempt : MikroBasic PRO 3.2

    Code:
    program Gouvernail
    ' program PiloteAT50
    '************************************************* ****************************
     ' microcontroleur : 16F819 sur EasyPic 5
     '
    ' Projet : PPE 2010
     '
    ' En entree : A0 Up3 = entree analogique
     '
     ' En sortie : portB Affichage des consignes "Babord et Tribord" sur lcd
     '
     '************************************************* ****************************
     'program PiloteAT50
     
     ' Lcd module connections
     
    dim LCD_RS as sbit  at RB4_bit
        LCD_EN as sbit  at RB5_bit
        LCD_D4 as sbit  at RB0_bit
        LCD_D5 as sbit  at RB1_bit
        LCD_D6 as sbit  at RB2_bit
        LCD_D7 as sbit  at RB3_bit
        LCD_RS_Direction as sbit at TRISB4_bit
        LCD_EN_Direction as sbit at TRISB5_bit
        LCD_D4_Direction as sbit at TRISB0_bit
        LCD_D5_Direction as sbit at TRISB1_bit
        LCD_D6_Direction as sbit at TRISB2_bit
        LCD_D7_Direction as sbit at TRISB3_bit
    ' End Lcd module connections
     
    ' Symbol Up3 = PORTA.0 ' tension analogique (<5V)
    ' déclaration des variables
     dim resulta  as word
     
     dim tension as longint
     dim angle   as longint
     
     dim text    as string[9]
     dim valeur  as string[11]
     
     const Vref = 5000
     
    '*******************************************************************************
    main:
    '*******************************************************************************
    ' Init ' config. et init. du PIC
    ' CMCON = 7
     trisb = %00000000 ' portB en sortie
     trisa = %11111111 ' portA en entrée
    Delay_ms(500)
    'Lcd_Config(PORTB, 3, 2, 1, 0, PORTB, 4, 6, 5) ' Initialize LCD connected to PORTB
     LCD_init() ' initialisation Lcd sur PortB
     Lcd_Cmd(_LCD_CLEAR)
     Lcd_Cmd(_Lcd_Cursor_Off)
     
    while true    ' début de la boucle
           resulta = adc_read(0)
           tension = resulta *  Vref /1024  ' en mv !!!
           '************************************************************************
           ' < ou > 4.02 v ???    ( 1024 * 4.02/5 = 823 !!! )
           if tension < 4020 then
              text = " Tribord "
              '*********************************************************************
               ' Calcul de l'angle
               angle = 3133 * ( 4020 - tension ) / 120000
           else
              Text = "  Babord "
              angle = 3133 * (tension - 4020) / 120000
           end if
       '*****************************************************************************
       ' Affichage
              LongintTostr(angle,valeur)
              Lcd_out(1, 1, text)
              Lcd_out(2,1,valeur)
               delay_ms(100)
    wend
    end.
    0 133 Compiled Successfully C:\Program Files\Mikroelektronika\ProjetsBPro\Gouvernail\Gouv ernail.mbas
    0 1143 Used ROM (program words): 1722 (84%) Free ROM (program words): 326 (16%)
    0 1143 Used RAM (bytes): 44 (18%) Free RAM (bytes): 196 (82%)

    a tiny little bit better ...

    4Th attempt : Our favourite PicBasicPro v 2.60 / MPASM/ MCS ( left MkB lines commented besides PbP lines ...)

    Code:
    '****************************************************************
    '*  Name    : UNTITLED.BAS                                      *
    '*  Author  : [select VIEW...EDITOR OPTIONS]                    *
    '*  Notice  : Copyright (c) 2010 [select VIEW...EDITOR OPTIONS] *
    '*          : All Rights Reserved                               *
    '*  Date    : 30/04/2010                                        *
    '*  Version : 1.0                                               *
    '*  Notes   :                                                   *
    '*          :                                                   *
    '****************************************************************
    'program Gouvernail                                                                                                        ' program PiloteAT50
    '*************************************************   ****************************
     ' microcontroleur : 16F819 sur EasyPic 5
     '
    ' Projet : PPE 2010
     '
    ' En entree : A0 Up3 = entree analogique
     '
     ' En sortie : portB Affichage des consignes "Babord et Tribord" sur lcd
     '
     '*************************************************   ****************************
     'program PiloteAT50
     
    @ ERRORLEVEL -306
    @ __config _HS_OSC & _WDT_ON & _PWRTE_ON & _BODEN_ON & _LVP_OFF & _CP_OFF
     
     entree var PORTA.0 ' tension analogique (<5V)
    ' déclaration des variables
    ' dim result  as word
     
    ' dim tension as longint
    ' dim angle   as longint
     
    ' dim text    as string[9]
    ' dim valeur  as string[10]
     
    ' const Vref = 5000
    result var word
    tension var word
    angle var word
    dummy var word
    vref con 5000
     
     '*************************************************  *****************************
     'sub Procedure Init ' Initialisation
     
     
    DEFINE  OSC 8
     
    CLEAR
    ;----[LCD definitions]------------------------------------------------------
    DEFINE LCD_DREG  PORTB          ' LCD Data port
    DEFINE LCD_DBIT  0              ' starting Data bit (0 or 4)
    DEFINE LCD_EREG  PORTB          ' LCD Enable port
    DEFINE LCD_EBIT  5              ' Enable bit  (on EasyPIC 5 LCD)
    DEFINE LCD_RSREG PORTB          ' LCD Register Select port
    DEFINE LCD_RSBIT 4              ' Register Select bit   (on EasyPIC 5 LCD)
    DEFINE LCD_BITS  4              ' LCD bus size (4 or 8 bits)
    DEFINE LCD_LINES 2              ' number of lines on LCD
    DEFINE LCD_COMMANDUS 2000       ' Command delay time in us 
    DEFINE LCD_DATAUS 50            ' Data delay time in us 
    ;----[LCD definitions]------------------------------------------------------
    DEFINE ADC_BITS 10 ' set number of bits in result
    DEFINE ADC_CLOCK 3 ' set clock source
    ADCON1 = %10000000  ' right formatted
     
    ' CMCON = 7
     
     trisb = %00000000 ' portB en sortie
     trisa = %11111111 ' portA en entrée
     
    'Delay_ms(500)
    PAUSE 500
    'Lcd_Config(PORTB, 3, 2, 1, 0, PORTB, 4, 6, 5) ' Initialize LCD connected to PORTB
     'LCD_init(PORTB) ' initialisation Lcd sur PortB
     
    ' Lcd_Cmd(lcd_Clear)
    ' Lcd_Cmd(lcd_cursor_off)
    LCDOUT $FE,1
     
    ' end sub
     
    '*************************************************  ******************************
     main: ' ********* Principal *********
    '*************************************************  ******************************
    ' Init ' config. et init. du PIC
     
     'while true ' début de la boucle
     while 1=1
     
    '     result = adc_read(0)
        adcin 0, result
         dummy = result * Vref 
         tension = DIV32 1024  ' en mv !!!
     
         '*************************************************  *************************
         ' < ou > 4.02 v ???    ( 1024 * 4.02/5 = 823 !!! )
     
         if tension < 4020 then
     
            LCDOUT $FE,2, " Tribord "
         else
            LCDOUT $FE,2, "  Babord "
         endif
     '*************************************************  ****************************
     ' Calcul de l'angle
     
    '        angle = 3133 * abs(tension - 4020) / 120 / 1000
            dummy = 3133 * abs(tension - 4020)
            angle = DIV32 12000
            angle = angle /10
     '*************************************************  ****************************
     ' Affichage
     
    '        LongintTostr(angle,valeur)
     
    '        Lcd_out(1, 1, text)
     
    '        Lcd_out(2,1,valeur)
            LCDOUT $FE, $C0, dec3 angle
     
    '         delay_ms(100)
              PAUSE 100
     
     wend
    end
    Success ; 461 Words ...


    Really astonishing for such a simple work !!!, don't you think ???

    Alain

    PS; as we are under the 2K limit EVERYONE can verify it with the Demo available versions of MikroBasic and MikroBasic Pro ...
    Last edited by Acetronics2; - 1st May 2010 at 12:17. Reason: ask Dave !!!
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  3. #3
    Join Date
    Sep 2007
    Location
    USA, CA
    Posts
    271


    Did you find this post helpful? Yes | No

    Default

    That is quite good. PDS only gets it down to 457, with 25 variables used.
    (PBP uses 32 variable bytes.) Where PDS really shines, however, is when the file gets very large, when you use interrupts (it's built in; Darrel's utility is not needed), and with great implementation of mixing words and longs.

  4. #4
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default

    Might be interesting if you would post your findings over at the mikroE forums.

  5. #5
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by rmteo View Post
    Might be interesting if you would post your findings over at the mikroE forums.
    I do think it would be a very bad idea ...

    totally unfair, overall ...

    much too wide a gap !!! , don't you think ???

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  6. #6
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default

    It could be an incentive for them to improve their products to be as good as PBP.

  7. #7
    Join Date
    Aug 2005
    Location
    Michigan, USA
    Posts
    224


    Did you find this post helpful? Yes | No

    Default

    Hi Alain,

    Thank you for posting the examples. May I impose to ask about the analog signal you're measuring and how it relates to degrees port and starboard? It seems you're sensing the port and starboard switch over at 4.020 volts (adc value 823). I'm just wondering if you couldn't use a different formula to produce the same results and eliminate the step of converting adc values of 0..1023 to voltage 0..4995-mvolts).

    Kind regards, Mike

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts