예제 #1
0
int16_t main(void) {
    int led2_on;
    int led3_on;

    led2_on = 0;
    led3_on = 1;
    init_clock();
    init_ui();
    init_timer();

    led_on(&led1);
    timer_setPeriod(&timer2, 0.1);
    timer_start(&timer2);

    while (1) {
        if (timer_flag(&timer2)) {
            timer_lower(&timer2);
            led_toggle(&led1);
        }

        if(!sw_read(&sw2)){
            timer_setPeriod(&timer2, 0.5);
            timer_start(&timer2);
            led2_on = 1;
            led3_on = 0;
        } else if(!sw_read(&sw3)){
            timer_setPeriod(&timer2, 0.1);
            timer_start(&timer2);
            led2_on = 0;
            led3_on = 1;
        }
        led_write(&led2, led2_on);
        led_write(&led3, led3_on);
    }
}
예제 #2
0
void VendorRequests(void) {
    WORD32 address;
    WORD result;

    switch (USB_setup.bRequest) {
        case TOGGLE_LED1:
            led_toggle(&led1);
            BD[EP0IN].bytecount = 0;         // set EP0 IN byte count to 0
            BD[EP0IN].status = 0xC8;         // send packet as DATA1, set UOWN bit
            break;
        case TOGGLE_LED2:
            led_toggle(&led2);
            BD[EP0IN].bytecount = 0;         // set EP0 IN byte count to 0
            BD[EP0IN].status = 0xC8;         // send packet as DATA1, set UOWN bit
            break;
        case READ_SW1:
            BD[EP0IN].address[0] = (uint8_t)sw_read(&sw1);
            BD[EP0IN].bytecount = 1;         // set EP0 IN byte count to 1
            BD[EP0IN].status = 0xC8;         // send packet as DATA1, set UOWN bit
            break;
            
        // case ENC_WRITE_REG:
        //     enc_writeReg(USB_setup.wValue, USB_setup.wIndex);
        //     BD[EP0IN].bytecount = 0;         // set EP0 IN byte count to 0
        //     BD[EP0IN].status = 0xC8;         // send packet as DATA1, set UOWN bit
        //     break;

        case ENC_READ_REG:
            result = enc_readReg(USB_setup.wValue);
            BD[EP0IN].address[0] = result.b[0];
            BD[EP0IN].address[1] = result.b[1];
            BD[EP0IN].bytecount = 2;         // set EP0 IN byte count to 1
            BD[EP0IN].status = 0xC8;         // send packet as DATA1, set UOWN bit
            break;
        case TOGGLE_LED3:
            led_toggle(&led3);
            BD[EP0IN].bytecount = 0;         // set EP0 IN byte count to 0
            BD[EP0IN].status = 0xC8;         // send packet as DATA1, set UOWN bit
            break;
        case READ_SW2:
            BD[EP0IN].address[0] = (uint8_t)sw_read(&sw2);
            BD[EP0IN].bytecount = 1;         // set EP0 IN byte count to 1
            BD[EP0IN].status = 0xC8;         // send packet as DATA1, set UOWN bit
            break;
        case READ_SW3:
            BD[EP0IN].address[0] = (uint8_t)sw_read(&sw3);
            BD[EP0IN].bytecount = 1;         // set EP0 IN byte count to 1
            BD[EP0IN].status = 0xC8;         // send packet as DATA1, set UOWN bit
            break;
        default:
            USB_error_flags |= 0x01;    // set Request Error Flag
    }
}
예제 #3
0
void VendorRequests(void) {
    WORD32 address;
    WORD result;
    WORD32 result32;

    switch (USB_setup.bRequest) {
        case TOGGLE_LED1:
            led_toggle(&led1);
            BD[EP0IN].bytecount = 0;         // set EP0 IN byte count to 0
            BD[EP0IN].status = 0xC8;         // send packet as DATA1, set UOWN bit
            break;
        case TOGGLE_LED2:
            led_toggle(&led2);
            BD[EP0IN].bytecount = 0;         // set EP0 IN byte count to 0
            BD[EP0IN].status = 0xC8;         // send packet as DATA1, set UOWN bit
            break;
        case READ_SW1:
            BD[EP0IN].address[0] = (uint8_t)sw_read(&sw1);
            BD[EP0IN].bytecount = 1;         // set EP0 IN byte count to 1
            BD[EP0IN].status = 0xC8;         // send packet as DATA1, set UOWN bit
            break;
        case ENC_READ_REG:
            result = (WORD)motor1.wrap_count;
            // result = (WORD)enc.wrap_count;
            BD[EP0IN].address[0] = result.b[0];
            BD[EP0IN].address[1] = result.b[1];
            BD[EP0IN].bytecount = 2;         // set EP0 IN byte count to 4
            BD[EP0IN].status = 0xC8;         // send packet as DATA1, set UOWN bit
            break;
        case TOGGLE_LED3:
            led_toggle(&led3);
            BD[EP0IN].bytecount = 0;         // set EP0 IN byte count to 0
            BD[EP0IN].status = 0xC8;         // send packet as DATA1, set UOWN bit
            break;
        case READ_SW2:
            BD[EP0IN].address[0] = (uint8_t)sw_read(&sw2);
            BD[EP0IN].bytecount = 1;         // set EP0 IN byte count to 1
            BD[EP0IN].status = 0xC8;         // send packet as DATA1, set UOWN bit
            break;
        case READ_SW3:
            BD[EP0IN].address[0] = (uint8_t)sw_read(&sw3);
            BD[EP0IN].bytecount = 1;         // set EP0 IN byte count to 1
            BD[EP0IN].status = 0xC8;         // send packet as DATA1, set UOWN bit
            break;
        default:
            USB_error_flags |= 0x01;    // set Request Error Flag
    }
}
예제 #4
0
파일: main.c 프로젝트: n-kei/kozos-inspire
int main(void)
{
  INTR_DISABLE; /* 割込み無効にする */

  init_system();
  init_components();
  test_execute();

  if (PORTCONF_SDC_DETECT() && !sw_read(Sw1)) {
      puts("Boot : SDC detected.\n");
      puts("Boot : Booting from SDC.\n");
      boot_from_sdc("kozos");
      puts("Boot : Boot from SDC failed.\n");
      puts("Boot : Going to serial boot mode.\n");
      boot_from_ser();
  } else {
      puts("Boot : SDC not found.\n");
      puts("Boot : Going to serial boot mode.\n");
      boot_from_ser();
  }

  for (;;) { }

  return 0;
}
예제 #5
0
int main(void) {
    setup();
    pwm_set_duty(0);
    pwm_set_direction(0);
    
    printf("%s\r\n", "STARTING LOOP");
    float encoder_master_count = 0;
    uint16_t current_ticks = 0;
    uint16_t previous_ticks = spi_read_ticks();
    float target_degs = 10;
    float motor_current = 0;  // current through motor in amperes
    float pid_command = 0;
    float theor_torque;
    bitset(&IEC0, 2);
    bitset(&IEC0, 6);
    
    while (1) {
        if (timer_flag(&timer2)) {
            // Blink green light to show normal operation.
            timer_lower(&timer2);
            led_toggle(&led2);
        }

        if (timer_flag(&timer3)) {
            timer_lower(&timer3);
            led_toggle(&led3);
            theor_torque = spring_model(degs);  // Outputs theoretical torque predicted by spring model
            cur_control.set_point = fabsf(theor_torque);
            cur_control.neg_set_point = read_sign(theor_torque);
            read_motor_current(&motor);
            cur_control.position = convert_motor_torque(motor.current);
            pid_command = PID_control(&cur_control);
            pwm_duty = pid_to_pwm(pid_command, cur_control.neg_set_point);
        }

        if (!sw_read(&sw2)) {
            // If switch 2 is pressed, the UART output terminal is cleared.
            printf("%s", clear);
        }
        
        ServiceUSB();
        current_ticks = spi_read_ticks();
        encoder_master_count = encoder_counter(current_ticks, previous_ticks, encoder_master_count);
        degs = count_to_deg(encoder_master_count);
        previous_ticks = current_ticks;
        pin_toggle(DEBUGD1);  // Heartbeat signal
        
    }
}
예제 #6
0
int16_t main(void) {
    init_clock();
    init_ui();
    init_timer();

    led_on(&led1);
    timer_setPeriod(&timer2, 1.0);
    timer_start(&timer2);

    while (1) {
        if (timer_flag(&timer2)) {
            timer_lower(&timer2);
            led_toggle(&led1);
            led_toggle(&led2);
        }
        led_write(&led3, !sw_read(&sw3));
    }
}
예제 #7
0
int main(void) {
    setup();

    printf("%s\r\n", "STARTING LOOP");
    float encoder_master_count = 0;
    float previous_degs = 0;
    float current_degs = 0;
    uint16_t current_ticks = 0;
    uint16_t previous_ticks = spi_read_ticks();
   
    while (1) {
        if (timer_flag(&timer2)) {
            // Blink green light to show normal operation.
            timer_lower(&timer2);
            led_toggle(&led2);
            printf("ddegs %3f, dd %d\r\n", delta_degs, drive_direction);
        }

        if (timer_flag(&timer3)) {
            timer_lower(&timer3);
            delta_degs = current_degs - previous_degs;
            current_duty_cycle = damper(delta_degs);
            previous_degs = current_degs;
        }

        if (!sw_read(&sw2)) {
            // If switch 2 is pressed, the UART output terminal is cleared.
            printf("%s", clear);
        }
        ServiceUSB();
        current_ticks = spi_read_ticks();
        encoder_master_count = encoder_counter(current_ticks, previous_ticks, encoder_master_count);
        current_degs = count_to_deg(encoder_master_count);
        previous_ticks = current_ticks;
    }
}
예제 #8
0
void VendorRequests(void) {
    WORD32 address;
    WORD result;
    WORD temp;
    WORD temp0, temp1;
    float move_degs;

    switch (USB_setup.bRequest) {
        WORD temp;
        case TOGGLE_LED1:
            led_toggle(&led1);
            BD[EP0IN].bytecount = 0;         // set EP0 IN byte count to 0
            BD[EP0IN].status = 0xC8;         // send packet as DATA1, set UOWN bit
            break;
        case TOGGLE_LED2:
            led_toggle(&led2);
            BD[EP0IN].bytecount = 0;         // set EP0 IN byte count to 0
            BD[EP0IN].status = 0xC8;         // send packet as DATA1, set UOWN bit
            break;
        case TOGGLE_LED3:
            led_toggle(&led3);
            BD[EP0IN].bytecount = 0;         // set EP0 IN byte count to 0
            BD[EP0IN].status = 0xC8;         // send packet as DATA1, set UOWN bit
            break;
        case READ_SW1:
            BD[EP0IN].address[0] = (uint8_t)sw_read(&sw1);
            BD[EP0IN].bytecount = 1;         // set EP0 IN byte count to 1
            BD[EP0IN].status = 0xC8;         // send packet as DATA1, set UOWN bit
            break;
        case READ_SW2:
            BD[EP0IN].address[0] = (uint8_t)sw_read(&sw2);
            BD[EP0IN].bytecount = 1;         // set EP0 IN byte count to 1
            BD[EP0IN].status = 0xC8;         // send packet as DATA1, set UOWN bit
            break;
        case READ_SW3:
            BD[EP0IN].address[0] = (uint8_t)sw_read(&sw3);
            BD[EP0IN].bytecount = 1;         // set EP0 IN byte count to 1
            BD[EP0IN].status = 0xC8;         // send packet as DATA1, set UOWN bit
            break;
        case ENC_READ_REG:
            result = enc_readReg(USB_setup.wValue);
            BD[EP0IN].address[0] = result.b[0];
            BD[EP0IN].address[1] = result.b[1];
            BD[EP0IN].bytecount = 2;  // set EP0 IN byte count to 1
            BD[EP0IN].status = 0xC8;  // send packet as DATA1, set UOWN bit
            break;
        case SET_DAMPER_COEF:
            VEL_SCALER = (float)(USB_setup.wValue.w)/(float)(USB_setup.wIndex.w);
            printf("Set VEL_SCALER to %4f\r\n", VEL_SCALER);
            BD[EP0IN].bytecount = 0;    // set EP0 IN byte count to 0 
            BD[EP0IN].status = 0xC8;    // send packet as DATA1, set UOWN bit
            break;
        case READ_DAMPER_VEL:
            temp0.w = round((delta_degs + 50) * 100);
            BD[EP0IN].address[0] = temp0.b[0];
            BD[EP0IN].address[1] = temp0.b[1];
            float step1 = (current_duty_cycle * (float)((pwm_direction == 1) ? 1:-1));
            temp1.w = round( (step1 + 5) * 1000);
            BD[EP0IN].address[2] = temp1.b[0];
            BD[EP0IN].address[3] = temp1.b[1];
            BD[EP0IN].bytecount = 4;    // set EP0 IN byte count to 2
            BD[EP0IN].status = 0xC8;    // send packet as DATA1, set UOWN bit
            break;

        // case READ_VELOCITY:
        //     move_degs=(delta_degs + 50) * 100;
        //     temp.w = round(move_degs);
        //     BD[EP0IN].address[0] = temp.b[0];
        //     BD[EP0IN].address[1] = temp.b[1];
        //     BD[EP0IN].bytecount = 2;    // set EP0 IN byte count to 2
        //     BD[EP0IN].status = 0xC8;    // send packet as DATA1, set UOWN bit
        //     break;
        // case READ_POSITION:
        //     move_degs=(current_degs + 50) * 100;
        //     temp.w = round(move_degs);
        //     BD[EP0IN].address[0] = temp.b[0];
        //     BD[EP0IN].address[1] = temp.b[1];
        //     BD[EP0IN].bytecount = 2;    // set EP0 IN byte count to 2
        //     BD[EP0IN].status = 0xC8;    // send packet as DATA1, set UOWN bit
        //     break;
        default:
            USB_error_flags |= 0x01;  // set Request Error Flag
    }
}
예제 #9
0
void VendorRequests(void) {
    WORD32 address;
    WORD result;
    WORD temp;
    uint16_t temp0, temp1;
    float move_degs;

    switch (USB_setup.bRequest) {
        WORD temp;
        case TOGGLE_LED1:
            led_toggle(&led1);
            BD[EP0IN].bytecount = 0;         // set EP0 IN byte count to 0
            BD[EP0IN].status = 0xC8;         // send packet as DATA1, set UOWN bit
            break;
        case TOGGLE_LED2:
            led_toggle(&led2);
            BD[EP0IN].bytecount = 0;         // set EP0 IN byte count to 0
            BD[EP0IN].status = 0xC8;         // send packet as DATA1, set UOWN bit
            break;
        case TOGGLE_LED3:
            led_toggle(&led3);
            BD[EP0IN].bytecount = 0;         // set EP0 IN byte count to 0
            BD[EP0IN].status = 0xC8;         // send packet as DATA1, set UOWN bit
            break;
        case READ_SW1:
            BD[EP0IN].address[0] = (uint8_t)sw_read(&sw1);
            BD[EP0IN].bytecount = 1;         // set EP0 IN byte count to 1
            BD[EP0IN].status = 0xC8;         // send packet as DATA1, set UOWN bit
            break;
        case READ_SW2:
            BD[EP0IN].address[0] = (uint8_t)sw_read(&sw2);
            BD[EP0IN].bytecount = 1;         // set EP0 IN byte count to 1
            BD[EP0IN].status = 0xC8;         // send packet as DATA1, set UOWN bit
            break;
        case READ_SW3:
            BD[EP0IN].address[0] = (uint8_t)sw_read(&sw3);
            BD[EP0IN].bytecount = 1;         // set EP0 IN byte count to 1
            BD[EP0IN].status = 0xC8;         // send packet as DATA1, set UOWN bit
            break;
        case ENC_READ_REG:
            result = enc_readReg(USB_setup.wValue);
            BD[EP0IN].address[0] = result.b[0];
            BD[EP0IN].address[1] = result.b[1];
            BD[EP0IN].bytecount = 2;  // set EP0 IN byte count to 1
            BD[EP0IN].status = 0xC8;  // send packet as DATA1, set UOWN bit
            break;
        case SET_PID_P:
            cur_control.Kp = (float)(USB_setup.wValue.w)/(float)(USB_setup.wIndex.w);
            printf("Set Kp to %4f\r\n", cur_control.Kp);
            BD[EP0IN].bytecount = 0;    // set EP0 IN byte count to 0 
            BD[EP0IN].status = 0xC8;    // send packet as DATA1, set UOWN bit
            break;
        case SET_PID_I:
            cur_control.Ki = (float)(USB_setup.wValue.w)/(float)(USB_setup.wIndex.w);
            printf("Set Ki to %4f\r\n", cur_control.Kp);
            BD[EP0IN].bytecount = 0;    // set EP0 IN byte count to 0 
            BD[EP0IN].status = 0xC8;    // send packet as DATA1, set UOWN bit
            break;
        case SET_PID_D:
            cur_control.Kd = (float)(USB_setup.wValue.w)/(float)(USB_setup.wIndex.w);
            printf("Set Kd to %4f\r\n", cur_control.Kp);
            BD[EP0IN].bytecount = 0;    // set EP0 IN byte count to 0 
            BD[EP0IN].status = 0xC8;    // send packet as DATA1, set UOWN bit
            break;
        case SET_SPRING_CONSTANT:
            SPRING_CONSTANT = (float)(USB_setup.wValue.w)/(float)(USB_setup.wIndex.w);
            printf("Set spring constant to %4f\r\n", SPRING_CONSTANT);
            BD[EP0IN].bytecount = 0;    // set EP0 IN byte count to 0 
            BD[EP0IN].status = 0xC8;    // send packet as DATA1, set UOWN bit
            break;
        case READ_POSITION:
            move_degs=(degs + 50) * 100;
            temp.w = round(move_degs);
            BD[EP0IN].address[0] = temp.b[0];
            BD[EP0IN].address[1] = temp.b[1];
            BD[EP0IN].bytecount = 2;    // set EP0 IN byte count to 2
            BD[EP0IN].status = 0xC8;    // send packet as DATA1, set UOWN bit
            break;
        default:
            USB_error_flags |= 0x01;  // set Request Error Flag
    }
}
예제 #10
0
#include "config.h"
#include "common.h"
#include "ui.h"
#include "timer.h"

int16_t main(void) {
    init_clock();
    init_ui();
    init_timer();

    led_on(&led1);
    led_on(&led3);
    timer_setPeriod(&timer2, 0.5);
    timer_start(&timer2);

    while (1) {
        if (timer_flag(&timer2)) {
            timer_lower(&timer2);
            led_toggle(&led1);
            led_toggle(&led2);
<<<<<<< HEAD
        }
        led_write(&led3, !sw_read(&sw3));
=======
            led_toggle(&led3);
        }
>>>>>>> 4dd3851d0a27e51bc2f0abaa05a14a41831d8576
    }
}