Menu

Time_Based_Task_Switcher

Gigi
2024-12-30
2024-12-31
  • Gigi

    Gigi - 2024-12-30

    I'm trying this TASK and I have some doubts:
    Should the configuration file be placed in the same folder as the code?
    Is the number of Tasks limited? 3 Task 1 LTask
    This test code doesn't work if I pass N. Task

    '----------------- CONFIGURE MICRO -------------------
     '------------------------------------------------
    ' Funziona bene pero' non si possono fermare MAI
    ' -- Viene utilizzato il TIMER0 ( che quindi non si può utilizzare )
    
    #chip 16F88, 4
    #config XT_OSC, WDT_OFF, PWRT_ON
    #option explicit
    
    '*****  SETTAGGIO PORTE
    #define Led1     PORTA.0     ' Led1
    #define Led2     PORTA.1     ' Led2
    #define Led3     PORTA.2     ' Led3
    #define Puls     PORTA.3     ' read_input
    #define Buzz    PORTA.4     '
    #define AD4     PORTA.5     '
    '-------------------
    #define B0        PORTB.0    '
    #define ADR1      PORTB.1    '
    #define ADR2      PORTB.2    '
    #define B3        PORTB.3    '
    #define En        PORTB.4    ' LCD data LCD seriale
    #define Rs        PORTB.5    ' LCD clock
    #define Rxdb      PORTB.6    ' RX debug (PICKIT2 tx)
    #define Txdb      PORTB.7    ' TX debug (PICKIT2 rx)
    
    '==== SETTAGGI DELLE PORTE DEL PIC I/O ecc. ======================
    ' --------  bit a bit controllo 0=output  1=input
    dir PORTa b'00101000'    ' legge impostazioni INP/OUT
    dir PORTb b'01001000'    ' delle porte
    
    '---------------- TASK's DEFINITIONS -------------------
    #include "time_based_task_switcher_library001.h"
    #define base_time 1000          ' Base time or "tick" valore in uS
    ' ---------------
    ' -- Time base deve essere il valore del TASK1 quello + veloce
    ' -- Task1,2,3 ecc. quelli + veloci
    ' -- LONG LTask quelli lenti
    
    
    
    #define Task1      pulsante   ' chiamata SUB (Lettura pulsante)
    #define Task1_ms   1          ' Task attivo ogni 
    #define Run_Task1             ' esegue con interrupt subroutine
    
    #define Task2      NTC         ' chiamata SUB 
    #define Task2_us   500       ' Task attivo ogni us
    
    #define Task3      sub2       'we will have the time delay for the LED read from ReadAD function
    #define Task3_ms    10
    
    #define LTask1      sub1       ' nome SUB richiamata
    #define LTask1_s    3        ' esegue ogni 
    
    #define LTask2      sub3       ' nome SUB richiamata
    #define LTask2_s    1        ' esegue ogni 
    
    
    '--------------------- MAIN -----------------------
    '
    
    dim ONF_puls as bit
    
    do
    
    Do_Task1      ' avvia task
    do_Task2
    Do_Task3
    
    Do_LTask1
    
    Do_LTask2
    
    
    loop
    
    
    
        '------------------- TASK's SUBs ---------------------
        '------------------------------------------------
        Sub pulsante
            ONF_puls = puls    'set led3 period to the AD value
        End Sub
    
        Sub sub1
            led1 = ! led1 'toggle led on bit 0
        End Sub
    
        Sub sub2
            led2 = ! led2 'toggle led on bit 1
        End Sub
    
        sub NTC
    
        end sub
    
        sub sub3
    
        end sub
    
     
  • Gigi

    Gigi - 2024-12-30

    In the GCB example, TIMER0 is set but it refers to a different pic than mine. How should it be set in my case?
    InitTimer0 Osc, TimerInitValue + TMR0_HFINTOSC , POST0_1

     
  • Anobium

    Anobium - 2024-12-30

    I have not used the Task switcher.

    I know I supports 16 tasks.

    What configuration file?

     
  • Anobium

    Anobium - 2024-12-30

    What is you target chip?

     
  • Gigi

    Gigi - 2024-12-30

    Configuration files: #include "time_based_task_switcher_library001.h"

    I'm using 16F88

    It seems to only work with Task1...Task3 and LTask1
    The compiler gives an error on line 950 of "time_based_task_switcher_library001.h"
    950 flag_LTask2 off

     
  • Anobium

    Anobium - 2024-12-31

    I have taken the demos and adapted.

    Using the MEGA328p demo as my source ( I used this because the timer is the same config as the 16F88).
    I added the following to toggle the PORTB.6 every xx ms. This worked. I added the task, the time, and to run the defined task. 'Task4', 'Task4_ms' and 'Run_Task4'
    I then hooked up chip and circuit and it all worked... after I had change the .h file, see below.

        Dir PORTB.6 out
        #define Task4 blink4
        #define Task4_ms 1000            '  Run this Task every xx mS
        #define Run_Task4  
        Sub blink4
            PORTB.6 = !PORTB.6 'Toggle portb.6
        End Sub
    

    time_based_task_switcher_library002.h

    The first thing I did was add #option explicit. This made sure I knew all the variable types.

    So, I had to add the following block. Note: Dimensioning variable does not allocate RAM. This only tells the compile the type of variable. Only if a variable is used is the memory allocated.

    Dim time_Task1 as Word
    Dim time_Task2 as Word
    Dim time_Task3 as Word
    Dim time_Task4 as Word
    Dim time_Task5 as Word
    Dim time_Task6 as Word
    Dim time_Task7 as Word
    Dim time_Task8 as Word
    Dim time_Task9 as Word
    Dim time_Task10 as Word
    
    Dim cont_Task1 as Word
    Dim cont_Task2 as Word
    Dim cont_Task3 as Word
    Dim cont_Task4 as Word
    Dim cont_Task5 as Word
    Dim cont_Task6 as Word
    Dim cont_Task7 as Word
    Dim cont_Task8 as Word
    Dim cont_Task9 as Word
    Dim cont_Task10 as Word
    
    Dim flag_Task1 as Word
    Dim flag_Task2 as Word
    Dim flag_Task3 as Word
    Dim flag_Task4 as Word
    Dim flag_Task5 as Word
    Dim flag_Task6 as Word
    Dim flag_Task7 as Word
    Dim flag_Task8 as Word
    Dim flag_Task9 as Word
    Dim flag_Task10 as Word
    
    Dim flag_LTask1 as Word
    Dim flag_LTask2 as Word
    Dim flag_LTask3 as Word
    Dim flag_LTask4 as Word
    Dim flag_LTask5 as Word
    Dim flag_LTask6 as Word
    Dim flag_LTask7 as Word
    Dim flag_LTask8 as Word
    Dim flag_LTask9 as Word
    Dim flag_LTask10 as Word
    

    Then!!!

    Then I did a compare of 001.h and 002.h
    001 seems to be an early development. With 002 being the one to use.

    And, search the forum confirmed 002.h is the latest.


    Regarding the location of the source .h file. Same folder as your project as "" not <> is used.

    #include "time_based_task_switcher_library002.h"

    Ignore the comment - clearly the "" is correct.


    My files are attached.


    Evan

     
  • Gigi

    Gigi - 2024-12-31

    Thanks Evan,
    I just saw that it was giving errors and I stopped.
    In the next few days I will test if everything works correctly.

    Greetings and HAPPY NEW YEAR

     
  • Anobium

    Anobium - 2024-12-31

    HAPPY NEW YEAR!!

     

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.