Menu

Single variable in subroutine

Boguslaw
2024-01-17
2024-01-18
  • Boguslaw

    Boguslaw - 2024-01-17

    Hi
    I want to use SUBroutine with single values, but compiler reports error, why ?

    Error: GCASM: Symbol [SFR]SYSMULTSUBSINGLE has not been defined. Inspect ASM file to determine error at CALL SYSMULTSUBSINGLE Hexfile address(see lst file): 000148

     
  • Anobium

    Anobium - 2024-01-17

    Hello,
    Post your program so I see the error. Please attach to your post.

     
  • Boguslaw

    Boguslaw - 2024-01-18

    Variables Kp ,Ku,Ki ,Kd ,Setpoint ,Integral , Previouserror,Pot1 are global

    sub Autotune
    dim petla as word
      '  Setpoint = 800                                          
      '  Integral = 0
      '  Previouserror = 0
      '  Ku = 0
      '  Tu = 0
        For petla = 1 To 100 Step 1
            Output1 = 0
           PWM1_Duty = Output1
            Pot1 = ReadAD10(AN0)                                    
    
            Wait 100 us
            Tu = Tu + 1
              Setpoint_tmp = Setpoint + 10
            If Pot1 > Setpoint_tmp Then Exit For
        Next
    kp = petla
        Kp = 0.6 * Ku
        Ki = 2 * Kp / Tu
        Kd = Kp * Tu / 8
    End Sub
    
     

    Last edit: Boguslaw 2024-01-18
  • Anobium

    Anobium - 2024-01-18

    This not the complete program, so, I cannot try to compile.

    But, Kp = 0.6 * Ku is probably the issue. You need to factorise to use integer calculations.

     
  • Boguslaw

    Boguslaw - 2024-01-18

    Attached code. I have one problem yet, PWM don't work can you see why ?
    I noticed that the problem is not in SUB, when I remove SUB the error is still there.
    , problem is caused by this line: Output1 = Kp * Error + Ki * Integral + Kd * Derivative
    I changed all variables to single and without effect.
    How to perform mathematical operations with single variables?

     

    Last edit: Boguslaw 2024-01-18
  • Anobium

    Anobium - 2024-01-18

    I would look at the demos for Q71.

    C:\GCstudio\gcbasic\demos\Vendor_Boards\Great_Cow_Basic_Demo_Board\18f26q71_chiprange_demonstrations

    There are many PWM demos. Work out which one you need to use - i would recommend PWM/CPP as this is the easy one. There more demos on 16bit demos in the demo folders.


    Regarding singles ( we called the Floats) , see https://sourceforge.net/p/gcbasic/discussion/596084/thread/b867317011/
    Use factorised integers. They work a lot lot faster and they work.

     
  • Boguslaw

    Boguslaw - 2024-01-18

    if I use specific numbers, I understand, but when I multiply two single variables,
    single1=single2*single3 s(ingles 2 and 3 calculated in another part of the program)
    I don't know how to solve it.

     
    • Anobium

      Anobium - 2024-01-18

      Read the https://sourceforge.net/p/gcbasic/discussion/596084/thread/b867317011/ post?

      Remove the SINGLES from you program and use factorised integers.

      Then, the maths will work.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.