cuff_mod_firmware.cydsn/interruptions.c
void function_scheduler(void) {
 
    static uint16 counter_calibration = DIV_INIT_VALUE;
    
    // Start ADC Conversion, SOC = 1

    timer_value0 = (uint32)MY_TIMER_ReadCounter();
    
    ADC_SOC_Write(0x01); 
    
    // Check Interrupt 

    if (interrupt_flag){
        interrupt_flag = FALSE;
        interrupt_manager();
    }
  
    //---------------------------------- Get Encoders

    encoder_reading(0, FALSE); 
    
    // Check Interrupt     
    
    if (interrupt_flag){
        interrupt_flag = FALSE;
        interrupt_manager();
    }   
    
    encoder_reading(1, FALSE);
    
    // Check Interrupt 
    
    if (interrupt_flag){
        interrupt_flag = FALSE;
        interrupt_manager();
    }
    
    /*encoder_reading(2, FALSE);
    
    // Check Interrupt 
    
    if (interrupt_flag){
        interrupt_flag = FALSE;
        interrupt_manager();
    }*/

    //---------------------------------- Control Motors
    
    motor_control(0);

    // Check Interrupt 

    if (interrupt_flag){
        interrupt_flag = FALSE;
        interrupt_manager();
    }
    
    motor_control(1);
    
    // Check Interrupt 
    
    if (interrupt_flag){
        interrupt_flag = FALSE;
        interrupt_manager();
    }

    //---------------------------------- Read conversion buffer - LOCK function

    analog_read_end();

    //---------------------------------- Calibration 

    // Divider 100, freq = 10 Hz
    /*if (!(calibration_flag == STOP)) {
        if (counter_calibration == CALIBRATION_DIV) {
            calibration();
            counter_calibration = 0;
        }
        counter_calibration++;
    }
    
    // Check Interrupt 
    
    if (interrupt_flag){
        interrupt_flag = FALSE;
        interrupt_manager();
    }*/
    
    if (pretensioning_flag == TRUE) {
       if (counter_calibration == CALIBRATION_DIV) {
           pretensioning_process();
           counter_calibration = 0;
       }
    counter_calibration++;
    } else {
        if(cuff_flag_force)
            drive_cuff();
            
        if (cuff_flag_proprio)
            slide_cuff();

        if (cuff_flag_force_proprio)
            force_and_slide_cuff();        
    }   
    
    if (interrupt_flag){
        interrupt_flag = FALSE;
        interrupt_manager();
    }
        
   
    //---------------------------------- Update States
    
    // Load k-1 state
    memcpy( &g_measOld, &g_meas, sizeof(g_meas) );
    memcpy( &g_refOld, &g_ref, sizeof(g_ref) );

    // Load k+1 state
    memcpy( &g_ref, &g_refNew, sizeof(g_ref) );

    if (interrupt_flag){
        interrupt_flag = FALSE;
        interrupt_manager();
    }

    //CyDelayUs(100);

    timer_value = (uint32)MY_TIMER_ReadCounter();
    MY_TIMER_WriteCounter(5000000);

}
//==============================================================================
//                                                            FUNCTION SCHEDULER
//==============================================================================
// Call all the function with the right frequency
//==============================================================================
// Base frequency 1000 Hz
//==============================================================================

FUNCTION SCHEDULER
Call all the function with the right frequency

Base frequency 1000 Hz
FUNCTION SCHEDULER Call all the function with the right frequency Base frequency 1000 Hz
void function_scheduler(void) {
    static uint16 counter_calibration = DIV_INIT_VALUE;
    timer_value0 = (uint32)MY_TIMER_ReadCounter();
    ADC_SOC_Write(0x01); 
    if (interrupt_flag){
        interrupt_flag = FALSE;
        interrupt_manager();
    }
    encoder_reading(0, FALSE); 
    if (interrupt_flag){
        interrupt_flag = FALSE;
        interrupt_manager();
    }   
    encoder_reading(1, FALSE);
    if (interrupt_flag){
        interrupt_flag = FALSE;
        interrupt_manager();
    }
    /*encoder_reading(2, FALSE);
    if (interrupt_flag){
        interrupt_flag = FALSE;
        interrupt_manager();
    }*/
    motor_control(0);
    if (interrupt_flag){
        interrupt_flag = FALSE;
        interrupt_manager();
    }
    motor_control(1);
    if (interrupt_flag){
        interrupt_flag = FALSE;
        interrupt_manager();
    }
    analog_read_end();
    /*if (!(calibration_flag == STOP)) {
        if (counter_calibration == CALIBRATION_DIV) {
            calibration();
            counter_calibration = 0;
        }
        counter_calibration++;
    }
    if (interrupt_flag){
        interrupt_flag = FALSE;
        interrupt_manager();
    }*/
    if (pretensioning_flag == TRUE) {
       if (counter_calibration == CALIBRATION_DIV) {
           pretensioning_process();
           counter_calibration = 0;
       }
    counter_calibration++;
    } else {
        if(cuff_flag_force)
            drive_cuff();
        if (cuff_flag_proprio)
            slide_cuff();
        if (cuff_flag_force_proprio)
            force_and_slide_cuff();        
    }   
    if (interrupt_flag){
        interrupt_flag = FALSE;
        interrupt_manager();
    }
    memcpy( &g_measOld, &g_meas, sizeof(g_meas) );
    memcpy( &g_refOld, &g_ref, sizeof(g_ref) );
    memcpy( &g_ref, &g_refNew, sizeof(g_ref) );
    if (interrupt_flag){
        interrupt_flag = FALSE;
        interrupt_manager();
    }
    timer_value = (uint32)MY_TIMER_ReadCounter();
    MY_TIMER_WriteCounter(5000000);
}
void function_scheduler ( void ) { static uint16 counter_calibration = DIV_INIT_VALUE ; timer_value0 = ( uint32 ) MY_TIMER_ReadCounter ( ) ; ADC_SOC_Write ( 0x01 ) ; if ( interrupt_flag ) { interrupt_flag = FALSE ; interrupt_manager ( ) ; } encoder_reading ( 0 , FALSE ) ; if ( interrupt_flag ) { interrupt_flag = FALSE ; interrupt_manager ( ) ; } encoder_reading ( 1 , FALSE ) ; if ( interrupt_flag ) { interrupt_flag = FALSE ; interrupt_manager ( ) ; } motor_control ( 0 ) ; if ( interrupt_flag ) { interrupt_flag = FALSE ; interrupt_manager ( ) ; } motor_control ( 1 ) ; if ( interrupt_flag ) { interrupt_flag = FALSE ; interrupt_manager ( ) ; } analog_read_end ( ) ; if ( pretensioning_flag == TRUE ) { if ( counter_calibration == CALIBRATION_DIV ) { pretensioning_process ( ) ; counter_calibration = 0 ; } counter_calibration ++ ; } else { if ( cuff_flag_force ) drive_cuff ( ) ; if ( cuff_flag_proprio ) slide_cuff ( ) ; if ( cuff_flag_force_proprio ) force_and_slide_cuff ( ) ; } if ( interrupt_flag ) { interrupt_flag = FALSE ; interrupt_manager ( ) ; } memcpy ( & g_measOld , & g_meas , sizeof ( g_meas ) ) ; memcpy ( & g_refOld , & g_ref , sizeof ( g_ref ) ) ; memcpy ( & g_ref , & g_refNew , sizeof ( g_ref ) ) ; if ( interrupt_flag ) { interrupt_flag = FALSE ; interrupt_manager ( ) ; } timer_value = ( uint32 ) MY_TIMER_ReadCounter ( ) ; MY_TIMER_WriteCounter ( 5000000 ) ; }
FUNCTION SCHEDULER
Call all the function with the right frequency
FUNCTION SCHEDULER Call all the function with the right frequency
// Start ADC Conversion, SOC = 1
 // Check Interrupt 
 //---------------------------------- Get Encoders
 // Check Interrupt     
 // Check Interrupt 
 /*encoder_reading(2, FALSE);
    
    // Check Interrupt 
    
    if (interrupt_flag){
        interrupt_flag = FALSE;
        interrupt_manager();
    }*/ //---------------------------------- Control Motors
 // Check Interrupt 
 // Check Interrupt 
 //---------------------------------- Read conversion buffer - LOCK function
 //---------------------------------- Calibration 
 // Divider 100, freq = 10 Hz
 /*if (!(calibration_flag == STOP)) {
        if (counter_calibration == CALIBRATION_DIV) {
            calibration();
            counter_calibration = 0;
        }
        counter_calibration++;
    }
    
    // Check Interrupt 
    
    if (interrupt_flag){
        interrupt_flag = FALSE;
        interrupt_manager();
    }*/ //---------------------------------- Update States
 // Load k-1 state
 // Load k+1 state
 //CyDelayUs(100);
