Example #1
0
void setFreq(int keypadValue){
	if(keypadValue == 0xF){
		//default value
		EALLOW;
		ConfigCpuTimer(&CpuTimer1, 150, 1000000*1/10000*.5);
		CpuTimer1Regs.TCR.bit.TSS = 0;
		EALLOW;
	}
	else if(keypadValue == 1){ //
		//second value not default
		EALLOW;
		ConfigCpuTimer(&CpuTimer1, 150, 1000000*1/5000*.5);
		CpuTimer1Regs.TCR.bit.TSS = 0;
		EALLOW;
	}
	else if(keypadValue == 2){
		//third value
		EALLOW;
		ConfigCpuTimer(&CpuTimer1, 150, 1000000*1/20000*.5);
		CpuTimer1Regs.TCR.bit.TSS = 0;
		EALLOW;
	}
	else{
		//do nothing
	}
}
Example #2
0
void StopWatchSetUp(float time)
{
    // CPU Timer0
    // Initialize address pointers to respective timer registers:
    StopWatch.RegsAddr = &CpuTimer0Regs;
    // Initialize timer period to maximum:
    CpuTimer0Regs.PRD.all  = 0xFFFFFFFF;
    // Initialize pre-scale counter to divide by 1 (SYSCLKOUT):
    CpuTimer0Regs.TPR.all  = 0;
    CpuTimer0Regs.TPRH.all = 0;
    // Make sure timer is stopped:
    CpuTimer0Regs.TCR.bit.TSS = 1;
    // Reload all counter register with period value:
    CpuTimer0Regs.TCR.bit.TRB = 1;
    // Reset interrupt counters:
    StopWatch.InterruptCount = 0;

    ConfigCpuTimer(&StopWatch,CPU_FREQ_MHZ , time);

    //pie interrupt
    IER |= M_INT1;
    PieCtrlRegs.PIEIER1.bit.INTx7 = 1;

    ReloadCpuTimer0();
    StartCpuTimer0();
}
Example #3
0
/**
* Initialize the Timer0 Module   
*
* 
*
* @param  none
*
* @return none 
*/
void cpu_timer0_init(void)
{
// Configure CPU-Timer 0 to interrupt every 500 milliseconds:
// 60MHz CPU Freq, 50 millisecond Period (in uSeconds)
   ConfigCpuTimer(&CpuTimer0, 60, 500000);  // @tgh
   CpuTimer0Regs.TCR.all = 0x4001; // Use write-only instruction to set TSS bit = 0  @tgh
}
void timerStart(void){
	// Configure CPU-Timer 0. 1 ms ticks.
	ConfigCpuTimer(&CpuTimer0, 150, TICK_PERIOD_us);

	// To ensure precise timing, use write-only instructions to write to the entire register. Therefore, if any
	// of the configuration bits are changed in ConfigCpuTimer and InitCpuTimers (in DSP2833x_CpuTimers.h), the
	// below settings must also be updated.

	CpuTimer0Regs.TCR.all = 0x4001; // Use write-only instruction to set TSS bit = 0


	// Enable CPU int1 which is connected to CPU-Timer 0, CPU int13
	// which is connected to CPU-Timer 1, and CPU int 14, which is connected
	// to CPU-Timer 2:
	IER |= M_INT1;
	IER |= M_INT13;
	IER |= M_INT14;

	// Enable TINT0 in the PIE: Group 1 interrupt 7
	PieCtrlRegs.PIEIER1.bit.INTx7 = 1;

	// Enable global Interrupts and higher priority real-time debug events:
	EINT;   // Enable Global interrupt INTM
	ERTM;   // Enable Global realtime interrupt DBGM
}
Example #5
0
void changeFunctions(){
	EALLOW;
	ConfigCpuTimer(&CpuTimer1, 150, 1000000*1/20000*.5);
	CpuTimer1Regs.TCR.bit.TSS = 0;
	EALLOW;
	PieVectTable.XINT13 = &test_isr;
}
Example #6
0
void main(void)
{ 

	InitSysCtrl();
	InitXintf();
	InitXintf16Gpio();
	ADInit();
	DINT;
	InitPieCtrl();
	IER = 0x0000;
	IFR = 0x0000;
	InitPieVectTable();
   EALLOW;  // This is needed to write to EALLOW protected registers
   PieVectTable.TINT0 = &ISRTimer0;
   EDIS;    // This is needed to disable write to EALLOW protected registers
   InitCpuTimers();   // For this example, only initialize the Cpu Timers
   ConfigCpuTimer(&CpuTimer0, 100, 987); //在定时器内进行采样,采样率1.5KHz
	
    IER |= M_INT1;
    PieCtrlRegs.PIECTRL.bit.ENPIE = 1;
    PieCtrlRegs.PIEIER1.bit.INTx7 = 1; 
	EINT; 
	ERTM;  
/*EALLOW;
GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 0; // GPIO0 = GPIO0
GpioCtrlRegs.GPADIR.bit.GPIO0 = 1; 
EDIS;
GpioDataRegs.GPADAT.bit.GPIO0 = 0;*/
	SET_ADRST;  
	DELAY_US(100000);
	CLEAR_ADRST; 
	StartCpuTimer0();
	while(1);

}
Example #7
0
static void init_peripherals_drivers(void)
{
    uint16_t i;

    /// Initialization of HRADC boards
    stop_DMA();

    decimation_factor = HRADC_FREQ_SAMP / ISR_CONTROL_FREQ;
    decimation_coeff = 1.0 / decimation_factor;


    HRADCs_Info.enable_Sampling = 0;
    HRADCs_Info.n_HRADC_boards = NUM_HRADC_BOARDS;

    Init_DMA_McBSP_nBuffers(NUM_HRADC_BOARDS, decimation_factor, HRADC_SPI_CLK);

    Init_SPIMaster_McBSP(HRADC_SPI_CLK);
    Init_SPIMaster_Gpio();
    InitMcbspa20bit();

    DELAY_US(500000);
    send_ipc_lowpriority_msg(0,Enable_HRADC_Boards);
    DELAY_US(2000000);

    for(i = 0; i < NUM_HRADC_BOARDS; i++)
    {
        Init_HRADC_Info(&HRADCs_Info.HRADC_boards[i], i, decimation_factor,
                        buffers_HRADC[i], TRANSDUCER_GAIN[i]);
        Config_HRADC_board(&HRADCs_Info.HRADC_boards[i], TRANSDUCER_OUTPUT_TYPE[i],
                           HRADC_HEATER_ENABLE[i], HRADC_MONITOR_ENABLE[i]);
    }

    Config_HRADC_SoC(HRADC_FREQ_SAMP);

    /// Initialization of PWM modules
    g_pwm_modules.num_modules = 2;

    PWM_MODULATOR_MOD_A = &EPwm1Regs;
    PWM_MODULATOR_MOD_B = &EPwm2Regs;

    disable_pwm_outputs();
    disable_pwm_tbclk();
    init_pwm_mep_sfo();

    /// PWM initialization
    init_pwm_module(PWM_MODULATOR_MOD_A, PWM_FREQ, 0, PWM_Sync_Master, 0,
                    PWM_ChB_Independent, PWM_DEAD_TIME);

    init_pwm_module(PWM_MODULATOR_MOD_B, PWM_FREQ, 0, PWM_Sync_Slave, 0,
                    PWM_ChB_Independent, PWM_DEAD_TIME);

    InitEPwm1Gpio();
    InitEPwm2Gpio();

    /// Initialization of timers
    InitCpuTimers();
    ConfigCpuTimer(&CpuTimer0, C28_FREQ_MHZ, 1000000);
    CpuTimer0Regs.TCR.bit.TIE = 0;
}
Example #8
0
void changeFunctions(float samplingRate){
	EALLOW;
	ConfigCpuTimer(&CpuTimer1, 150,  1000000*1/samplingRate*.5);
	CpuTimer1Regs.TCR.bit.TSS = 0;

	EALLOW;
	PieVectTable.XINT13 = &DAC_isr;
}
Example #9
0
void changeFunctions(){
	EALLOW;
	ConfigCpuTimer(&CpuTimer1, 150,  1000000*1/20000*.5);
	CpuTimer1Regs.TCR.bit.TSS = 0;
	SRAMaddress = 0x260000;
	EALLOW;
	PieVectTable.XINT13 = &DAC_isr;
}
Example #10
0
/*-----------------------------------------------------------------------------
 * void config_schedulerTimer(void)
 *
 * Abstract:
 *      This function configures scheduler timer
 */
void config_schedulerTimer(void)
{
  InitCpuTimers();

  /* Configure CPU-Timer 0 to interrupt every 2.0E-7 sec. */
  /* Parameters:  Timer Pointer, CPU Freq in MHz, Period in usec. */
  ConfigCpuTimer(&CpuTimer0, 90.0, 2.0E-7 * 1000000);
  StartCpuTimer0();
}
Example #11
0
/* ----------------------- Start implementation -----------------------------*/
BOOL
xMBPortTimersInit( USHORT usTim1Timerout50us )
{
	// Interrupts that are used in this example are re-mapped to
	// ISR functions found within this file.
	EALLOW;  // This is needed to write to EALLOW protected registers
	PieVectTable.TINT0 = &prvvTIMERExpiredISR;
	EDIS;    // This is needed to disable write to EALLOW protected registers	

	// Initialize the Device Peripheral. This function can be found in DSP2833x_CpuTimers.c
	InitCpuTimers();

	#if (CPU_FRQ_150MHZ)
	// Configure CPU-Timer 0 to interrupt every second:
	// 150MHz CPU Freq, 1 second Period (in uSeconds)
	ConfigCpuTimer(&CpuTimer0, 150, usTim1Timerout50us);
	#endif

	#if (CPU_FRQ_100MHZ)
	// Configure CPU-Timer 0 to interrupt every second:
	// 100MHz CPU Freq, 1 second Period (in uSeconds)
	ConfigCpuTimer(&CpuTimer0, 100, usTim1Timerout50us);
	#endif

	// To ensure precise timing, use write-only instructions to write to the entire register. Therefore, if any
	// of the configuration bits are changed in ConfigCpuTimer and InitCpuTimers (in DSP2833x_CpuTimers.h), the
	// below settings must also be updated.
	//CpuTimer0Regs.TCR.all = 0x4009;	// Use write-only instruction to set TSS bit = 1
	CpuTimer0Regs.TCR.all = 0xC011;

	// Enable CPU int1 which is connected to CPU-Timer 0
	IER |= M_INT1;
	//IER |= M_INT13;
	//IER |= M_INT14;

	// Enable TINT0 in the PIE: Group 1 interrupt 7
	PieCtrlRegs.PIEIER1.bit.INTx7 = 1;

	// Enable global Interrupts and higher priority real-time debug events:
	EINT;   // Enable Global interrupt INTM
	ERTM;   // Enable Global realtime interrupt DBGM

    return TRUE;
}
Example #12
0
void main(void){

   InitSysCtrl();
   DINT;
   InitPieCtrl();
   IER = 0x0000;
   IFR = 0x0000;
   InitPieVectTable();
   EALLOW;  // This is needed to write to EALLOW protected registers
   PieVectTable.TIMER0_INT = &cpu_timer0_isr;
   EDIS;    // This is needed to disable write to EALLOW protected registers
   InitCpuTimers();   // For this example, only initialize the Cpu Timers
   // 100MHz CPU Freq, 50 microsecond Period (in uSeconds) 20,000 Hz
   ConfigCpuTimer(&CpuTimer0, CPU_CLOCK_100, INT_PERIOD_uS);
   CpuTimer0Regs.TCR.all = 0x4001; // Use write-only instruction to set TSS bit = 0

   // Configure GPIO12 (LED rojo) as a GPIO output pin
   EALLOW;
   GpioCtrlRegs.GPAMUX1.bit.GPIO12 = 0; // declare GPIO
   GpioCtrlRegs.GPADIR.bit.GPIO12 = 1;  // decalre as output
   EDIS;

   // Enable CPU INT1 which is connected to CPU-Timer 0:
   IER |= M_INT1;
   // Enable TINT0 in the PIE: Group 1 __interrupt 7
   PieCtrlRegs.PIEIER1.bit.INTx7 = 1;

   //Configure the ADCs and power them up
   ConfigureADC();
   //Setup the ADCs for software conversions
   SetupADCSoftware();

   // Enable DACOUTA
   EALLOW;
   //Use VDAC as the reference for DAC
   DaccRegs.DACCTL.bit.DACREFSEL  = REFERENCE_VDAC;
   //Enable DAC output
   DaccRegs.DACOUTEN.bit.DACOUTEN = 1;
   EDIS;

// iniciar buffers de datos
   init_buffer();

// Enable global Interrupts and higher priority real-time debug events:
   EINT;   // Enable Global __interrupt INTM
   ERTM;   // Enable Global realtime __interrupt DBGM


// Step 6. IDLE loop. Just sit and loop forever (optional):
   for(;;);
}
Example #13
0
/**
 * Añadir descripcion de la funcion
 * @param unsigned long int WaitTime
 * @returns void
 */
void SetAlarm(unsigned long int WaitTime)
{
	NextSchedulingDelay = WaitTime;

	EALLOW;
	PieVectTable.TINT0 = &cpu_timer0_isr;
	EDIS;

	CpuTimer0Regs.TCR.bit.TSS = 1;
	InitCpuTimers();
	ConfigCpuTimer(&CpuTimer0, 150, (float)(WaitTime*1000));
	CpuTimer0Regs.TCR.all = 0x4001; /** Use write-only instruction to set TSS bit = 0 */
	IER |= M_INT1;
	PieCtrlRegs.PIEIER1.bit.INTx7 = 1;
}
Example #14
0
void Uart_timer_init()
{
	EALLOW;
	PieVectTable.TINT0 = &cpu_timer0_isr;
	EDIS;

	InitCpuTimers();
	ConfigCpuTimer(&CpuTimer0, 60, 30000); // 30ms

	CpuTimer0Regs.TCR.all = 0x4001;
	IER |= M_INT1;

	// Enable TINT0 in the PIE: Group 1 interrupt 7
	PieCtrlRegs.PIEIER1.bit.INTx7 = 1;
}
Example #15
0
//---------------------------------------------------------------------------
// ConfigCpuTimer:
//---------------------------------------------------------------------------
// This function initializes the selected timer to the period specified
// by the "Freq" and "Period" parameters. The "Freq" is entered as "MHz"
// and the period in "uSeconds". The timer is held in the stopped state
// after configuration.
//
void SetupTimerInterrupt(void)
{
	InitCpuTimers();   // For this example, only initialize the Cpu Timers
    // Configure CPU-Timer 0, 1, and 2 to interrupt every second:
	// 150MHz CPU Freq, 1 msecond Period (in uSeconds)
    ConfigCpuTimer(&CpuTimer2, 150, 1000);
    // To ensure precise timing, use write-only instructions to write to the entire register. Therefore, if any
	// of the configuration bits are changed in ConfigCpuTimer and InitCpuTimers (in DSP2833x_CpuTimers.h), the
	// below settings must also be updated.
	CpuTimer2Regs.TCR.all = 0x4001; // Use write-only instruction to set TSS bit = 0
	// Step 4. User specific code, enable interrupts:
	// Enable  CPU int 14, which is connected to CPU-Timer 2:
	IER |= M_INT14;
	// Enable TINT0 in the PIE: Group 1 interrupt 7
	PieCtrlRegs.PIEIER1.bit.INTx7 = 1;

	// Enable global Interrupts and higher priority real-time debug events:
	EINT;   // Enable Global interrupt INTM
	ERTM;   // Enable Global realtime interrupt DBGM
}
void ClockSetup()
{
	Clock.RegsAddr = &CpuTimer1Regs;
	// Initialize timer period to maximum:
	CpuTimer1Regs.PRD.all  = 0xFFFFFFFF;
	// Initialize pre-scale counter to divide by 1 (SYSCLKOUT):
	CpuTimer1Regs.TPR.all  = 0;
	CpuTimer1Regs.TPRH.all = 0;
	// Make sure timer is stopped:
	CpuTimer1Regs.TCR.bit.TSS = 1;
	// Reload all counter register with period value:
	CpuTimer1Regs.TCR.bit.TRB = 1;
	// Reset interrupt counters:
	Clock.InterruptCount = 0;

	ConfigCpuTimer(&Clock,CPU_FREQ_MHZ, CLOCK_PERIOD);

	//pie interrupt
	IER |= M_INT13;

	ReloadCpuTimer1();
	StartCpuTimer1();
}
Example #17
0
/**
 * This function will initial TMS320F28379D board.
 */
void rt_hw_board_init()
{
    /* Configure the system clock @ 84 Mhz */
    InitSysCtrl();

    DINT;
    InitPieCtrl();

    IER = 0x0000;
    IFR = 0x0000;

    InitPieVectTable();

    EALLOW;  // This is needed to write to EALLOW protected registers
    PieVectTable.TIMER2_INT = &cpu_timer2_isr;
    PieVectTable.RTOS_INT = &RTOSINT_Handler;
    EDIS;

    InitCpuTimers();
    ConfigCpuTimer(&CpuTimer2, 200, 1000000 / RT_TICK_PER_SECOND);
    CpuTimer2Regs.TCR.all = 0x4000;
    IER |= M_INT14;

#ifdef RT_USING_HEAP
    rt_system_heap_init((void *)HEAP_BEGIN, (void *)HEAP_END);
#endif

    rt_hw_sci_init();

#ifdef RT_USING_COMPONENTS_INIT
    rt_components_board_init();
#endif
#ifdef RT_USING_CONSOLE
    rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
#endif
    rt_interrupt_leave_sethook((void (*)(void))trap_rtosint);
}
//
// IssueSCCReset - This function will generate SCC Reset for the specified
//                 CPU timer instance number
//
void IssueSCCReset(Uint16 peripheral_number)
{
    //
    // Initialize CPU timers. This will stop all timers.
    //
    InitCpuTimers();

    //
    // Configure the specified CPU Timer for a 500ns period @200MHz CPU Frq
    //
    ConfigCpuTimer(&(*TIMERVARS[peripheral_number]), 200, 0.5);

    EALLOW;

    //
    // Enable CPU interrupt 1, 13, and 14
    //
    IER |= (M_INT1 | M_INT13 | M_INT14);
    PieCtrlRegs.PIEIER1.bit.INTx7 = 1;

    //
    // Start specified Timer
    //
    (*TIMERREGS[peripheral_number]).TCR.all = 0x4020;

    //
    // Enable Global interrupt INTM
    //
    EINT;
    EDIS;

    while(1)
    {
        SafeCopyCodeZ1(32, (Uint16 *)0xC000, (Uint16 *)0x80000);
    }
}
Example #19
0
static void init_peripherals_drivers(void)
{
    uint16_t i;

    /// Initialization of HRADC boards
    stop_DMA();

    decimation_factor = (uint16_t) roundf(HRADC_FREQ_SAMP / ISR_CONTROL_FREQ);
    decimation_coeff = 1.0 / (float) decimation_factor;


    HRADCs_Info.enable_Sampling = 0;
    HRADCs_Info.n_HRADC_boards = NUM_HRADC_BOARDS;

    Init_DMA_McBSP_nBuffers(NUM_HRADC_BOARDS, decimation_factor, HRADC_SPI_CLK);

    Init_SPIMaster_McBSP(HRADC_SPI_CLK);
    Init_SPIMaster_Gpio();
    InitMcbspa20bit();

    DELAY_US(500000);
    send_ipc_lowpriority_msg(0,Enable_HRADC_Boards);
    DELAY_US(2000000);

    for(i = 0; i < NUM_HRADC_BOARDS; i++)
    {
        Init_HRADC_Info(&HRADCs_Info.HRADC_boards[i], i, decimation_factor,
                        buffers_HRADC[i], TRANSDUCER_GAIN[i]);
        Config_HRADC_board(&HRADCs_Info.HRADC_boards[i], TRANSDUCER_OUTPUT_TYPE[i],
                           HRADC_HEATER_ENABLE[i], HRADC_MONITOR_ENABLE[i]);
    }

    Config_HRADC_SoC(HRADC_FREQ_SAMP);

    /**
     *
     * Initialization of PWM modules. PWM signals are mapped as the following:
     *
     *      ePWM  =>  Signal    POF transmitter
     *     channel     Name        on BCB
     *
     *     ePWM1A => Q1_MOD_1       PWM1
     *     ePWM1B => Q1_MOD_5       PWM2
     *     ePWM2A => Q2_MOD_1       PWM3
     *     ePWM2B => Q2_MOD_5       PWM4
     *     ePWM3A => Q1_MOD_2       PWM5
     *     ePWM3B => Q1_MOD_6       PWM6
     *     ePWM4A => Q2_MOD_2       PWM7
     *     ePWM4B => Q2_MOD_6       PWM8
     *     ePWM5A => Q1_MOD_3       PWM9
     *     ePWM5B => Q1_MOD_7       PWM10
     *     ePWM6A => Q2_MOD_3       PWM11
     *     ePWM6B => Q2_MOD_7       PWM12
     *     ePWM7A => Q1_MOD_4       PWM13
     *     ePWM7B => Q1_MOD_8       PWM14
     *     ePWM8A => Q2_MOD_4       PWM15
     *     ePWM8B => Q2_MOD_8       PWM16
     *
     */

    g_pwm_modules.num_modules = 8;

    PWM_MODULATOR_Q1_MOD_1_5 = &EPwm1Regs;
    PWM_MODULATOR_Q2_MOD_1_5 = &EPwm2Regs;
    PWM_MODULATOR_Q1_MOD_2_6 = &EPwm3Regs;
    PWM_MODULATOR_Q2_MOD_2_6 = &EPwm4Regs;
    PWM_MODULATOR_Q1_MOD_3_7 = &EPwm5Regs;
    PWM_MODULATOR_Q2_MOD_3_7 = &EPwm6Regs;
    PWM_MODULATOR_Q1_MOD_4_8 = &EPwm7Regs;
    PWM_MODULATOR_Q2_MOD_4_8 = &EPwm8Regs;

    disable_pwm_outputs();
    disable_pwm_tbclk();
    init_pwm_mep_sfo();

    init_pwm_module(PWM_MODULATOR_Q1_MOD_1_5, PWM_FREQ, 0, PWM_Sync_Master, 0,
                    PWM_ChB_Independent, PWM_DEAD_TIME);
    init_pwm_module(PWM_MODULATOR_Q2_MOD_1_5, PWM_FREQ, 1, PWM_Sync_Slave, 180,
                    PWM_ChB_Independent, PWM_DEAD_TIME);
    cfg_pwm_module_h_brigde_q2(PWM_MODULATOR_Q2_MOD_1_5);

    init_pwm_module(PWM_MODULATOR_Q1_MOD_2_6, PWM_FREQ, 0, PWM_Sync_Slave, 45,
                    PWM_ChB_Independent, PWM_DEAD_TIME);
    init_pwm_module(PWM_MODULATOR_Q2_MOD_2_6, PWM_FREQ, 3, PWM_Sync_Slave, 225,
                    PWM_ChB_Independent, PWM_DEAD_TIME);
    cfg_pwm_module_h_brigde_q2(PWM_MODULATOR_Q2_MOD_2_6);

    init_pwm_module(PWM_MODULATOR_Q1_MOD_3_7, PWM_FREQ, 0, PWM_Sync_Slave, 90,
                    PWM_ChB_Independent, PWM_DEAD_TIME);
    init_pwm_module(PWM_MODULATOR_Q2_MOD_3_7, PWM_FREQ, 5, PWM_Sync_Slave, 270,
                    PWM_ChB_Independent, PWM_DEAD_TIME);
    cfg_pwm_module_h_brigde_q2(PWM_MODULATOR_Q2_MOD_3_7);

    init_pwm_module(PWM_MODULATOR_Q1_MOD_4_8, PWM_FREQ, 0, PWM_Sync_Slave, 135,
                    PWM_ChB_Independent, PWM_DEAD_TIME);
    init_pwm_module(PWM_MODULATOR_Q2_MOD_4_8, PWM_FREQ, 7, PWM_Sync_Slave, 315,
                    PWM_ChB_Independent, PWM_DEAD_TIME);
    cfg_pwm_module_h_brigde_q2(PWM_MODULATOR_Q2_MOD_4_8);

    InitEPwm1Gpio();
    InitEPwm2Gpio();
    InitEPwm3Gpio();
    InitEPwm4Gpio();
    InitEPwm5Gpio();
    InitEPwm6Gpio();
    InitEPwm7Gpio();
    InitEPwm8Gpio();

    /// Initialization of timers
    InitCpuTimers();
    ConfigCpuTimer(&CpuTimer0, C28_FREQ_MHZ, 1000000);
    CpuTimer0Regs.TCR.bit.TIE = 0;
}
main() {
    InitSysCtrl(); // 初始化system
    DINT;
    // 初始化PIE
    InitPieCtrl();
    // 初始化ADC
    InitPieVectTable();
    MemCopy(&RamfuncsLoadStart, &RamfuncsLoadEnd, &RamfuncsRunStart);
    InitFlash();
    //AdcOffsetSelfCal();
    InitAdc();

    IER = 0x0000;
    IFR = 0x0000;
    // 初始化中斷向量表

    InitEPwm1Gpio();
    GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 1;  // GPIO0 = PWM1A
    GpioCtrlRegs.GPADIR.bit.GPIO0 = 1;   //GPIO0 = output
    EALLOW;
    SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;
    InitEPwm1Example();

    InitCpuTimers();
    ConfigCpuTimer(&CpuTimer0, 1, 3906); //必須先配置  再致能 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    CpuTimer0Regs.TCR.all = 0x4000;   // 致能CPUTIMER0

    EDIS;

    // 設定中斷向量表位置
    EALLOW;
    PieVectTable.XINT1 = &xint1_isr;
    PieVectTable.XINT2 = &xint2_isr;
    PieVectTable.ADCINT1 = &adc_isr;
    PieVectTable.TINT0 = &cputimer_isr;
    EDIS;

    // 設置外部中斷腳位及燈號腳位
    EALLOW;
    GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 0;         // GPIO ADC開關
    GpioCtrlRegs.GPADIR.bit.GPIO1 = 0;          // input
    GpioCtrlRegs.GPAQSEL1.bit.GPIO1 = 0;        // XINT1 Synch to SYSCLKOUT only
    GpioIntRegs.GPIOXINT1SEL.bit.GPIOSEL = 1;   // XINT1 is GPIO1
    GpioCtrlRegs.GPAPUD.bit.GPIO1 = 0;

    GpioCtrlRegs.GPAMUX1.bit.GPIO2 = 0;         // GPIO
    GpioCtrlRegs.GPADIR.bit.GPIO2 = 1;          // OUTput
    GpioDataRegs.GPACLEAR.bit.GPIO2 = 1; 		// 當ADC ON/OFF 標示燈

    GpioCtrlRegs.GPAMUX1.bit.GPIO3 = 0;			// GPIO ePWM開關
    GpioCtrlRegs.GPADIR.bit.GPIO3 = 0;
    GpioCtrlRegs.GPAQSEL1.bit.GPIO3 = 0;        // XINT2 Synch to SYSCLKOUT only
    GpioIntRegs.GPIOXINT2SEL.bit.GPIOSEL = 3;   // XINT2 is GPIO3
    GpioCtrlRegs.GPAPUD.bit.GPIO3 = 0;  		//

    GpioCtrlRegs.GPAMUX1.bit.GPIO4 = 0;         // GPIO
    GpioCtrlRegs.GPADIR.bit.GPIO4 = 1;          // OUTput
    GpioDataRegs.GPACLEAR.bit.GPIO4 = 1; 		// 當 ePWM ON/OFF 標示燈

    GpioCtrlRegs.GPAMUX1.bit.GPIO6 = 0;         // GPIO
    GpioCtrlRegs.GPADIR.bit.GPIO6 = 1;          // OUTput 閃爍用
    GpioDataRegs.GPACLEAR.bit.GPIO6 = 1;
    EDIS;

    IER |= M_INT1;  // 開啟GROUP1中斷
    EINT;
    ERTM;

    EALLOW;
    PieCtrlRegs.PIECTRL.bit.ENPIE = 1;  // 致能PIE(非必要)
    PieCtrlRegs.PIEIER1.bit.INTx1 = 0;
    PieCtrlRegs.PIEIER1.bit.INTx4 = 1;
    PieCtrlRegs.PIEIER1.bit.INTx5 = 1;
    //PieCtrlRegs.PIEIER1.bit.INTx7 = 1;  // !!!!!!!! 不能同時開啟  , 否則打架  !!!!!!!!!
    XIntruptRegs.XINT1CR.bit.POLARITY = 3; // interrupt occur on both falling and rising edge
    XIntruptRegs.XINT1CR.bit.ENABLE = 1; // Enable Xint1
    XIntruptRegs.XINT2CR.bit.POLARITY = 3; // interrupt occur on both falling and rising edge
    XIntruptRegs.XINT2CR.bit.ENABLE = 1; // Enable Xint2
    EDIS;

    LoopCount = 0;
    ConversionCount = 0;

// Configure ADC
// Note: Channel ADCINA4  will be double sampled to workaround the ADC 1st sample issue for rev0 silicon errata

    EALLOW;
    AdcRegs.ADCCTL1.bit.ADCENABLE = 0;  // 不致能ADC (在initadc中已經致能)
    AdcRegs.ADCCTL1.bit.INTPULSEPOS = 1; //ADCINT1 trips after AdcResults latch

    AdcRegs.INTSEL1N2.bit.INT1E = 0;	//disabled ADCINT1
    AdcRegs.INTSEL1N2.bit.INT1CONT = 0;	//Disable ADCINT1 Continuous mode
    AdcRegs.INTSEL1N2.bit.INT1SEL = 0;	//setup EOC0 to trigger ADCINT1 to fire

    AdcRegs.ADCSOC0CTL.bit.CHSEL = 1;	//set SOC0 channel select to ADCINA1
    AdcRegs.ADCSOC0CTL.bit.TRIGSEL = 1;	//set SOC0 start trigger on CPUtimer
    AdcRegs.ADCSOC0CTL.bit.ACQPS = 6;//set SOC0 S/H Window to 7 ADC Clock Cycles, (6 ACQPS plus 1)
    //AdcRegs.ADCINTFLGCLR.bit.ADCINT1 = 1;
    EDIS;

    //GpioCtrlRegs.AIOMUX1.bit. &= ~(0x08);  // ADCINA1
//
    EALLOW;
    SysCtrlRegs.XCLK.bit.XCLKOUTDIV = 2;
    EDIS;

    for (;;) {
        //volatile long double n;
        //for (n = 0; n < 5000; n++)
        //	;
        //EALLOW;
        //GpioDataRegs.GPATOGGLE.bit.GPIO6 = 1;
        //EDIS;

        if (GpioDataRegs.GPADAT.bit.GPIO1 == 1) {
            Voltage1[array] = AdcResult.ADCRESULT0;

            if (Voltage1[array] > 5000) {
                EALLOW;
                SysCtrlRegs.PCLKCR1.bit.EPWM1ENCLK = 0;
                SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;
                SysCtrlRegs.LPMCR0.bit.LPM = 3;  // 全部休眠
                EDIS;

                EALLOW;
                SysCtrlRegs.CLKCTL.bit.WDHALTI = 1;  // 從休眠中開啟 , 全部重設!!
                EDIS;
            }

            v1 = 3031;
            v2 = (int)Voltage1[array];
            k1 = 0.3;	//0.0001;
            k2 = 0.000055;
            verr = v1 - v2;
            vk2 = verr + z1;
            z1 = verr;
            vko2 =(int) vk2 * k2;
            if (vko2 >= 1400)
            {
                vko2 = 1400;
            }
            else if (vko2 <= -1300) 	///////////////////////
            {
                vko2 = -1300;
            }
            vou2 = vko2 + z2;
            z2 = vou2;
            vk1 = verr;
            vko1 =(int) vk1 * k1;
            vout =(int)( vou2 + vko1);
            if (vout >= 1400) {
                vout = 1400;
            } else if (vout <= 0) {
                vout = 0;

            }

            EALLOW;
            EPwm1Regs.CMPA.half.CMPA = 1500 - vout;     // Set compare A value
            EDIS;
            if (array < 255)
                array++;
            else
                array = 0;
        }
    }

}
Example #21
0
main()
{
	int16 i;
	int16 j;
	int16 test[100];
   

//一、 system initialize: pll clock:150M;hispcp=1 100m/2; lospcp=2 100m/4;eWM,ADC,cpu Timer clock enabled
	InitSysCtrl(); //修改了默认时钟到150MHz,关闭了无关外设时钟

//	DELAY_US(1000000);	
//二、initialize GPIO:set the GPIO to it's default state: 普通GPIO状态,均为输入,输入采样方式为第一种,均为上拉使能.
              //epwm disable pull up
	InitGpio();	//全部引脚初始化

//用户自定义IO初始化(主要包括:逻辑输入输出引脚)
	InitLogicIO();

//串口初始化
	InitScicGpio();
	InitSci();
//初始化触摸屏变量
	initvar();


//	MemCopy(&RamfuncsLoadStart, &RamfuncsLoadEnd, &RamfuncsRunStart);
//EPwm初始化	
 //      InitEPwmGpio();	//PWM IO初始化
	//InitEPwm1Gpio(); 
	//InitEPwm2Gpio(); //所有PWM模块都需要开启
	//InitEPwm3Gpio();
	//InitEPwm4Gpio();
	//InitEPwm5Gpio();
	//InitEPwm6Gpio();


//三、initialize interrupts:disable cpu interrupt; disabel all pie interrupts and clear all pie interrupt flags
	DINT;
	InitPieCtrl();
	IER=0x0000;
	IFR=0x0000;
//initialize Pie interrupts and enable pie
	InitPieVectTable();

//用户自定义的中断初始化
	EALLOW;
	PieVectTable.TINT0 = &cpu_timer0_isr;  //Cpu timer0 interrupt
    PieVectTable.XINT1 = &xint1_isr;
	EDIS;


//四、initialize peripherials and setup peripherials
    InitFlash();

    InitXintf();

//ADC initialize
	InitAdc();
//ADC setup
	SetupAdc();

//       Adc_Inquire();
//Epwm Setup
//	SetupEPwm();   //pwm开始产生

//CPU timer0 initialize
	InitCpuTimers();
// Configure CPU-Timer 0 to interrupt every msecond:
// 150MHz CPU Freq, 3m second Period (in uSeconds)
   	ConfigCpuTimer(&CpuTimer0, 150, 3000);
   	StartCpuTimer0();

//五、User specific code, enable interrupts:

//在开始中断之前先进行测试循环。此时进行单步运行

//1. I/O test
	//测试程序,GPIOA的低18位为通用I/O输入
	//测试程序,GPIOA的24,25,26,27为通用I/O输入,GPIOB的48-61为通用I/O输入
	//由于I/o口均有上拉,所以只要测试输入0时是否正确即可。这样最大限度保护芯片。
   	for(i=0;i<100;i++)
   		{
   		j=i;
   		}

//   EALLOW;
//   GpioCtrlRegs.GPADIR.all = 0x0003FFFF;     // GPIO functionality GPIO0-GPIO15
//   EDIS;
//   GpioDataRegs.GPACLEAR.all = 0x0003FFFF;
//   GpioDataRegs.GPASET.all = 0x0001AAAA;
//   GpioDataRegs.GPATOGGLE.all = 0x0003FFFF;


//2. Communication Test:  //具体通讯是否成功还需要更多程序

	//测试RS485通讯芯片
		GpioDataRegs.GPASET.bit.GPIO21=1;
		GpioDataRegs.GPATOGGLE.bit.GPIO22=1;

	//测试CAN通讯芯片
		GpioDataRegs.GPATOGGLE.bit.GPIO19=1;

   	for(i=0;i<100;i++)
   		{
   		j=i;
   		}
	//测试RS485通讯芯片
		GpioDataRegs.GPASET.bit.GPIO21=1;
		GpioDataRegs.GPATOGGLE.bit.GPIO22=1;

	//测试CAN通讯芯片
		GpioDataRegs.GPATOGGLE.bit.GPIO19=1;

   	for(i=0;i<100;i++)
   		{
   		j=i;
   		}

// 3. A/D Test
	//软件启动adc转换

	for(i=0;i<100;i++)
   		{
		AdcRegs.ADCTRL2.bit.SOC_SEQ1=1;
		Adc_Inquire();
   		}

// 4. PWM Test  //每次测一个单相,这样子发现错误及时下电

   	for(i=0;i<100;i++)
   		{
   		j=i;
   		}
	
		*FPGA_PWMA_Wait1=1000;
		*FPGA_PWMA_Duty1=1000;

		*FPGA_PWMA_Wait2=2000;
		*FPGA_PWMA_Duty2=2000;

		*FPGA_PWMA_Wait3=3000;
		*FPGA_PWMA_Duty3=3000;

		*FPGA_PWMA_Wait4=4000;
		*FPGA_PWMA_Duty4=4000;

		*FPGA_PWMA_Wait5=5000;
		*FPGA_PWMA_Duty5=5000;

		*FPGA_PWMA_Wait6=6000;
		*FPGA_PWMA_Duty6=6000;

		*FPGA_PWMA_Wait7=1000;
		*FPGA_PWMA_Duty7=1000;

		*FPGA_PWMA_Wait8=2000;
		*FPGA_PWMA_Duty8=2000;

		*FPGA_PWMA_Wait9=3000;
		*FPGA_PWMA_Duty9=3000;

		*FPGA_PWMA_Wait10=4000;
		*FPGA_PWMA_Duty10=4000;

		*FPGA_PWMA_Wait11=5000;
		*FPGA_PWMA_Duty11=5000;

		*FPGA_PWMA_Wait12=6000;
		*FPGA_PWMA_Duty12=6000;

   	for(i=0;i<100;i++)
   		{
   		j=i;
   		}

		*FPGA_PWMB_Wait1=1000;
		*FPGA_PWMB_Duty1=1000;

		*FPGA_PWMB_Wait2=2000;
		*FPGA_PWMB_Duty2=2000;

		*FPGA_PWMB_Wait3=3000;
		*FPGA_PWMB_Duty3=3000;

		*FPGA_PWMB_Wait4=4000;
		*FPGA_PWMB_Duty4=4000;

		*FPGA_PWMB_Wait5=5000;
		*FPGA_PWMB_Duty5=5000;

		*FPGA_PWMB_Wait6=6000;
		*FPGA_PWMB_Duty6=6000;

		*FPGA_PWMB_Wait7=1000;
		*FPGA_PWMB_Duty7=1000;

		*FPGA_PWMB_Wait8=2000;
		*FPGA_PWMB_Duty8=2000;

		*FPGA_PWMB_Wait9=3000;
		*FPGA_PWMB_Duty9=3000;

		*FPGA_PWMB_Wait10=4000;
		*FPGA_PWMB_Duty10=4000;

		*FPGA_PWMB_Wait11=5000;
		*FPGA_PWMB_Duty11=5000;

		*FPGA_PWMB_Wait12=6000;
		*FPGA_PWMB_Duty12=6000;

   	for(i=0;i<100;i++)
   		{
   		j=i;
   		}

		*FPGA_PWMC_Wait1=1000;
		*FPGA_PWMC_Duty1=1000;

		*FPGA_PWMC_Wait2=2000;
		*FPGA_PWMC_Duty2=2000;

		*FPGA_PWMC_Wait3=3000;
		*FPGA_PWMC_Duty3=3000;

		*FPGA_PWMC_Wait4=4000;
		*FPGA_PWMC_Duty4=4000;

		*FPGA_PWMC_Wait5=5000;
		*FPGA_PWMC_Duty5=5000;

		*FPGA_PWMC_Wait6=6000;
		*FPGA_PWMC_Duty6=6000;

		*FPGA_PWMC_Wait7=1000;
		*FPGA_PWMC_Duty7=1000;

		*FPGA_PWMC_Wait8=2000;
		*FPGA_PWMC_Duty8=2000;

		*FPGA_PWMC_Wait9=3000;
		*FPGA_PWMC_Duty9=3000;

		*FPGA_PWMC_Wait10=4000;
		*FPGA_PWMC_Duty10=4000;

		*FPGA_PWMC_Wait11=5000;
		*FPGA_PWMC_Duty11=5000;

		*FPGA_PWMC_Wait12=6000;
		*FPGA_PWMC_Duty12=6000;

   	for(i=0;i<100;i++)
   		{
   		j=i;
   		}

		*FPGA_PWMD_Wait1=1000;
		*FPGA_PWMD_Duty1=1000;

		*FPGA_PWMD_Wait2=2000;
		*FPGA_PWMD_Duty2=2000;

		*FPGA_PWMD_Wait3=3000;
		*FPGA_PWMD_Duty3=3000;

		*FPGA_PWMD_Wait4=4000;
		*FPGA_PWMD_Duty4=4000;

		*FPGA_PWMD_Wait5=5000;
		*FPGA_PWMD_Duty5=5000;

		*FPGA_PWMD_Wait6=6000;
		*FPGA_PWMD_Duty6=6000;

		*FPGA_PWMD_Wait7=1000;
		*FPGA_PWMD_Duty7=1000;

		*FPGA_PWMD_Wait8=2000;
		*FPGA_PWMD_Duty8=2000;

		*FPGA_PWMD_Wait9=3000;
		*FPGA_PWMD_Duty9=3000;

		*FPGA_PWMD_Wait10=4000;
		*FPGA_PWMD_Duty10=4000;

		*FPGA_PWMD_Wait11=5000;
		*FPGA_PWMD_Duty11=5000;

		*FPGA_PWMD_Wait12=6000;
		*FPGA_PWMD_Duty12=6000;

   	for(i=0;i<100;i++)
   		{
   		j=i;
   		}

		*FPGA_PWME_Wait1=1000;
		*FPGA_PWME_Duty1=1000;

		*FPGA_PWME_Wait2=2000;
		*FPGA_PWME_Duty2=2000;

		*FPGA_PWME_Wait3=3000;
		*FPGA_PWME_Duty3=3000;

		*FPGA_PWME_Wait4=4000;
		*FPGA_PWME_Duty4=4000;

		*FPGA_PWME_Wait5=5000;
		*FPGA_PWME_Duty5=5000;

		*FPGA_PWME_Wait6=6000;
		*FPGA_PWME_Duty6=6000;

		*FPGA_PWME_Wait7=1000;
		*FPGA_PWME_Duty7=1000;

		*FPGA_PWME_Wait8=2000;
		*FPGA_PWME_Duty8=2000;

		*FPGA_PWME_Wait9=3000;
		*FPGA_PWME_Duty9=3000;

		*FPGA_PWME_Wait10=4000;
		*FPGA_PWME_Duty10=4000;

		*FPGA_PWME_Wait11=5000;
		*FPGA_PWME_Duty11=5000;

		*FPGA_PWME_Wait12=6000;
		*FPGA_PWME_Duty12=6000;

		//PWM复位功能演示,复位以后,所有PWM为零。
		GpioDataRegs.GPACLEAR.bit.GPIO31=1;
		DELAY_US(1);
		GpioDataRegs.GPASET.bit.GPIO31=1;

// 5. D/A Test


		*DAC1=1024;
		*DAC2=2048;
		*DAC3=3072;
		*DAC4=4095;

// 6.测试FPGA的I/O
// 首先测试是否结果为1
for(j=0;j<10;j++)
{
	for(i=0; i<24; i++)
		test[i]=*(FPGA_IO1_DATA+i);
	i=0;
		}
//再测试是否结果为0
for(j=0;j<100;j++)
{
	for(i=0; i<24; i++)
		test[i]=*(FPGA_IO1_DATA+i);
	i=0;
		}

//输出功能演示,只有输出使能的IO pin才能输出0
		*FPGA_IODIR_LOW=0xFFFF;
		*FPGA_IODIR_HIGH=0x00FF;

		j=0;

	for(i=0; i<24; i++)
	{

		*(FPGA_IO1_DATA+i)=j;
		j=~j;
		}

		j=0;

	for(i=0; i<24; i++)
	{
		j=~j;
		*(FPGA_IO1_DATA+i)=j;

		}

//复位功能演示,复位以后,所有IO上拉。且输出不使能
		GpioDataRegs.GPACLEAR.bit.GPIO30=1;
		DELAY_US(1);
		GpioDataRegs.GPASET.bit.GPIO30=1;

		j=*FPGA_IODIR_LOW;
		j=*FPGA_IODIR_HIGH;

		j=0;
	for(i=0; i<24; i++)
		*(FPGA_IO1_DATA+i)=j;

//开用到的中断,最后开中断。测试SCI 通讯以及DSP 和FPGA的通讯

	EnableInterrupts();  //cpu timer0 中断

	i=0;
	
// 六. 主循环IDLE loop. Just sit and loop forever (optional):
  	for(;;)
   	{
	//	ScicRegs.SCITXBUF=i;
		DELAY_US(1000);

/*
		if(GpioDataRegs.GPADAT.bit.GPIO27==0)
			GpioDataRegs.GPBCLEAR.bit.GPIO50=1;
		else 
			GpioDataRegs.GPBSET.bit.GPIO50=1;
						
		if(GpioDataRegs.GPBDAT.bit.GPIO48==0)
			GpioDataRegs.GPBCLEAR.bit.GPIO51=1;	
		else 
			GpioDataRegs.GPBSET.bit.GPIO51=1;	
	//	ModebusRegsDataBuff[0]=i;
//		GpioDataRegs.GPBTOGGLE.bit.GPIO60=1;
//		GpioDataRegs.GPBTOGGLE.bit.GPIO61=1;		
//		GpioDataRegs.GPBTOGGLE.bit.GPIO58=1;
//		GpioDataRegs.GPBTOGGLE.bit.GPIO59=1;

     	GpioDataRegs.GPBCLEAR.bit.GPIO53= 1;
     	GpioDataRegs.GPBCLEAR.bit.GPIO52= 1;
						
		i++;
	//	if(i==2000)
		if(i==FPGA_DATA_Test_length)
			i=0;
	//	TestState=~TestState;

*/
	
		slavecomm();	

		
   	}

	
}
Example #22
0
void main(void)
{
	//Enable peripheral clocks and other things
	//F2837xD_SysCtrl.c
	InitSysCtrl();

    EALLOW;
    GpioCtrlRegs.GPAMUX1.all = 0x00000000;  // All GPIO
    GpioCtrlRegs.GPAMUX2.all = 0x00000000;  // All GPIO
    GpioCtrlRegs.GPBMUX1.all = 0x00000000;  // All GPIO

    GpioCtrlRegs.GPADIR.all = 0xFFFFFFFF;   // All outputs
    GpioCtrlRegs.GPBDIR.all = 0x00001FFF;   // All outputs
    EDIS;

	//InitGpio();
	//initalize GPIO
	InitSpiaGpio();

	DINT;
	InitPieCtrl();

	// Disable CPU __interrupts and clear all CPU __interrupt flags:
	IER = 0x0000;
	IFR = 0x0000;

	InitPieVectTable();

	EALLOW; //This is needed to write to EALLOW protected registers
	ClkCfgRegs.LOSPCP.bit.LSPCLKDIV = 0x5; //LSPCLK (200 Mhz)/10


	//-----------------------------------------------------------------------------------
	//Instantiate CPU timer control
	//CPU timer interrupt services in prototype phase
	EALLOW;
	PieVectTable.TIMER0_INT = &cpu_timer0_isr;
	PieVectTable.TIMER1_INT = &cpu_timer1_isr;
	PieVectTable.TIMER2_INT = &cpu_timer2_isr;
	EDIS; //This is needed to disable write to EALLOW protected registers

	InitCpuTimers();

    // Configure CPU-Timer 0, 1, and 2 to interrupt every second:
    // 200MHz CPU Freq, 1 second Period (in uSeconds)
	ConfigCpuTimer(&CpuTimer0, 200, 100000);
    ConfigCpuTimer(&CpuTimer1, 200, 10000000);
    ConfigCpuTimer(&CpuTimer2, 200, 1000000);

    // To ensure precise timing, use write-only instructions to write to the entire register. Therefore, if any
    // of the configuration bits are changed in ConfigCpuTimer and InitCpuTimers (in F2837xD_cputimervars.h), the
    // below settings must also be updated.
	CpuTimer0Regs.TCR.all = 0x4000; // Use write-only instruction to set TSS bit = 0
    CpuTimer1Regs.TCR.all = 0x4000; // Use write-only instruction to set TSS bit = 0
    CpuTimer2Regs.TCR.all = 0x4000; // Use write-only instruction to set TSS bit = 0

    // Enable CPU int1 which is connected to CPU-Timer 0, CPU int13
    // which is connected to CPU-Timer 1, and CPU int 14, which is connected
    // to CPU-Timer 2:
	IER |= M_INT1;
    IER |= M_INT13;
    IER |= M_INT14;

    // Enable TINT0 in the PIE: Group 1 interrupt 7
    PieCtrlRegs.PIEIER1.bit.INTx7 = 1;

    // Enable global Interrupts and higher priority real-time debug events:
    EINT; // Enable Global interrupt INTM
    ERTM; // Enable Global realtime interrupt DBGM
	//Enable interrupts

    //End CPU timer configuration
	//-----------------------------------------------------------------------------------

    spi_init();
	spi_fifo();
	output_high();
	DELAY_US(1000000);
	LTC_wakeup();

	/*
	//LTC ADCV read voltage functions here ---
	//Note: Additional ADC readings may be possible i.e Sum of Measurement cells,
	LTC_refon_set();
	LTC_ADC_clear();
	//LTC_ADC_conversion();
	//----------------------------------------

	//need to somehow clear receive buffer
	SpiaRegs.SPIFFRX.bit.RXFFOVFCLR = 1;

	//LTC_read_voltages_123();
	//LTC_read_voltages_456();
	//LTC_read_voltages_789();
	//LTC_read_voltages_10_11_12();

	//LTC_UVOV_get_flags();

	//ready_rxbuf();
	//read_voltage_from_receive_buffer();
	//receive_all_data();
	//LTC_read_UVOV_flags();
	//read_voltage_from_receive_buffer();

	//Uint16 checker[6] = {rdata[0], rdata[1], rdata[2], rdata[3], rdata[4], rdata[5]};
	//Uint16 PEC_check = LTC_pec_calc(checker, 6);
	*/
	//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
	for(;;) //infinite loop
	{
		//incorporate a regular LTC_wakeup procedure (< 2.0 seconds)
		//incorporate a regular LTC pulse signal (< 1.5 seconds)
		//It is important to regularly pulse wake up and pulse signals to the
		//LTC6804-2 and LTC3300 boards so that the Watchdog Timer does not expire
		//LTC6804-2 ADC reference ON
		//LTC3300 72 pulse cycle of an execute command repeatedly operating
	}
}
Example #23
0
void timerINIT(){


	// Step 1. Initialize System Control:
	// PLL, WatchDog, enable Peripheral Clocks
	// This example function is found in the DSP2833x_SysCtrl.c file.
	 //InitPeripheralClocks();

	// Step 2. Initalize GPIO:
	// This example function is found in the DSP2833x_Gpio.c file and
	// illustrates how to set the GPIO to it's default state.
	// InitGpio();  // Skipped for this example


	// Step 3. Clear all interrupts and initialize PIE vector table:
	// Disable CPU interrupts
	   DINT;

	// Initialize the PIE control registers to their default state.
	// The default state is all PIE interrupts disabled and flags
	// are cleared.
	// This function is found in the DSP2833x_PieCtrl.c file.
	   InitPieCtrl();

	// Disable CPU interrupts and clear all CPU interrupt flags:
	   IER = 0x0000;
	   IFR = 0x0000;

	// Initialize the PIE vector table with pointers to the shell Interrupt
	// Service Routines (ISR).
	// This will populate the entire table, even if the interrupt
	// is not used in this example.  This is useful for debug purposes.
	// The shell ISR routines are found in DSP2833x_DefaultIsr.c.
	// This function is found in DSP2833x_PieVect.c.
	   InitPieVectTable();

	// Interrupts that are used in this example are re-mapped to
	// ISR functions found within this file.
	   EALLOW;  // This is needed to write to EALLOW protected registers
	 // PieVectTable.TINT0 = &cpu_timer0_isr;
	   PieVectTable.XINT13 = &ADC_isr;
	  //PieVectTable.TINT2 = &cpu_timer2_isr;
	   EDIS;    // This is needed to disable write to EALLOW protected registers

	// Step 4. Initialize the Device Peripheral. This function can be
	//         found in DSP2833x_CpuTimers.c
	   InitCpuTimers();   // For this example, only initialize the Cpu Timers
	   EALLOW;


// Configure CPU-Timer 0, 1, and 2 to interrupt every second:
// 150MHz CPU Freq, 1 second Period (in uSeconds)

  // ConfigCpuTimer(&CpuTimer0, 150, 1000000);
   ConfigCpuTimer(&CpuTimer1, 150, 1000000*1/20000*.5); //1/10000 is the frequency we want to toggle timer1 to interrupt
   //ConfigCpuTimer(&CpuTimer2, 150, 1000000);




	// To ensure precise timing, use write-only instructions to write to the entire register. Therefore, if any
	// of the configuration bits are changed in ConfigCpuTimer and InitCpuTimers (in DSP2833x_CpuTimers.h), the
	// below settings must also be updated.

	  // CpuTimer0Regs.TCR.all = 0x4001; // Use write-only instruction to set TSS bit = 0
	   CpuTimer1Regs.TCR.all = 0x4001; // Use write-only instruction to set TSS bit = 0
	   //CpuTimer2Regs.TCR.all = 0x4001; // Use write-only instruction to set TSS bit = 0

	// Step 5. User specific code, enable interrupts:


	// Enable CPU int1 which is connected to CPU-Timer 0, CPU int13
	// which is connected to CPU-Timer 1, and CPU int 14, which is connected
	// to CPU-Timer 2:
	   //IER |= M_INT1;
	   IER |= M_INT13;
	   //IER |= M_INT14;

	// Enable TINT0 in the PIE: Group 1 interrupt 7
	   PieCtrlRegs.PIEIER1.bit.INTx7 = 1;

	// Enable global Interrupts and higher priority real-time debug events:
	   EINT;   // Enable Global interrupt INTM
	   ERTM;   // Enable Global realtime interrupt DBGM
	   EALLOW;

	// Step 6. IDLE loop. Just sit and loop forever (optional):


}
//
// Main
//
void main(void)
{
//
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the F2837xS_SysCtrl.c file.
//
    InitSysCtrl();

//
// Step 2. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts
//
    DINT;

//
// Initialize the PIE control registers to their default state.
// The default state is all PIE interrupts disabled and flags
// are cleared.
// This function is found in the F2837xS_PieCtrl.c file.
//
    InitPieCtrl();

//
// Disable CPU interrupts and clear all CPU interrupt flags:
//
    IER = 0x0000;
    IFR = 0x0000;

//
// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
// This will populate the entire table, even if the interrupt
// is not used in this example.  This is useful for debug purposes.
// The shell ISR routines are found in F2837xS_DefaultIsr.c.
// This function is found in F2837xS_PieVect.c.
//
    InitPieVectTable();

//
// Step 3. Configure the timer used to profile the TMU and RTS routines
//
    InitCpuTimers();
    ConfigCpuTimer(&CpuTimer1, PROFILE_FREQ, PROFILE_PER);

//
// Step 4. Enable global Interrupts and higher priority real-time debug events:
//
    EINT;  // Enable Global interrupt INTM
    ERTM;  // Enable Global realtime interrupt DBGM

//
// Step 5. Run the test, generate the input vector, call the RTS/TMU
// routines, get the error vector and, finally, print the execution time.
//
    genInputVector(inputVector, VECTOR_SIZE);
    ticksRTS = RTS_runTest(inputVector, rtsOutput, VECTOR_SIZE);
    ticksTMU = TMU_runTest(inputVector, tmuOutput, VECTOR_SIZE);
    maxError = genErrorVector(rtsOutput, tmuOutput, errorVector, VECTOR_SIZE);
    timeRTS = ticksRTS * (1.0/PROFILE_FREQ);
    timeTMU = ticksTMU * (1.0/PROFILE_FREQ);

//
// To use the printf statement, allocate space for the .cio, .sysmem section,
// increase allotment for the .text, stack and heap sections in the properties
// and linker command file.
//
    printf("Execution Results \n");
    printf("RTS Time : %10.6f us\n", timeRTS);
    printf("TMU Time : %10.6f us\n", timeTMU);
}
void main(void)
{
//
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the F2837xS_SysCtrl.c file.
//
   InitSysCtrl();

//
// Step 2. Initialize GPIO:
// This example function is found in the F2837xS_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
//
// InitGpio();  // Skipped for this example

//
// Step 3. Clear all __interrupts and initialize PIE vector table:
//
   DINT;

//
// Initialize the PIE control registers to their default state.
// The default state is all PIE __interrupts disabled and flags
// are cleared.
// This function is found in the F2837xS_PieCtrl.c file.
//
   InitPieCtrl();

//
// Disable CPU __interrupts and clear all CPU __interrupt flags:
//
   IER = 0x0000;
   IFR = 0x0000;

//
// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
// This will populate the entire table, even if the __interrupt
// is not used in this example.  This is useful for debug purposes.
// The shell ISR routines are found in F2837xS_DefaultIsr.c.
// This function is found in F2837xS_PieVect.c.
//
   InitPieVectTable();

//
// Interrupts that are used in this example are re-mapped to
// ISR functions found within this file.
//
   EALLOW;  // This is needed to write to EALLOW protected registers
   PieVectTable.TIMER0_INT = &cpu_timer0_isr;
   EDIS;    // This is needed to disable write to EALLOW protected registers

//
// Step 4. Initialize the Device Peripheral. This function can be
//         found in F2837xS_CpuTimers.c
//
   InitCpuTimers();   // For this example, only initialize the Cpu Timers

//
// Configure CPU-Timer 0 to __interrupt every 500 milliseconds:
// 60MHz CPU Freq, 50 millisecond Period (in uSeconds)
//
   ConfigCpuTimer(&CpuTimer0, 60, 500000);

//
// To ensure precise timing, use write-only instructions to write to the entire
// register. Therefore, if any of the configuration bits are changed in
// ConfigCpuTimer and InitCpuTimers (in F2837xS_cputimervars.h), the below
// settings must also be updated.
//
   CpuTimer0Regs.TCR.all = 0x4001;

//
// Step 5. User specific code, enable __interrupts:
// Configure GPIO34 as a GPIO output pin
//
   EALLOW;
   GpioCtrlRegs.GPBMUX1.bit.GPIO34 = 0;
   GpioCtrlRegs.GPBDIR.bit.GPIO34 = 1;
   EDIS;

//
// Enable CPU INT1 which is connected to CPU-Timer 0:
//
   IER |= M_INT1;

//
// Enable TINT0 in the PIE: Group 1 __interrupt 7
//
   PieCtrlRegs.PIEIER1.bit.INTx7 = 1;

//
// Enable global Interrupts and higher priority real-time debug events:
//
   EINT;   // Enable Global __interrupt INTM
   ERTM;   // Enable Global realtime __interrupt DBGM

//
// Step 6. IDLE loop. Just sit and loop forever (optional):
//
   for(;;);
}
Example #26
0
File: main.c Project: fcq1129/dsp
void main()
{
	InitSysCtrl();  //初始化系统
	
	DINT;          //关中断  
	IER = 0x0000;
	IFR = 0x0000;

	InitPieCtrl();  //初始化PIE

	InitPieVectTable();  //初始化PIE中断向量表

	InitPeripherals();   //初始化外设
	PieCtrl.PIEIER1.bit.INTx7 = 1; //使能PIE模块中的CPU定时器0的中断
	IER|=M_INT1;                   //开CPU中断1;
	EINT;                          //使能全局中断

	ConfigCpuTimer(&CpuTimer0,150,900000); //CpuTimer0中断时间1s
	StartCpuTimer0();             //启动CPU定时器0	
	
	GpioDataRegs.GPDDAT.bit.GPIOD5 = 0; //输出为低
	GpioDataRegs.GPDDAT.bit.GPIOD6 = 0;

	WriteLcdCom(0x01);////清屏
    WriteLcdCom(0x0c);////整体显示开,游标开

	WriteLcdCom(0x90);  //第二行显示信息
	WriteLcdDat(0xb7);
	WriteLcdDat(0xeb);
	WriteLcdDat(0xb3);
	WriteLcdDat(0xa4);
	WriteLcdDat(0xc7);
	WriteLcdDat(0xe0);
	
	for(;;)
		
	{    WriteLcdCom(0x80);        //第一行第一个字节地址
//		ShowNumber(9);
		ShowNumber(Clock.hours/10); //显示小时
		ShowNumber(Clock.hours%10);

		WriteLcdDat(0xa1);      //在小时和分钟之间加:分隔
		WriteLcdDat(0xc3);

		ShowNumber(Clock.mins/10); //显示分钟
		ShowNumber(Clock.mins%10);

		WriteLcdDat(0xa1);      //在分钟和秒之间加:分隔
		WriteLcdDat(0xc3);

		ShowNumber(Clock.secs/10);  //显示秒
		ShowNumber(Clock.secs%10);
			
		WriteLcdCom(0x90);  //第二行显示信息
		WriteLcdDat(0xb7);
		WriteLcdDat(0xeb);
		WriteLcdDat(0xb3);
		WriteLcdDat(0xa4);
		WriteLcdDat(0xc7);
		WriteLcdDat(0xe0);
	}

    
      


}
Example #27
0
void main()
{
	int i;
	InitSysCtrl();
	InitGpio();
	DINT;					//禁止全局中断
	InitPieCtrl();			//将PIE控制寄存器初始化为默认状态
	IER=0x0000;				//禁止CPU中断(IER:CPU级中断使能寄存器)
	IFR=0x0000;				//清除CPU中断标志位(IFR:CPU级中断标志寄存器)
	InitPieVectTable(); 	//初始化中断向量表
	EALLOW;					//确认中断函数入口地址

	/***********车哥的是把MemoryCopy()放在这里************/

	PieVectTable.T1PINT = &renew_PWM_isr;
	PieVectTable.RXAINT = &scia_receive_isr;
	PieVectTable.TXAINT = &scia_send_isr;
	PieVectTable.RXBINT = &scib_receive_isr;
	PieVectTable.TXBINT = &scib_send_isr;
	//PieVectTable.CAPINT5= &measure_height_isr;
	PieVectTable.TINT0  = &cpu_timer0_isr;
//	PieVectTable.ADCINT = &adc_isr;

	EDIS;
	InitPeripherals();
	ConfigCpuTimer(&CpuTimer0, 150, 1000000);
	StartCpuTimer0();

	// Configure ADC
//	AdcRegs.ADCMAXCONV.all = 0x0001;       // Setup 2 conv's on SEQ1
//	AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x3; // Setup ADCINA3 as 1st SEQ1 conv.
//	AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 0x2; // Setup ADCINA2 as 2nd SEQ1 conv.
//	AdcRegs.ADCTRL2.bit.EVA_SOC_SEQ1 = 1;  // Enable EVASOC to start SEQ1
//	AdcRegs.ADCTRL2.bit.INT_ENA_SEQ1 = 1;  // Enable SEQ1 interrupt (every EOS)

//	EvaRegs.GPTCONA.bit.T1TOADC = 1;       // Enable EVASOC in EVA
	for(i=0;i<11;i++)  	//初始化数据变量
	{
	    bufferA[i] = 0;
	    bufferB[i] = 0;
    }

	MemCopy(&RamfuncsLoadStart, &RamfuncsLoadEnd, &RamfuncsRunStart);
	InitFlash();

	PieCtrlRegs.PIEIER2.bit.INTx4=1;	//使能INT2 INTx4 T1PINT
	PieCtrlRegs.PIEIER9.bit.INTx1=1;  	//使能PIE模块中的SCIA接收中断
	PieCtrlRegs.PIEIER9.bit.INTx2=1;  	//使能PIE模块中的SCIA发送中断
	PieCtrlRegs.PIEIER9.bit.INTx3=1;	//使能PIE模块中的SCIB接收中断
	PieCtrlRegs.PIEIER9.bit.INTx4=1;	//使能PIE模块中的SCIB发送中断
//	PieCtrlRegs.PIEIER5.bit.INTx6=1;	//使能PIE模块中的CAP5捕获中断
	PieCtrlRegs.PIEIER1.bit.INTx7=1;	//使能PIE模块中的CPU定时器中断
	PieCtrlRegs.PIEIER1.bit.INTx6=1;	//使能PIE模块中的ADC中断
	IER|=M_INT9 | M_INT2  | M_INT1;		//开CPU中断

	EINT;  								//开全局中断
	ERTM;  								//开全局实时中断


	/*初始化pid_z模块	全局Q24
	pid_z.param.Kp  =_IQ(0.5);
	pid_z.param.Ki  =_IQ(0.0);
	pid_z.param.Kd  =_IQ(0);
	pid_z.param.Kr  =_IQ(1.0);
	pid_z.param.Km  =_IQ(1.0);
	pid_z.param.Umax=_IQ(1.0);
	pid_x.param.Umin=_IQ(1.0);

	//初始化pid_y模块	全局Q24
	pid_y.param.Kp  =_IQ(0.01);
	pid_y.param.Ki  =_IQ(0);
	pid_y.param.Kd  =_IQ(0);
	pid_y.param.Kr  =_IQ(1.0);
	pid_y.param.Km  =_IQ(1.0);
	pid_y.param.Umax=_IQ(10.0);
	pid_y.param.Umin=_IQ(10.0);

	//初始化pid_x模块	全局Q24
	pid_x.param.Kp  =_IQ(0.01);
	pid_x.param.Ki  =_IQ(0);
	pid_x.param.Kd  =_IQ(0);
	pid_x.param.Kr  =_IQ(1.0);
	pid_x.param.Km  =_IQ(1.0);
	pid_x.param.Umax=_IQ(10.0);
	pid_x.param.Umin=_IQ(10.0);
	*/
	/**************看门狗******************
	EALLOW;
	SysCtrlRegs.SCSR=1;
	EDIS;
	KickDog();
	EALLOW;
	SysCtrlRegs.WDCR =0x2F;				//使能看门狗
	EDIS;
	************************************/

	//DELAY_US(2000000);					//安全起见延时10s,现在延时2s做实验

	DELAY_US(5000000);				//delay 3s


//	EvaRegs.T1CMPR=0x5B8D;				//50%
//	EvaRegs.T2CMPR=0x5B8D;
//	EvbRegs.T3CMPR=0x5B8D;
//	EvbRegs.T4CMPR=0x5B8D;

//	EvaRegs.T1CMPR=soilgate;			//60%
//	EvaRegs.T2CMPR=soilgate;
//	EvbRegs.T3CMPR=soilgate;
//	EvbRegs.T4CMPR=soilgate;
//	DELAY_US(2000000);
/*
	EvaRegs.T1CMPR=0x7704;				//65%
	EvaRegs.T2CMPR=0x7704;
	EvbRegs.T3CMPR=0x7704;
	EvbRegs.T4CMPR=0x7704;
*/
	/**********************油门设置*************************
	EvaRegs.T1CMPR=0x927C;
	EvaRegs.T2CMPR=0x927C;
	EvbRegs.T3CMPR=0x927C;
	EvbRegs.T4CMPR=0x927C;
	DELAY_US(3000000);					//delay 2s
	EvaRegs.T1CMPR=0x493E;
	EvaRegs.T2CMPR=0x493E;
	EvbRegs.T3CMPR=0x493E;
	EvbRegs.T4CMPR=0x493E;
	****************************************************/



	//进入循环,等待中断
	for(;;)
	{
		DELAY_US(20000000);
		TakeoffSoilgate(23437);		//50%
		DELAY_US(2000000);
		TakeoffSoilgate(26906);		//起飞57.3%
		DELAY_US(10000000);
		TakeoffSoilgate(26250);		//软着陆
		DELAY_US(1000000);
		TakeoffSoilgate(25312);
		DELAY_US(1000000);
		TakeoffSoilgate(0x500E);
		DELAY_US(15000000);
		TakeoffSoilgate(26906);		//起飞
		b=-3.5;
		DELAY_US(6000000);
		TakeoffSoilgate(26250);		//软着陆
		DELAY_US(1000000);
		TakeoffSoilgate(25312);
		DELAY_US(1000000);
		TakeoffSoilgate(0x500E);
		DELAY_US(15000000);
//		TakeoffSoilgate(26906);		//起飞
		for(;;)
		{

		}
		/*
		switch(FlyFlag)
		{
			case 1:						//起飞

				 TakeoffSoilgate(809);
				 DELAY_US(2000000);
				 TakeoffSoilgate(23437);
				 break;
			case 2:						//开启定高PID,飞行20s
				 ;
				 break;
			case 3:						//降落
				 break;
			case 4:						//起飞
				 break;
			case 5:						//往回飞,改大点飞行角度
				 break;
			case 6:						//降落
				 break;
			case 7:						//起飞
				 break;
			case 8:						//飞行,此过程中有风扇
				 break;
			case 9:						//降落
				 break;
		}
		*/

	}//end for loop
}//end main
Example #28
0
void changeFrequency(long freq){
	EALLOW;
	ConfigCpuTimer(&CpuTimer1, 150,  1000000*1/freq*.5);
	CpuTimer1Regs.TCR.bit.TSS = 0;

}