Menu

CODE OPTIMISATION

Help
JANIS
2018-12-27
2020-01-04
<< < 1 2 3 4 > >> (Page 3 of 4)
  • JANIS

    JANIS - 2019-02-13

    Shematics is attached

     
  • JANIS

    JANIS - 2019-02-13

    Pictures , please

     
  • Anobium

    Anobium - 2019-02-13

    Well done.

    A few questions now this is done.

    What is the best insight or learning from the project? (Do not saying the help from the forum!)
    What advice would you give to others?

     
  • JANIS

    JANIS - 2019-02-13

    I said at the beginning that I wanted to make a project using a graphical LCD. Here are a lot of hardships and nuances that need to be taken into account to dynamically operate pixels. I had little time, I work with project irregularly. I started the project long ago. Not just the program, but need work with the electronic side too. I think others will be able to learn from this project code. Here is the case of the inetresant. Pic16F18877 is full! If you'd like to use more feature, you should make code optimization :)

     
    • Anobium

      Anobium - 2019-02-13

      Full - you sure?
      Program Memory: 8118/32768 words (24.77%) RAM: 442/2048 bytes (21.58%) Chip: 16F18877

       
  • JANIS

    JANIS - 2019-02-13

    there is charging, arrows run :)

     
  • JANIS

    JANIS - 2019-02-13

    I hope my programmcode and idea will give benefit and help someone.

     
  • kent_twt4

    kent_twt4 - 2019-02-13

    Janis, nicely executed and well documented project. Something for all of us to strive for. Thanks for sharing.

     
  • JANIS

    JANIS - 2019-02-13

    when you add another graphical instruction to the code, the compiler no longer compiles. compilation error

     
    • Anobium

      Anobium - 2019-02-13

      Post an example and we can advise... but, I would think you have simply filled a page of memory and you need to split into two smaller subs.

       
    • kent_twt4

      kent_twt4 - 2019-02-13

      Suspiciously close to memory page boundary (8192).

       
  • JANIS

    JANIS - 2019-02-13

    Thank you Kent! Everyone should help each other and share ideas :). GCB is our little world

     
  • JANIS

    JANIS - 2019-02-13

    Anobium, the charger is in the box and it works. The project is over :) If there is no problem during the operation, I will not do anything. Until next project :)

     
  • JANIS

    JANIS - 2020-01-01

    Hello everyone in the new year!
    I want to extend this project with some minor changes, but it doesn't work. When compiling a program, the compiler gives a message! Ahhhhh

     
  • JANIS

    JANIS - 2020-01-01

    this problem was before.

    Anobium
    Full - you sure?
    Program Memory: 8118/32768 words (24.77%) RAM: 442/2048 bytes (21.58%) Chip: 16F18877

    ====================================
    i did a little optimization of the program and everything was fine. microcontroller is not full. but now i need to upgrade the program.

     
  • Anobium

    Anobium - 2020-01-01

    You need to look at the HTML related to the project - look for the method that is large than the 16f page size. Take that method and cut into two methods - this way the method (its a sub or a function) can then fit within the 16f page.

     
  • JANIS

    JANIS - 2020-01-01

    I didn't understand, here's the HTML page.!

     
  • Jim giordano

    Jim giordano - 2020-01-01

    He means the part after that, below where it says subroutines there should be a table of routine sizes. Unless it didn't make that part because it wouldn't compile. Then just look for your largest subroutine and break it into two pieces and cross your fingers.

     
  • Jim giordano

    Jim giordano - 2020-01-01

    looking at the code you posted on the previous page, it is your main, it was almost too big back then. Just break it in half, make the second half a sub, and call it from the first half.

     

    Last edit: Jim giordano 2020-01-01
  • JANIS

    JANIS - 2020-01-02

    Thank you Jim & Anobium ! I divided two stages into subroutines. now is possible compile my code! Maybe someone is interested in learning about changes to my battery charger. I had designed it so that when charged at a constant current, the voltage is gradually increased until it reaches a maximum of 15.6V. This voltage remains after that. This is not good because the battery then heats up and releases gas. Therefore, when the maximum voltage is reached, the charger switches to standby mode at 13.0V and maintains a constant storage voltage for the battery.

    Here's the code attached

     
  • stan cartwright

    stan cartwright - 2020-01-02

    edit forget this, I was reading page 1
    I have seen 2 line lcd displays that are very slow to update. The glcds I have used with gcb are fast for graphics and text.
    I would sort the code, eg earlier post

    if scale_volts_akku=115  then percents_akku=10:goto done
    if scale_volts_akku=116 or scale_volts_akku  =117 then percents_akku=20:goto done
    

    could be

    if scale_volts_akku=115  then percents_akku=10:goto done
    if scale_volts <=117  then percents_akku=20:goto done
    

    little things like this happenning often adds up wasted time.

     

    Last edit: stan cartwright 2020-01-02
  • Jim giordano

    Jim giordano - 2020-01-02

    Here's a little trick you might find useful sometime-

    at about line 190 you have

    pwm_ref_string=str(pwm_perc)
          ''INTOFF
    if pwm_perc=>100 then GLCDPrint (90, 25, pwm_ref_string + "%")'': goto next_1''   pwm_ref_string - nedrikst salidzinat ar skaitli, savadak raasies , ka 100 ( vai 10 , skaitlis) nav definets
    if pwm_perc=>10&pwm_perc<100 then GLCDPrint(90, 25, pwm_ref_string + "% ")
    if pwm_perc<10 then GLCDPrint(90, 25, pwm_ref_string + "%  ")
    

    which takes about 180 instructions looking at the .asm file

    This could be rewritten as

    pwm_ref_string=str(pwm_perc)+"%  "
    GLCDPrint (90, 25, left(pwm_ref_string,4) )
    

    which takes about 62 instructions, saveing a bit of memory if you are tight on space.

     
  • stan cartwright

    stan cartwright - 2020-01-02

    if pwm_perc=>10&pwm_perc<100 then GLCDPrint(90, 25, pwm_ref_string + "% ")

    if pwm_perc=>10 then if pwm_perc<100 then GLCDPrint(90, 25, pwm_ref_string + "% ")
    might be faster

     
  • Jim giordano

    Jim giordano - 2020-01-02

    Syntax Error: Mutliple IFs not permitted. .

    but, indeed

     #chip 16f18324,32
     #option explicit
      #startup InitPPS, 85
      Sub InitPPS
          RC5PPS     = 0x0018 'SCL1 > RC5
          SSP1CLKPPS = 0x0015 'RC5 > SCL1 (bi-directional)
          RC4PPS     = 0x0019 'SDA1 > RC4
          SSP1DATPPS = 0x0014 'RC4 > SDA1 (bi-directional)
      End Sub
    
      wait 100 ms  ' time to let lcd initialize
      #define HI2C_BAUD_RATE 400
      #define HI2C_DATA rc4
      #define HI2C_CLOCK rc5
      Dir HI2C_DATA in
      Dir HI2C_CLOCK in
      HI2CMode Master
      #define LCD_IO 10
      #define LCD_SPEED FAST
    
      dim ovf as word
      InitTimer1 osc,0
      On Interrupt Timer1Overflow Call fixt1
      sub fixt1
        tmr1h=0x80
        ovf++
      end sub
      timer1=0
      starttimer 1
      wait while tmr1l=0  ' wait for timer to start
    
    dim pwm_perc
    dim pwm_ref_string as string
    dim t1,t2,ov1,ov2 as word
    pwm_perc=50
    pwm_ref_string="test"
    
    ovf=0:timer1=0
    if pwm_perc=>10&pwm_perc<100 then Printx(90, 25, pwm_ref_string + "% ")
    t1=Timer1:ov1=ovf
    
    ovf=0:timer1=0
    if pwm_perc=>10 then
      if pwm_perc<100 then Printx(90, 25, pwm_ref_string + "% ")
    end if
    t2=Timer1:ov2=ovf
    
    cls:print ov1:print ":":print t1:locate 1,0:print ov2:print ":":print t2
    
    sub printx (xx,yyy,st as string)
    
    end sub
    

    is faster, first takes 160 ticks, second takes 132 ticks.
    and it's 10 instructions smaller!

    But we should stop cluttering up JANIS's thread :)

     

    Last edit: Jim giordano 2020-01-02
<< < 1 2 3 4 > >> (Page 3 of 4)

Log in to post a comment.