//
// Main
//
void main(void)
{
    Uint16 ReceivedChar;
    char *msg;

//
// 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();

//
// For this example, only init the pins for the SCI-A port.
//  GPIO_SetupPinMux() - Sets the GPxMUX1/2 and GPyMUX1/2 register bits
//  GPIO_SetupPinOptions() - Sets the direction and configuration of the GPIOS
// These functions are found in the F2837xS_Gpio.c file.
//
   GPIO_SetupPinMux(28, GPIO_MUX_CPU1, 1);
   GPIO_SetupPinOptions(28, GPIO_INPUT, GPIO_PUSHPULL);
   GPIO_SetupPinMux(29, GPIO_MUX_CPU1, 1);
   GPIO_SetupPinOptions(29, GPIO_OUTPUT, GPIO_ASYNC);

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

//
// Initialize 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 4. User specific code:
//
   LoopCount = 0;

   scia_fifo_init();       // Initialize the SCI FIFO
   scia_echoback_init();   // Initialize SCI for echoback

   msg = "\r\n\n\nHello World!\0";
   scia_msg(msg);

   msg = "\r\nYou will enter a character, and the DSP will echo it back! \n\0";
   scia_msg(msg);

   for(;;)
   {
       msg = "\r\nEnter a character: \0";
       scia_msg(msg);

       //
       // Wait for inc character
       //
       while(SciaRegs.SCIFFRX.bit.RXFFST == 0) { } // wait for empty state

       //
       // Get character
       //
       ReceivedChar = SciaRegs.SCIRXBUF.all;

       //
       // Echo character back
       //
       msg = "  You sent: \0";
       scia_msg(msg);
       scia_xmit(ReceivedChar);

       LoopCount++;
   }
}
void main(void)
{
	char s1[32];
	unsigned char flag = 0;

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

// Step 2. Initalize GPIO:
// This example function is found in the DSP2802x_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
// InitGpio();
// Setup only the GP I/O only for I2C functionality
   InitI2CGpio();

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

// Initialize 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 DSP2802x_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 DSP2802x_DefaultIsr.c.
// This function is found in DSP2802x_PieVect.c.
   InitPieVectTable();
#ifndef _DEBUG
   // Copy time critical code and Flash setup code to RAM
   // This includes the following ISR functions: EPwm1_timer_isr(), EPwm2_timer_isr()
   // EPwm3_timer_isr and and InitFlash();
   // The  RamfuncsLoadStart, RamfuncsLoadEnd, and RamfuncsRunStart
   // symbols are created by the linker. Refer to the F2808.cmd file.
      MemCopy(&RamfuncsLoadStart, &RamfuncsLoadEnd, &RamfuncsRunStart);

   // Call Flash Initialization to setup flash waitstates
   // This function must reside in RAM
      InitFlash();
#endif
// Step 4. Initialize all the Device Peripherals:
// This function is found in DSP2802x_InitPeripherals.c
// InitPeripherals(); // Not required for this example
   I2C_Init();		//use polling

// Step 5. Com port initial
   scia_echoback_init();
   scia_msg("-- Network Analyzer V0.03--\r\n");
   scia_msg("-- Build On: "__DATE__" "__TIME__"--\r\n");
   scia_msg("-- Start: 36.125KHz--\r\n");
   scia_msg("-- End:   100kHz   --\r\n");
   scia_msg("-- Step : 125Hz    --\r\n");
   scia_msg("-- Point: 511      --\r\n");

// Step 6. BSP init, LEDs & Button
   led_init();
   button_init();
   GPIOx_Init();
   //blink
   led_on(0x007f);
   led_off(0x007f);
   //clear GPIO0~GPIO3
   GPIOx_Clear(0x000f);

// Step 7. Initial AD5933
   ad5933_init();

   // Application loop
   for(;;)
   {
	   /*
	    * GPIO12 pressed routine
	    */
	   while( (0 == GpioDataRegs.GPADAT.bit.GPIO12)
			   && ( 0 == GpioDataRegs.GPADAT.bit.GPIO19 ) ){};
	   //GPIO12 pressed
	   if(1 == GpioDataRegs.GPADAT.bit.GPIO12)
	   {
		  //clear GPIO0~GPIO3
		  GPIOx_Clear(0x000f);
		  DELAY_US(100000);    // Delay 100ms , wait
		  sprintf(s1,"Temperature=%d\r\n", ad5993_GetTemperature());
		  scia_msg(s1);
		  ad5933_sweep( 0x0001 << 0, mag_ref);
		  //led indicator
		  led_off(0x007f);
		  if( diff_variance < AD5933_STANDARD_VARIANCE )
		  {
			  led_off(0x01 << 0);	//led0 off
			  led_off(0x01 << 6);	//led6 off
			  sprintf(s1,"Ref larger than standard.\r\n" );
			  scia_msg(s1);
		  }
		  else
		  {
			  led_on(0x01 << 0);	//led0 on
			  led_on(0x01 << 6);	//led6 on
			  sprintf(s1,"Ref less than standard.\r\n" );
			  scia_msg(s1);
		  }
		  scia_PrintLF();
	   }

	   /*
	    * GPIO19 pressed routine
	    */
	   if( 1 == GpioDataRegs.GPADAT.bit.GPIO19)
	   {
		   //clear flag
		   flag = 0;

		   //GROUP1--0b1010
		   //clear GPIO0~GPIO3
		   GPIOx_Clear(0x000f);
		   //set GPIO1 GPIO3
		   GPIOx_Set(0x000A);
		   // Delay 100ms , wait
		   DELAY_US(100000);
		   sprintf(s1,"Temperature=%d\r\n", ad5993_GetTemperature());
		   scia_msg(s1);
		   ad5933_sweep(0x0001 << 0, mag_ref0);;
		   //led0 indicator
		   led_off(0x007f);
		   if( diff_variance < AD5933_STANDARD_VARIANCE )
		   {
		   	  led_off(0x01 << 0);	//led0 off
			  sprintf(s1,"Group0 Ref larger than standard.\r\n" );
			  scia_msg(s1);
		   }
		   else
		   {
		   	  led_on(0x01 << 0);	//led0 on
		   	  flag++;
              sprintf(s1,"Group0 Ref less than standard.\r\n" );
			  scia_msg(s1);
		   }
		   scia_PrintLF();

		   //GROUP2--0b0101
		   //clear GPIO0~GPIO3
		   GPIOx_Clear(0x000f);
		   //set GPIO0 GPIO2
		   GPIOx_Set(0x0005);
		   // Delay 100ms , wait
		   DELAY_US(100000);
		   sprintf(s1,"Temperature=%d\r\n", ad5993_GetTemperature());
		   scia_msg(s1);
		   ad5933_sweep(0x0001 << 1, mag_ref1);
		   //led1 indicator
		   led_off(0x007f);
		   if( diff_variance < AD5933_STANDARD_VARIANCE )
		   {
		   	  led_off(0x01 << 1);	//led1 off
			  sprintf(s1,"Group1 Ref larger than standard.\r\n" );
			  scia_msg(s1);
		   }
		   else
		   {
		   	  led_on(0x01 << 1);	//led1 on
		   	  flag++;
			  sprintf(s1,"Group1 Ref less than standard.\r\n" );
			  scia_msg(s1);
		   }
		   scia_PrintLF();

		   //GROUP3--0b1111
		   //clear GPIO0~GPIO3
		   GPIOx_Clear(0x000f);
		   //set GPIO0~GPIO3
		   GPIOx_Set(0x000F);
		   // Delay 100ms , wait
		   DELAY_US(100000);
		   sprintf(s1,"Temperature=%d\r\n", ad5993_GetTemperature());
		   scia_msg(s1);
		   ad5933_sweep(0x0001 << 2, mag_ref2);
		   //led2 indicator
		   led_off(0x007f);
		   if( diff_variance < AD5933_STANDARD_VARIANCE )
		   {
		   	  led_off(0x01 << 2);	//led2 off
              sprintf(s1,"Group2 Ref larger than standard.\r\n" );
			  scia_msg(s1);
		   }
		   else
		   {
		   	  led_on(0x01 << 2);	//led2 on
		   	  flag++;
			  sprintf(s1,"Group2 Ref less than standard.\r\n" );
			  scia_msg(s1);
		   }
		   scia_PrintLF();

		   //GROUP4--0b1110
		   //clear GPIO0~GPIO3
		   GPIOx_Clear(0x000f);
		   //set GPIO1~GPIO3
		   GPIOx_Set(0x000E);
		   // Delay 100ms , wait
		   DELAY_US(100000);
		   sprintf(s1,"Temperature=%d\r\n", ad5993_GetTemperature());
		   scia_msg(s1);
		   ad5933_sweep(0x0001 << 3, mag_ref3);
		   //led3 indicator
		   led_off(0x007f);
		   if( diff_variance < AD5933_STANDARD_VARIANCE )
		   {
		   	  led_off(0x01 << 3);	//led3 off
  			  sprintf(s1,"Group3 Ref larger than standard.\r\n" );
			  scia_msg(s1);
		   }
		   else
		   {
		   	  led_on(0x01 << 3);	//led3 on
		   	  flag++;
			  sprintf(s1,"Group3 Ref less than standard.\r\n" );
			  scia_msg(s1);
		   }
		   scia_PrintLF();

		   //GROUP5--0b0110
		   //clear GPIO0~GPIO3
		   GPIOx_Clear(0x000f);
		   //set GPIO2~GPIO3
		   GPIOx_Set(0x0006);
		   // Delay 100ms , wait
		   DELAY_US(100000);
		   sprintf(s1,"Temperature=%d\r\n", ad5993_GetTemperature());
		   scia_msg(s1);
		   ad5933_sweep(0x0001 << 4, mag_ref4);
		   //led4 indicator
		   led_off(0x007f);
		   if( diff_variance < AD5933_STANDARD_VARIANCE )
		   {
		   	  led_off(0x01 << 4);	//led4 off
			  sprintf(s1,"Group4 Ref larger than standard.\r\n" );
			  scia_msg(s1);
		   }
		   else
		   {
		   	  led_on(0x01 << 4);	//led4 on
		   	  flag++;
			  sprintf(s1,"Group4 Ref less than standard.\r\n" );
			  scia_msg(s1);
		   }
		   scia_PrintLF();

		   //GROUP6--0b1101
		   //clear GPIO0~GPIO3
		   GPIOx_Clear(0x000f);
		   //set GPIO0 GPIO2 GPIO3
		   GPIOx_Set(0x000D);
		   // Delay 100ms , wait
		   DELAY_US(100000);
		   sprintf(s1,"Temperature=%d\r\n", ad5993_GetTemperature());
		   scia_msg(s1);
		   ad5933_sweep(0x0001 << 5, mag_ref5);
		   //led5 indicator
		   led_off(0x007f);
		   if( diff_variance < AD5933_STANDARD_VARIANCE )
		   {
		   	  led_off(0x01 << 5);	//led5 off
			  sprintf(s1,"Group5 Ref larger than standard.\r\n" );
			  scia_msg(s1);
		   }
		   else
		   {
		   	  led_on(0x01 << 5);	//led5 on
		   	  flag++;
			  sprintf(s1,"Group5 Ref less than standard.\r\n" );
			  scia_msg(s1);
		   }
		   scia_PrintLF();

		   if(6 == flag)
		   {
			   led_on(0x01 << 6);	//led6 on
 			   sprintf(s1,"total less than standard.\r\n" );
			   scia_msg(s1);
		   }
		   else
		   {
			   led_off(0x01 << 6);	//led6 off
			   sprintf(s1,"any larger than standard.\r\n" );
			   scia_msg(s1);
		   }

		   //the end
		   //clear GPIO0~GPIO3
		   GPIOx_Clear(0x000f);
	   }

   }   // end of for(;;)
}   // end of main
void PSRAMDataPass(void){
	msg = "PSRAM Data Area is OK!\r\0";
	scia_msg(msg);
}
void PSRAMDataFail(void){
	msg = "ERROR: PSRAM test failed!\r\0";
	scia_msg(msg);
	PSRAMError = 1;
}
void PSRAMTest(void){
	Uint32 PSRAMDataSize = PSRAMZoneSize;
	Uint32 i;

	msg = "\PSRAM Test:\r\0";
	scia_msg(msg);
//Clear operation
	//PSRAMClear - стирание PSRAM
	for(i=0;i < PSRAMDataSize;i++){
		PSRAM_Zone[i] = 0;
	}

//Write operations
	//ProgrammAreaWrite - запись 16 зон в PSRAM
	for(i=0;i < PSRAMDataSize;i++){
		PSRAM_Zone[i] = i;
	}

/*debug - —пециально измен¤ем значени¤ в пам¤ти дл¤ проверки правильности работы алгоритма Verify operations
	PSRAM_Zone[800]		= !PSRAM_Zone[800];
	PSRAM_Zone[1800] 	= !PSRAM_Zone[1800];
	PSRAM_Zone[2800] 	= !PSRAM_Zone[2800];
	PSRAM_Zone[3800] 	= !PSRAM_Zone[3800];
*/

//Verify operations
	//DataAreaVerify - проверка данных в PSRAM
	PassCount = 0;	// —брасываем счетчик успешных чтений
	FailCount = 0;	// —брасываем счетчик ошибочных чтений

	// ѕроверка
	for(i=0;i < PSRAMDataSize;i++){
		VerifyData = PSRAM_Zone[i];

		if(VerifyData != i){
			FailCount++;
			ZoneError = 1;
		}
		else{PassCount++;
			//! ¬ывод адреса, по которому обнаружена ошибка
		}
	}

	if(PassCount == PSRAMDataSize){
		PSRAMDataPass();
	}
	else{
		PSRAMDataFail();
	}
	if(PSRAMError == 1){
		msg = "PSRAM Test is finished with errors!\r\0";
		scia_msg(msg);
		msg = "===========================\r\0";
		scia_msg(msg);

	}
	else{
		msg = "PSRAM is OK!\r===========================\r\0";
		scia_msg(msg);
	}
}
Exemple #6
0
void doPwmMenu(void) {
	int dutyCycleMult = 2;
	int epwmFreq = 1500;
	int pwmStatus = 0;
	int breakOutOfLoop = 0;
        while(breakOutOfLoop == 0) {
                scia_msg(clearScreen);
                printMenu(pwmMenu, 6);
                read = scia_read();
                switch (read) {
                        case 0x30: //go back
                                breakOutOfLoop = 1;
                                break;
			case 0x31: //enable/disable pwm
				if (pwmStatus == 0) {
					epwmInit(epwmFreq, dutyCycleMult);
					pwmStatus = 1;
					pwmString2[25] = ' '; //[1) Toggle PWM:           OFF]
					pwmString2[26] = 'O';
					pwmString2[27] = 'N';
				}
				else {
					pwmStatus = 0;
					EALLOW;
					GpioCtrlRegs.GPADIR.all = 0xFFFF;
					GpioCtrlRegs.GPAMUX1.all = 0x0000;
  					GpioDataRegs.GPASET.all = 0xFFFF;
					EDIS;
					pwmString2[25] = 'O';
					pwmString2[26] = 'F';
					pwmString2[27] = 'F';
				}
				break;
			case 0x32:
				if (pwmStatus == 1) {
					char dutyCyclePrompt[] = "Enter the new duty cycle:";
					int i = 0;
					int mult = 10;
					int newDutyCycleMult = 0;
					char digits[] = "00";
					scia_msg(dutyCyclePrompt);
					while (i < 2) {
						read = scia_read();
						if (read < 0x3A || read > 0x2F) {
							newDutyCycleMult = newDutyCycleMult + (mult*(read-48));
							digits[i] = read;
							i++;
							mult = mult - 9;
						}
						else {
							scia_msg(nope);
							i = 0;
							break;
						}
					}
					if (i != 0) {
						dutyCycleMult = newDutyCycleMult;
						//"2) Duty Cycle:           50% ";
						pwmString3[25] = digits[0];
						pwmString3[26] = digits[1];
						i = ((epwmFreq/100)*dutyCycleMult);
						EPwm1Regs.CMPA.half.CMPA = (epwmFreq-i); // adjust duty for output EPWM1A
       						EPwm2Regs.CMPA.half.CMPA = (epwmFreq-i);
					}
				}
				else {
					scia_msg(pwm_is_kill);
					read = scia_read();
				}
				break;
			case 0x33:
				if (pwmStatus == 1) {

				}
				else {
					scia_msg(pwm_is_kill);
					read = scia_read();
				}
				break;
        }
	}
}
Exemple #7
0
void main(void) {
   memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize);
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
   InitSysCtrl();
   SysCtrlRegs.PCLKCR1.bit.EQEP2ENCLK = 0;    // eQEP2
   SysCtrlRegs.PCLKCR0.bit.SPIBENCLK = 0;     // SPI-B
   InitFlash();
// Step 2. Initalize GPIO: 
// InitGpio();  // Skipped; not needed
   InitEQep1Gpio();
   //InitEPwm1Gpio();
   //InitEPwm2Gpio();
   //InitEPwm3Gpio();
   InitECap1Gpio();
   InitECap2Gpio();
   InitECap3Gpio();
   EALLOW;
   GpioCtrlRegs.GPAMUX2.bit.GPIO16 = 1;
   GpioCtrlRegs.GPAMUX2.bit.GPIO17 = 1;
   GpioCtrlRegs.GPAMUX2.bit.GPIO18 = 1;
   GpioCtrlRegs.GPAMUX2.bit.GPIO19 = 1;
   GpioCtrlRegs.GPBMUX2.bit.GPIO50 = 0;
   GpioCtrlRegs.GPBMUX2.bit.GPIO51 = 0;
   GpioCtrlRegs.GPBDIR.bit.GPIO50 = 1;
   setupDrv8301();
   setupSpiA();
   //DRV8301_setupSpi();
   EDIS;
   DINT;
   InitPieCtrl(); // The default state is all PIE interrupts disabled and flags are cleared.
   
// Disable CPU interrupts and clear all CPU interrupt flags:
   IER = 0x0000;
   IFR = 0x0000;

// Initialize the PIE vector table with pointers to the shell ISRs.
// 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 F2806x_DefaultIsr.c.
   InitPieVectTable();

// Interrupts that are used in this example are re-mapped to our ISR functions
   EALLOW;
   PieVectTable.ECAP1_INT = &ecap1_isr;  // Group 4 PIE Peripheral Vectors
   PieVectTable.ECAP2_INT = &ecap2_isr;	 // ''
   PieVectTable.ECAP3_INT = &ecap3_isr;  // ''
   PieVectTable.ADCINT1 = &adc_isr; //
   //PieVectTable.SCIRXINTA = &scia_isr;
   EDIS;

// Step 4. Initialize all the Device Peripherals:
   InitECapRegs();
   scia_init();
   epwmInit(1,2,0); //10kHz, 50% duty, no chop
   InitAdc();
   AdcOffsetSelfCal();
   
// Step 5. Enable interrupts:
   IER |= M_INT1; // Enable CPU Interrupt 1 (connected to ADC)
   IER |= M_INT4; // Enable CPU INT4 which is connected to ECAP1-4 INT
   IER |= M_INT3; // Enable CPU INT1 which is connected to CPU-Timer 0:

   PieCtrlRegs.PIEIER1.bit.INTx1 = 1;	   // INT1.1 for ADC
   PieCtrlRegs.PIEIER4.bit.INTx1 = 1;      // INT4.1 for ecap1
   PieCtrlRegs.PIEIER4.bit.INTx2 = 1;      // INT4.2 for ecap2
   PieCtrlRegs.PIEIER4.bit.INTx3 = 1;      // INT4.3 for ecap3



// Enable global Interrupts and higher priority real-time debug events:
   EINT;   // Enable Global interrupt INTM
   ERTM;   // Enable Global realtime interrupt DBGM
   
   qep_data.init(&qep_data);
   int printData = 10001;
   readHallStateFlag = 1;
   char writeBuffer[80] = {0};
   int lastPhase = 0;
   gogo = 1;
   DRV8301_enable();
   DRV8301_setupSpi();
   i = 0;
	while(1) {
		qep_data.calc(&qep_data);
		if (readHallStateFlag)
			updateHallState();
		if ((lastPhase != Phase) && (printData)) {
			//\033[2J\033[0;0H\r
			sprintf(writeBuffer, "Hall State: %d\n\r", (int)Phase);
			scia_msg(writeBuffer);
		    sprintf(writeBuffer, "Velocity: %d rpm\n\r", qep_data.SpeedRpm_fr);
			scia_msg(writeBuffer);
			//sprintf(writeBuffer, "Mechanical Angle: %f degrees\n\r", qep_data.theta_mech*360);
			//scia_msg(writeBuffer);
			//sprintf(writeBuffer, "Electrical Angle: %f\n\r", qep_data.theta_elec);
			//scia_msg(writeBuffer);
			lastPhase = Phase;
		}
		//DRV8301_readData();
		//if (!Phase /*|| drv8301.fault || drv8301.OverTempShutdown || drv8301.OverTempWarning*/) {
			//while (!Phase || drv8301.fault || drv8301.OverTempShutdown || drv8301.OverTempWarning){
				//GpioDataRegs.GPBCLEAR.bit.GPIO50 = 1;
				///DELAY_US(32000);
				//DELAY_US(32000);
				//sprintf(writeBuffer, "\aERROR DECTECTED: \n\r Hall State: %d %d %d\n\r", CoilA, CoilB, CoilC);
				//scia_msg(writeBuffer);
				//sprintf(writeBuffer, "Fault Bit: %d\n\rOverTempShutdown: %d\n\rOverTempWarning%d\n\r", drv8301.fault, drv8301.OverTempShutdown, drv8301.OverTempWarning);
				//scia_msg(writeBuffer);
			//}
		//}
		//else {
		    //GpioDataRegs.GPBSET.bit.GPIO50 = 1;
		//}

	}

}