コード例 #1
0
ファイル: fy.c プロジェクト: AndTH/GCA
/*
 * get the new position from decoder
 */
void automode(void) {
  unsigned char choice1;
  unsigned char choice2;

  if( newPos != INPUT_ON ) {
    return;
  }

  do {
    waitMS(10);
    choice1 = dataIn >> 4;
    waitMS(10);
    choice2 = dataIn >> 4;
  } while( choice1 != choice2 );

  if( choice1 < MAX_TRACKS ) {
    choice = choice1;

    if( choice == 0 )
      choice = MAX_TRACKS / 2 + 1;

    waitMS(100);
    move();

  }

}
コード例 #2
0
ファイル: fy.c プロジェクト: AndTH/GCA
/*
 * flash the ledOK as confirmation
 */
void confirm(unsigned char cnt) {
  unsigned char n;

  for( n = 0; n < cnt; n++ ) {
    ledOK = LEDOK_ON;
    waitMS(250);
    ledOK = LEDOK_OFF;
    waitMS(250);
  };
}
コード例 #3
0
ファイル: fy.c プロジェクト: AndTH/GCA
/*
 * show current choice on the 7 segment display
 */
void updateDisplay(void) {
  unsigned int c = choice;
  unsigned int h = c / 10;
  unsigned int l = c % 10;

  display = h;
  displayH = 1;
  waitMS(20);
  displayH = 0;

  display = l;
  displayL = 1;
  waitMS(20);
  displayL = 0;
}
コード例 #4
0
ファイル: microStim.c プロジェクト: ryekelly/Ex
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
    int i;
    int boardNum = 0;
    int ULStat;
    int reward;
    LARGE_INTEGER frequency;        // ticks per second
    char ErrMsg[ERRSTRLEN];
    float duration;
    
    // get ticks per second
    QueryPerformanceFrequency(&frequency);

    if (nrhs > 0)
    {
        duration = *mxGetPr(prhs[0]);
    }
    else
    {
        duration = 10;
    }

    ULStat = cbDOut(boardNum, AUXPORT,8);
    waitMS(duration,frequency);
    ULStat = cbDOut(boardNum, AUXPORT,0);

    return;
}
コード例 #5
0
ファイル: fy.c プロジェクト: AndTH/GCA
void move(void) {
  unsigned char alive = 0;
  unsigned int diff = 0;
  unsigned int newpos = 0;

  stepnr = getPosition(curtrack);
  newpos = getPosition(choice);

  ledOK = LEDOK_OFF;

  if( stepnr == newpos ) {
    waitMS( 500 );
    ledOK = LEDOK_ON;
    return;
  }

  updateDisplay();
  power = POWER_ON;
  pulswidth = MAX_PULSWIDTH;

  while( stepnr != newpos ) {

    if( stepnr > newpos ) {
      diff = stepnr - newpos;
      stepnr--;
      oneStep(STEP_LEFT);
    }
    else if( stepnr < newpos ) {
      diff = newpos - stepnr;
      stepnr++;
      oneStep(STEP_RIGHT);
    }

    if( diff < 150 && pulswidth < MAX_PULSWIDTH ) {
      // slower
      pulswidth += (MAX_PULSWIDTH - pulswidth) / 150;
    }
    else if(pulswidth > MIN_PULSWIDTH) {
      // faster
      pulswidth -= (pulswidth - MIN_PULSWIDTH) / 150;
    }

    alive++;

    if( alive > 100 ) {
      //ledOK = !ledOK;
      alive = 0;
    }

  }; // end while


  if( !readByte(ADDR_KEEPPOWER) )
    power = POWER_OFF;

  curtrack = choice;
  ledOK = LEDOK_ON;

}
コード例 #6
0
int main(void) {

   volatile int count = 0;

//   printf("SystemBusClock  = %ld\n", SystemBusClock);
//   printf("SystemCoreClock = %ld\n", SystemCoreClock);

   // Real programs never die!
   for(;;) {
      count++;
//      printf("Count = %d\n", count);
      waitMS(100);
   }
   return 0;
}
コード例 #7
0
ファイル: fy.c プロジェクト: AndTH/GCA
/*
 * initialize all before processing
 */
void startup(void) {
  // configure the ports
  initIO();

  waitMS(10);

  // test display
  choice = 41;
  updateDisplay();
  waitMS(1000);

  choice   = MAX_TRACKS/2 +1;
  curtrack = choice;

  initPositions();
  updateDisplay();

  // get the permanent power setting from eeprom
  if( !readByte(ADDR_KEEPPOWER) )
    power = POWER_OFF;

  // signal started up
  confirm(4);
}
コード例 #8
0
ファイル: fy.c プロジェクト: AndTH/GCA
void initPositions(void) {
  waitMS(100);

  if( getPosition(choice) == 0 || getPosition(choice) == 0xFFFF ) {
    unsigned char i;

    for( i = 1; i <= MAX_TRACKS; i++ ) {
        // not initialized before
        savePosition(i, initpos);
    }
    // default power off step motor
    saveByte(ADDR_KEEPPOWER, KEEPPOWER_OFF);
  }
  // always set the calibration position
  savePosition(choice, initpos);
}
コード例 #9
0
ファイル: platform_config.c プロジェクト: achambers16/pixy
void clockInit(void)
{
	//uint32_t EMCClk;

	__disable_irq();
 	/* Set the XTAL oscillator frequency to 12MHz*/
	CGU_SetXTALOSC(__CRYSTAL);
	CGU_EnableEntity(CGU_CLKSRC_XTAL_OSC, ENABLE);
	CGU_EntityConnect(CGU_CLKSRC_XTAL_OSC, CGU_BASE_M3);
	
	/* Set PL160M 12*1 = 12 MHz */
	CGU_EntityConnect(CGU_CLKSRC_XTAL_OSC, CGU_CLKSRC_PLL1);
//	CGU_EntityConnect(CGU_CLKSRC_IRC, CGU_CLKSRC_PLL1);
	CGU_SetPLL1(1);
	CGU_EnableEntity(CGU_CLKSRC_PLL1, ENABLE);

	// setup CLKOUT
	CGU_EntityConnect(CGU_CLKSRC_PLL1, CGU_CLKSRC_IDIVB);
	CGU_EnableEntity(CGU_CLKSRC_IDIVB, ENABLE);
	CGU_SetDIV(CGU_CLKSRC_IDIVB, 12);  // 12 -> 6 pclks per cpu clk, 10 -> 5 pclks
	// set input for CLKOUT to IDIVB
	LPC_CGU->BASE_OUT_CLK &= ~0x0f000000;
	LPC_CGU->BASE_OUT_CLK |= 0x0d000000;

	/* Run SPIFI from PL160M, /2 */
	CGU_EntityConnect(CGU_CLKSRC_PLL1, CGU_CLKSRC_IDIVA);
	CGU_EnableEntity(CGU_CLKSRC_IDIVA, ENABLE);
	CGU_SetDIV(CGU_CLKSRC_IDIVA, 2);
	CGU_EntityConnect(CGU_CLKSRC_IDIVA, CGU_BASE_SPIFI);
	CGU_UpdateClock();

	LPC_CCU1->CLK_M4_EMCDIV_CFG |=    (1<<0) |  (1<<5);		// Turn on clock / 2
	LPC_CREG->CREG6 |= (1<<16);	// EMC divided by 2
    LPC_CCU1->CLK_M4_EMC_CFG |= (1<<0);		// Turn on clock

	/* Set PL160M @ 12*9=108 MHz */
	CGU_SetPLL1(9);

	/* Run base M3 clock from PL160M, no division */
	CGU_EntityConnect(CGU_CLKSRC_PLL1, CGU_BASE_M3);

	waitMS(10);

	/* Change the clock to 204 MHz */
	/* Set PL160M @ 12*15=180 MHz */
	CGU_SetPLL1(17);

	waitMS(10);

	CGU_UpdateClock();

	//EMCFlashInit();

	//vEMC_InitSRDRAM(SDRAM_BASE_ADDR, SDRAM_WIDTH, SDRAM_SIZE_MBITS, SDRAM_DATA_BUS_BITS, SDRAM_COL_ADDR_BITS);
	LPC_SCU->SFSP3_3 = 0xF3; /* high drive for SCLK */
	/* IO pins */
	LPC_SCU->SFSP3_4=LPC_SCU->SFSP3_5=LPC_SCU->SFSP3_6=LPC_SCU->SFSP3_7 = 0xD3;
	LPC_SCU->SFSP3_8 = 0x13; /* CS doesn't need feedback */

#if 0
	EMCClk = CGU_GetPCLKFrequency(CGU_PERIPHERAL_M3CORE)/2;
	if (spifi_init(&sobj, 9, S_RCVCLK | S_FULLCLK, EMCClk)) {
		if (spifi_init(&sobj, 9, S_RCVCLK | S_FULLCLK, EMCClk)) {
			while(1);
		}
	}
#endif
	__enable_irq();
//	SPIFI_Init();
}
コード例 #10
0
ファイル: fy.c プロジェクト: AndTH/GCA
/*
 * setup service to define the track positions
 * control remains in this function as long as the setup button is active
 */
void setup(void) {
  confirm(5);

  // start with position mid
  stepnr = initpos;
  choice = MAX_TRACKS / 2 + 1;
  updateDisplay();

  pulswidth = MAX_PULSWIDTH;
  power = POWER_ON;
  waitMS(100);

  curtrack = choice;

  while( buttonSetup == BUTTON_ON ) {
    waitMS(10);

    if( buttonRight == BUTTON_ON && buttonLeft == BUTTON_ON ) {
      saveByte( ADDR_KEEPPOWER, readByte(ADDR_KEEPPOWER) ? KEEPPOWER_OFF:KEEPPOWER_ON );
      confirm(3);
      while( buttonRight == BUTTON_ON && buttonLeft == BUTTON_ON );
    }

    while( stepnr < MAX_STEPS && buttonLeft == BUTTON_OFF && buttonRight == BUTTON_ON ) {
      // turn right; end position is not reached
      stepnr++;
      oneStep(STEP_RIGHT);
    };

    while( stepnr > 0 && buttonLeft == BUTTON_ON && buttonRight == BUTTON_OFF ) {
      // turn left; start position is not reached
      stepnr--;
      oneStep(STEP_LEFT);
    };

    // check if the buttonSave is pressed
    if( buttonSave == BUTTON_ON ) {
      // save the new position in eeprom
      savePosition( choice, stepnr);
      confirm(1);

      choice++;
      if( choice > MAX_TRACKS )
        choice = 1;
      curtrack = choice;
      updateDisplay();

      while( buttonSave == BUTTON_ON )
        waitMS(10);
    }

    // check if the buttonNext is pressed
    if( buttonNext == BUTTON_ON ) {
      confirm(1);

      choice++;
      if( choice > MAX_TRACKS )
        choice = 1;
      curtrack = choice;
      updateDisplay();

      while( buttonNext == BUTTON_ON )
        waitMS(10);
    }

  } // end while

  if( !readByte(ADDR_KEEPPOWER) )
    power = POWER_OFF;  /* power off step motor */
}
コード例 #11
0
ファイル: digCodeOrig.c プロジェクト: ryekelly/Ex
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
    int i;
    int boardNum = 0;
    int ULStat;
    int lowPort,highPort,strobePort;
    LARGE_INTEGER frequency;        // ticks per second
    double* doubleData;
    mxChar * charData;
    double waitTimeMS1,waitTimeMS2;

    /* These variables set the lag between bit flips (ms) */
    /* 20-50 uS is the range needed for the Ripple system */
    /* faster than that will likely cause dropped codes */
    waitTimeMS1 = 0.050; /* between setting bits and the strobe */
    waitTimeMS2 = 0.050; /* between setting the strobe to 1 and back to 0 */

    // get ticks per second
    QueryPerformanceFrequency(&frequency);

    lowPort = FIRSTPORTA;
    highPort = FIRSTPORTB;
    strobePort = FIRSTPORTC;

    ULStat = cbDConfigPort (boardNum, lowPort, DIGITALOUT);
    ULStat = cbDConfigPort (boardNum, highPort, DIGITALOUT);
    ULStat = cbDConfigPort (boardNum, strobePort, DIGITALOUT);

    if (nrhs > 0)
    {
        switch (mxGetClassID(prhs[0]))
        {
        case mxDOUBLE_CLASS:
            doubleData = mxGetPr(prhs[0]);

            for (i = 0; i < mxGetNumberOfElements(prhs[0]); i++)
            {
                ULStat = cbDOut(boardNum, lowPort, ((int)doubleData[i]) % 256);
                ULStat = cbDOut(boardNum, highPort, ((int)doubleData[i]) / 256);
                waitMS(waitTimeMS1,frequency);
                ULStat = cbDOut(boardNum, strobePort,1);
                waitMS(waitTimeMS2,frequency);
                ULStat = cbDOut(boardNum, strobePort,0);
            }
            break;
        case mxCHAR_CLASS:
            charData = (mxChar*)mxGetData(prhs[0]);

            for (i = 0; i < mxGetNumberOfElements(prhs[0]); i++)
            {
                ULStat = cbDOut(boardNum, lowPort, charData[i]);
                waitMS(waitTimeMS1,frequency);
                ULStat = cbDOut(boardNum, strobePort, 1);
                waitMS(waitTimeMS2,frequency);
                ULStat = cbDOut(boardNum, strobePort, 0);
            }
            break;
        default:
            mexPrintf("Sorry, this data type cannot be transmitted.\n");
            mexEvalString("drawnow;");
        }
    }

    return;
}