예제 #1
0
int do_autoshim(char *comstr, short maxpwr, short maxgain)
{
				/* save acq. registers on stack */
   int             rstatus;	/* return status of auto-lock */
   int		   stat_before_autshm;

   spinrate = getSpinSet();

   maxtime = 0;			/* no time limit on shimming initially */
   rstatus = 0;			/* initialize return status to OK */
   g_maxpwr = maxpwr;

/* establish some pointers for other routines later on */
   init_shim();
#ifdef XXX
   init_dac();
#endif

   DPRINT(0, "Auto Shim\n");
   stat_before_autshm = get_acqstate();
   update_acqstate(ACQ_SHIMMING);
   getstatblock();		/* tell host that console is shimming now */

   lk2kcf();
   auto_x(comstr,(int)maxgain);
   lk2kcs();	/* reset lock filter to 2kHz slow */
   if (!host_abort && !failAsserted)
   {
      update_acqstate(stat_before_autshm);
      getstatblock();		/* tell host that shimming is complete now */
   }
   DPRINT(0, "Auto Shim Exits\n");
   return (rstatus);
}
예제 #2
0
int     main(int argc, char** argv)
{
    u8          status;
    u8          prev_status;

    TRISDbits.TRISD8 = INPUT;               //Bouton INPUT
    TRISFbits.TRISF1 = OUTPUT;              //LED INPUT
    LATFbits.LATF1 = GND;                   //Etat initial = éteint

    INTCONbits.MVEC = TRUE;           //Multi-vector interrupt mode
    asm volatile("ei");               //Autorise les macro-ASM (interruptions)

    init_lcd();
    init_dac();
    init_oscil();
    init_MIDI();

    tab_create(tab);                        // Remplit le tableau avec les périodes

    while(PROCESS)
    {
        status = PORTDbits.RD8;
        if (!status && prev_status)
        {                                   // Appuyer sur le bouton change la fréquence
            if (cursor == 100)
                cursor = 10000;
            else
                cursor /= 10;
        }
        prev_status = status;
        WDTCONbits.WDTCLR = TRUE;       //Clear Watchdog
    }
}
예제 #3
0
파일: sound.cpp 프로젝트: Weanuts/ersky9x
void start_sound()
{
	
	start_dactimer() ;
	init_dac() ;
	init_twi() ;
	setVolume( 2 ) ;

#ifdef REVB
#ifndef REVX	
	register Pio *pioptr ;
	pioptr = PIOA ;
	pioptr->PIO_CODR = 0x02000000L ;	// Set bit A25 OFF
	pioptr->PIO_PER = 0x02000000L ;		// Enable bit A25 (Stock buzzer)
	pioptr->PIO_OER = 0x02000000L ;		// Set bit A25 as output
#endif
#else
	register Pio *pioptr ;
	pioptr = PIOA ;
	pioptr->PIO_CODR = 0x00010000L ;	// Set bit A16 OFF
	pioptr->PIO_PER = 0x00010000L ;		// Enable bit A16 (Stock buzzer)
	pioptr->PIO_OER = 0x00010000L ;		// Set bit A16 as output
#endif
#ifdef REVX	
	configure_pins( PIO_PC26, PIN_ENABLE | PIN_LOW | PIN_OUTPUT | PIN_PORTC | PIN_NO_PULLUP ) ;
	audioOn() ;
#endif
}
예제 #4
0
파일: sound.cpp 프로젝트: chrisshum128/mbtx
void start_sound()
{
	start_dactimer() ;
	init_dac() ;
	// TODO - for volume, shared with EEPROM?
	//init_twi() ;
}
예제 #5
0
int main(int argc, char** argv) {

//    BMXPUPBA = BMXPFMSZ - 0x4000;

//  sizeof(presets) = 17820 bits
//  0x5000 = 20480

    INTCONbits.MVEC = TRUE;           //Multi-vector interrupt mode
    asm volatile("ei");               //Autorise les macro-ASM (interruptions)

//    memcpy(&presets, flash_adress, sizeof(presets));

    init_Menus();
    init_pins();
    init_lcd();
    init_preset();
    create_tab_env();
    create_tab_frequenz();
    create_tab_period();
    init_MIDI();
//    init_pwm();
    init_dac();
    update_menu();

    while (42)
    {
        boutons();
        processEncodeur();
        WDTCONbits.WDTCLR = 1;
    }
    return (0);
}
예제 #6
0
void    init(void)
{
    INTCONbits.MVEC = TRUE;           //Multi-vector interrupt mode
    asm volatile("ei");               //Autorise les macro-ASM (interruptions)

    create_tab_frequenz();
    create_tab_period();                        // Remplit le tableau avec les périodes
    init_lcd();
    init_MIDI();
    init_dac();
    init_preset();
}
예제 #7
0
파일: main.c 프로젝트: Azizou/stm32f0_devel
void main(void)
{
  uint16_t pos = 0;
  uint16_t i;
  init_dac();
  for(;;) {
    DAC->DHR12R1 = table_mountain[pos++];
                for (uint32_t i = 0; i < 180; i++);
    if (pos >= ( sizeof(table_mountain) / sizeof(table_mountain[0]) )) {
      pos = 0;
    }
  }
}
예제 #8
0
void main(void)
{
    uint32_t i;
    RCC->AHBENR |= RCC_AHBENR_GPIOBEN;
    GPIOB->MODER = 0x00005555;
    GPIOB->ODR = 0x0000;
    NVIC_EnableIRQ(15);
    init_dac();
    init_dma();
    init_tim2();
    for(;;) {
        GPIOB->ODR = DMA1->ISR;
    }
}
예제 #9
0
/**
 * \brief Run WM8731 module unit tests.
 */
int main(void)
{
	const usart_serial_options_t uart_serial_options = {
		.baudrate = CONF_TEST_BAUDRATE,
		.paritytype = CONF_TEST_PARITY
	};

	/* Initialize the system. */
	sysclk_init();
	board_init();
#ifdef BOARD_AT24C_TWI_INSTANCE
	/* reset EEPROM state to release TWI */
	at24cxx_reset();
#endif

	/* Configure console UART. */
	sysclk_enable_peripheral_clock(CONSOLE_UART_ID);
	stdio_serial_init(CONF_TEST_UART, &uart_serial_options);

	/* Initial the WM8731 to DAC */
	init_dac();

	/* Initial the ssc interface */
	init_ssc();

	/* Configure DMA */
	init_dma();

	/* Define all the test cases */
	DEFINE_TEST_CASE(wm8731_transfer_test, NULL, run_wm8731_transfer_test,
			NULL, "WM8731 transfer test.");

	/* Put test case addresses in an array */
	DEFINE_TEST_ARRAY(wm8731_tests) = {
		&wm8731_transfer_test,
	};

	/* Define the test suite */
	DEFINE_TEST_SUITE(wm8731_suite, wm8731_tests,
			"SAM WM8731 module test suite");

	/* Run all tests in the test suite */
	test_suite_run(&wm8731_suite);

	while (1) {
		/* Busy-wait forever */
	}
}
예제 #10
0
파일: main.c 프로젝트: kehribar/xmegaE5
int main()
{
	uint32_t pc = 0;
	initClock_32Mhz();
	init_dac();	
	init_uart();

	while(1)
	{
		pc += increment;

		DACA.CH0DATAH = lut[pc >> 24];

		while(!(DACA.STATUS & (DAC_CH1DRE_bm)));
	}
}
예제 #11
0
int main(int argc, char** argv) {

    //---------- FLASH ------------
    // MCHP_FLASH_ENABLE            non fonctionnel
    // MCHPCONbits.FAEN = 1;        non fonctionnel
    // while(MCHPCONbits.FCBUSY);   non fonctionnel

    // NVMCONbits.WR = 1;
    // NVMCONbits.NVMOP = ?;

    init_pins();
    init_preset();
    init_Menus();
    INTCONbits.MVEC = TRUE;           //Multi-vector interrupt mode
    asm volatile("ei");               //Autorise les macro-ASM (interruptions)
    init_lcd();
    create_tab_env();
    create_tab_frequenz();
    create_tab_period();
    init_MIDI();
    init_pwm();

    init_dac();
/*    PMCON = 0;
    PMAEN = 0;
    PMMODE = 0;
    PMADDR = 0;
    PMSTAT = 0;
    PMDIN = 0;
    PMDOUT = 0;
    AD1CON1 = 0;
    AD1CON2 = 0;
    AD1CON3 = 0;
    AD1CHS = 0;
    AD1CSSL = 0;
    U2STA = 0;
    U2MODE = 0;*/
    update_menu();

    while (42) {
        boutons();
        processEncodeur();
    }
    return (0);
}
예제 #12
0
파일: mirror.c 프로젝트: sean-duffy/empr
int main(void) {
    serial_init();
    init_adc();
    init_dac();
    //SysTick_Config(SystemCoreClock / 6);
    
    uint16_t adc_value;

    while(1) {
        // Read analogue value
        ADC_StartCmd(LPC_ADC,ADC_START_NOW);
        // Wait conversion complete
        while (!(ADC_ChannelGetStatus(LPC_ADC,ADC_CHANNEL_1,ADC_DATA_DONE)));

        adc_value = ADC_ChannelGetData(LPC_ADC,ADC_CHANNEL_1);
        DAC_UpdateValue(LPC_DAC, adc_value / 4);
    }

    return 0;
}
예제 #13
0
파일: main.c 프로젝트: atikbif/Relkon7
// вспомогательная служебная задача
static void prvFlashTask( void *pvParameters )
{
    static unsigned short s_tmr=0;
	static float adc_res = 0;
	static unsigned short adc_max[8];
	static unsigned short adc_min[8];
	static unsigned short cur_adc = 0;

    unsigned char tmp;
    init_adc();init_dac();		// инициализация ацп и цап
    update_code();				// обновление кодового слова в FRAM
    FLLastExecutionTime = xTaskGetTickCount();
    for( ;; )
	{

    	// фильтр АЦП
    	if(emu_mode==0){
			for(tmp=0;tmp<8;tmp++) {
				cur_adc = get_adc(tmp);
				if(s_tmr % 8 == 0) {adc_min[tmp]=adc_max[tmp]=cur_adc;}
				adc_sum[tmp]+=cur_adc;
				if(cur_adc<adc_min[tmp]) adc_min[tmp] = cur_adc;
				if(cur_adc>adc_max[tmp]) adc_max[tmp] = cur_adc;
			}
			s_tmr++;
			if(s_tmr % 8 == 0) {
				for(tmp=0;tmp<8;tmp++) {
					adc_res=(adc_sum[tmp]-adc_min[tmp]-adc_max[tmp])*16.0/(8-2)*adc_coeff+0.5;
					adc_sum[tmp]=0;
					if(adc_res>65535) adc_res=65535;_Sys_ADC[tmp]=adc_res;
				}
			}
		}
    	
    	if((s_tmr%64)==0) {get_time();toggle_led();}	// обновление текущего времени и мигание светодиода
        vTaskDelayUntil( &FLLastExecutionTime, mainFLASH_DELAY );
	}
}
int main(void)
{
        uint8_t sensor; // Stores analog readings for transmission
        int i; // multipurpose counter
        char choice = 0; // Holds the top-level menu character
//      int red = 0;     // For the red LED intensity
//      int green = 0;   // For the green LED intensity
//      int blue = 0;    // For the blue LED intensity
        uint8_t exit = 0;    // Flag that gets set if we need to go back to idle mode.
        unsigned int temph=0;  // Temporary variable (typically stores high byte of a 16-bit int )
        unsigned int templ=0;  // Temporary variable (typically stores low byte of a 16-bit int)
        uint8_t location = 0;  // Holds the EEPROM location of a stored IR signal
//      unsigned int frequency = 0; // For PWM control - PWM frequency, also used to set buzzer frequency
//        int amplitude;
        int channel;
        unsigned int duty;      // For PWM control - PWM duty cycle

        int baud;   // Baud rate selection for auxiliary UART
        char scale;  // For auxiliary UART

        long int time_out=0; // Counter which counts to a preset level corresponding to roughly 1 minute

        // Initialize system
        
        // Turn off JTAG to save a bit of battery life
        CCP = CCP_IOREG_gc;    
        MCU.MCUCR = 1;

        init_clock();

        init_led();

        init_adc();

        init_ir();

        init_BT();

        init_dac();

        init_buzzer();

        initAccel();

        init_aux_uart(131, -3); // Set the auxiliary uart to 115200 8n1

        EEPROM_DisableMapping();

        // Enable global interrupts
        sei();

        // Do the following indefinitely
        while(1) {
            // Turn off LED
                set_led(0,0,0);

                // Reset flags (in case this isn't the first time through the loop)
                exit = 0;
                choice = 0;
                time_out = 0;
                stop_ir_timer();

                // Sing a BL song in idle mode so you can be found. Stop as soon as you get a *
                while(choice != 42) {
                        bt_putchar('B');
                        bt_putchar('L');
                        if (USART_RXBufferData_Available(&BT_data)) {
                                choice = USART_RXBuffer_GetByte(&BT_data);
                                if (choice == 128) {
                                    // Something is trying to connect directly to an iRobot
                                    set_aux_baud_rate( ROOMBA_UART_SETTINGS ); // depends on model
                                    aux_putchar( 128); // pass through to iRobot
                                    serial_bridge(); // currently never returns
                                }
                                else if (choice == 0) {
                                    // Something may be trying to connect directly to a MindFlex headset
                                    set_aux_baud_rate( 135, -2); // 57600
                                    aux_putchar( 0); // pass through to headset
                                    serial_bridge(); // currently never returns;
                                }
                                else {
                                    bt_putchar(choice);
                                }
                        }
                        if (choice != 42)
                            _delay_ms(500);
                }

                // Active part of the program - listens for commands and responds as necessary
                while(exit == 0) {
                        // Checks if we haven't heard anything for a long time, in which case we exit loop and go back to idle mode
                        time_out++;
                        // Corresponds to roughly 60 seconds
                        if(time_out > 33840000) {
                                exit = 1;
                        }

                        // Check for a command character
                        if (USART_RXBufferData_Available(&BT_data)) {
                                choice = USART_RXBuffer_GetByte(&BT_data);
                        }
                        else {
                                choice = 0;
                        }
                        // If it exists, act on command
                        if(choice != 0) {
                                // Reset the time out
                                time_out = 0;
                                // Return the command so the host knows we got it
                                bt_putchar(choice);

                                // Giant switch statement to decide what to do with the command
                                switch(choice) {
                                        // Return the currect accelerometer data - X, Y, Z, and status (contains tapped and shaken bits)
                                        case 'A':
                                                updateAccel();
                                                bt_putchar(_acc.x);
                                                bt_putchar(_acc.y);
                                                bt_putchar(_acc.z);
                                                bt_putchar(_acc.status);
                                                break;
                                        // Set the buzzer
                                        case 'B': // frequency_divider(2)
                                                if (get_arguments(2)) {
                                                    set_buzzer(GET_16BIT_ARGUMENT(0));
                                                }
                                                break;
                                        // Turn off the buzzer
                                        case 'b':
                                                turn_off_buzzer();
                                                break;
                                        // Returns the value of the light sensor
                                        case 'L':
                                                sensor = read_analog(LIGHT, 0);
                                                bt_putchar(sensor);
                                                break;
                                        // Returns the Xmegas internal temperature read - this is undocumented because the value returned is very erratic
                                        case 'T':
                                                sensor = read_internal_temperature();
                                                bt_putchar(sensor);
                                                break;
                                        // Returns the battery voltage
                                        case 'V':
                                                sensor = read_analog(BATT_VOLT, 0);
                                                bt_putchar(sensor);
                                                break;
                                        // Differential ADC mode
                                        case 'D': // active(1) numgainstages(1)
                                                if (get_arguments(2)) {
                                                    if (arguments[0] == '0') {
                                                        adcResolution = ADC_RESOLUTION_8BIT_gc;
                                                        adcConvMode = ADC_ConvMode_Unsigned;
                                                        adcGain = ADC_DRIVER_CH_GAIN_NONE;
                                                        adcInputMode = ADC_CH_INPUTMODE_SINGLEENDED_gc;
                                                        init_adc();
                                                    }
                                                    else if (arguments[0] == '1') {
                                                        adcResolution = ADC_RESOLUTION_12BIT_gc;
                                                        adcConvMode = ADC_ConvMode_Signed;

                                                        if (arguments[1] >= '1' && arguments[1] <= '6') { // number of gain stages
                                                            adcGain = (arguments[1] - '0') << ADC_CH_GAINFAC_gp;
                                                            adcInputMode = ADC_CH_INPUTMODE_DIFFWGAIN_gc;
                                                            init_adc();
                                                        }
                                                        else if (arguments[1] == '0') {
                                                            adcGain = ADC_DRIVER_CH_GAIN_NONE;
                                                            adcInputMode = ADC_CH_INPUTMODE_DIFF_gc;
                                                            init_adc();
                                                        }
                                                        else {
                                                            err();
                                                        }
                                                    }
                                                    else {
                                                        err();
                                                    }
                                                }
                                                break;
                                        // Returns the readings on all six ADC ports
                                        case 'X':
                                                for (i=0; i<6; i++) {
                                                    sensor = read_analog(pgm_read_byte_near(muxPosPins+i), 0);
                                                    bt_putchar(sensor);
                                                }
                                                break;
                                        // Returns differential measurement on pair of ADC ports
                                        // Assumes we are in differential mode
                                        case 'x':
                                                if (get_arguments(2)) {
                                                    i = read_differential(arguments[0], arguments[1]);
                                                    bt_putchar(0xFF&(i >> 8));
                                                    bt_putchar(0xFF&i);
                                                }
                                                break;

                                        case 'e': // this is a bit of testing code, which will eventually be changed
                                                  // do not rely on it
                                                if (get_arguments(2)) {
                                                  char a1 = arguments[0];
                                                  char a2 = arguments[1];
                                                  while(1) {
                                                      _delay_ms(2);
                                                      i = read_differential(a1, a2);
                                                      itoa((i<<4)>>4, (char*)arguments, 10);
                                                      for (i=0; arguments[i]; i++)
                                                          bt_putchar(arguments[i]);
                                                      bt_putchar('\r');
                                                      bt_putchar('\n');
                                                  }
                                                }
                                                break;

                                        // Sets the full-color LED
                                        case 'O': // red(1) green(1) blue(1);
                                                if (get_arguments(3)) {
                                                    set_led(arguments[0], arguments[1], arguments[2]);
                                                }
                                                break;
                                        // Switches serial between irDA and standard serial
                                        // Currently, this works over the same port numbers as
                                        // standard serial, instead of using the IR receiver
                                        // and IR LED.  This may change when I get the IR receiver
                                        // and LED working reliably.
                                        case 'J':
                                                temph = bt_getchar_timeout_echo();
                                                if(/*temph == 256 || */ temph < '0' || temph > '1') {
                                                        err();
                                                        break;
                                                }
                                                set_irda_mode(temph - '0');
                                                break;

                                        // Sets up the IR transmitter with signal characteristics
                                        case 'I':
                                                init_ir();
                                                temph = bt_getchar_timeout_echo();
                                                if(temph == 256) {
                                                        err();
                                                        break;
                                                }
                                                templ = bt_getchar_timeout_echo();
                                                if(templ == 256) {
                                                        err();
                                                        break;
                                                }
                                                // Set the frequency of the IR carrier
                                                robotData.frequency = ((temph)<<8) + templ;
                                                set_ir_carrier(robotData.frequency);
                                                templ = bt_getchar_timeout_echo();
                                                if(templ == 256) {
                                                        err();
                                                        break;
                                                }
                                                else {
                                                // Set the length of the start up pulses
                                                        robotData.startUpPulseLength = templ;
                                                }
                                                if(robotData.startUpPulseLength > 16) {
                                                        err();
                                                        break;
                                                }

                                                // Read in the start up pulse timing data
                                                for(i=0; i < robotData.startUpPulseLength; i++) {
                                                        temph = bt_getchar_timeout_echo();
                                                        if(temph == 256) {
                                                                err();
                                                                break;
                                                        }
                                                        templ = bt_getchar_timeout_echo();
                                                        if(templ == 256) {
                                                                err();
                                                                break;
                                                        }
                                                        robotData.startUpPulse[i] = ((temph)<<8) + templ;
                                                }
                                                if(temph == 256 || templ == 256) {
                                                        break;
                                                }
                                                templ = bt_getchar_timeout_echo();
                                                if(templ == 256) {
                                                        err();
                                                        break;
                                                }
                                                // Set the bit encoding to one of four pre-determined settings (see protocol instructions for more information)
                                                robotData.bitEncoding = templ;

                                                templ = bt_getchar_timeout_echo();
                                                if(templ == 256) {
                                                        err();
                                                        break;
                                                }
                                                // Set the number of bits (and bytes) contained in an IR command
                                                robotData.numBits = templ;
                                                robotData.numBytes = (robotData.numBits-1)/8 + 1;
                                                temph = bt_getchar_timeout_echo();
                                                if(temph == 256) {
                                                        err();
                                                        break;
                                                }
                                                templ = bt_getchar_timeout_echo();
                                                if(templ == 256) {
                                                        err();
                                                        break;
                                                }
                                                // Set timing data for a high bit
                                                robotData.highBitTime = ((temph)<<8) + templ;
                                                temph = bt_getchar_timeout_echo();
                                                if(temph == 256) {
                                                        err();
                                                        break;
                                                }
                                                templ = bt_getchar_timeout_echo();
                                                if(temph == 256) {
                                                        err();
                                                        break;
                                                }
                                                // Set timing data for a low bit
                                                robotData.lowBitTime = ((temph)<<8) + templ;
                                                temph = bt_getchar_timeout_echo();
                                                if(temph == 256) {
                                                        err();
                                                        break;
                                                }
                                                templ = bt_getchar_timeout_echo();
                                                if(templ == 256) {
                                                        err();
                                                        break;
                                                }
                                                // Set timing data for on or off
                                                robotData.offTime = ((temph)<<8) + templ;
                                                break;
                                        // Transmit an IR signal according to the previously determined configuration
                                        case 'i':
                                                init_ir();
                                                // Get the signal data as one or more bytes
                                                for(i = 0; i < robotData.numBytes; i++) {
                                                        templ = bt_getchar_timeout_echo();
                                                        if(templ == 256) {
                                                                err();
                                                                break;
                                                        }
                                                        robotData.irBytes[i] = templ;
                                                }
                                                if(templ == 256) {
                                                        break;
                                                }
                                                temph = bt_getchar_timeout_echo();
                                                if(temph == 256) {
                                                        err();
                                                        break;
                                                }
                                                templ = bt_getchar_timeout_echo();
                                                if(templ == 256) {
                                                        err();
                                                        break;
                                                }
                                                // Determine if the signal is repeated or not, and if so, with what frequency
                                                robotData.repeatTime = ((temph)<<8) + templ;
                                                if(robotData.repeatTime != 0) {
                                                        robotData.repeatFlag = 1;
                                                }
                                                else {
                                                        robotData.repeatFlag = 0;
                                                }
                                                // Startup timer interrupts
                                                start_ir_timer();
                                                break;
                                        // Turn off any repeating IR signal
                                        case '!':
                                                robotData.repeatFlag = 0;
                                                stop_ir_timer();
                                                break;
                                        // Capture a signal from the IR receiver
                                        case 'R':
                                                init_ir_read();
                                                while(ir_read_flag!=0);
                                                break;
                                        // Store the captured signal in an EEPROM location
                                        case 'S':
                                                location = bt_getchar_timeout_echo()-48; // Subtracting 48 converts from ASCII to numeric numbers
                                                if((location >= 0) && (location < 5) && (signal_count > 4)) {
                                                        write_data_to_eeprom(location);
                                                }
                                                else {
                                                        err();
                                                }
                                                break;
                                        // Receive a raw IR signal over bluetooth and transmit it with the IR LED
                                        case 's':
                                                if(read_data_from_serial()) {
                                                        temph = bt_getchar_timeout_echo();
                                                        if(temph == 256) {
                                                                err();
                                                                break;
                                                        }
                                                        templ = bt_getchar_timeout_echo();
                                                        if(templ == 256) {
                                                                err();
                                                                break;
                                                        }
                                                        // Set if the signal should repeat and if so, with what frequency
                                                        robotData.repeatTime = ((temph)<<8) + templ;
                                                        if(robotData.repeatTime != 0) {
                                                                robotData.repeatFlag = 1;
                                                        }
                                                        else {
                                                                robotData.repeatFlag = 0;
                                                        }
                                                        // Set frequency to 38KHz, since raw signals must have come from the receiver at some point
                                                        robotData.frequency = 0x0349;
                                                        robotData.startUpPulseLength = 0;
                                                        robotData.bitEncoding = 0x04;
                                                        start_ir_timer();
                                                }
                                                else {
                                                                err();
                                                                break;
                                                }
                                                break;
                                        // Get a stored signal from an EEPROM location and transmit it over the IR LED (and repeat as desired)
                                        case 'G':
                                                location = bt_getchar_timeout_echo()-48;
                                                if(location >= 0 && location < 5) {
                                                        temph = bt_getchar_timeout_echo();
                                                        if(temph == 256) {
                                                                err();
                                                                break;
                                                        }
                                                        templ = bt_getchar_timeout_echo();
                                                        if(templ == 256) {
                                                                err();
                                                                break;
                                                        }
                                                        robotData.repeatTime = ((temph)<<8) + templ;
                                                        if(robotData.repeatTime != 0) {
                                                                robotData.repeatFlag = 1;
                                                        }
                                                        else {
                                                                robotData.repeatFlag = 0;
                                                        }
                                                        read_data_from_eeprom(location);
                                                        robotData.frequency = 0x0349;
                                                        robotData.startUpPulseLength = 0;
                                                        robotData.bitEncoding = 0x04;
                                                        start_ir_timer();
                                                }
                                                else {
                                                        err();
                                                }
                                                break;
                                        // Get a stored signal from EEPROM and print it over bluetooth to the host
                                        case 'g':
                                                location = bt_getchar_timeout_echo()-48;
                                                if(location >= 0 && location < 5) {
                                                        print_data_from_eeprom(location);
                                                }
                                                else {
                                                        err();
                                                }
                                                break;
                                                // Output on digital I/O
                                        case '>':
                                                // Set port
                                                temph = bt_getchar_timeout_echo();
                                                if(temph == 256) {
                                                        err();
                                                        break;
                                                }
                                                // Get value
                                                templ = bt_getchar_timeout_echo();
                                                if(templ == 256) {
                                                        err();
                                                        break;
                                                }
                                                set_output(temph, (templ-48));
                                                break;
                                                // Input on digital I/O
                                        case '<':
                                                // Get port
                                                temph = bt_getchar_timeout_echo();
                                                if(temph == 256) {
                                                        err();
                                                        break;
                                                }
                                                // Get value (1 or 0)
                                                templ = read_input(temph)+48;
                                                bt_putchar(templ);
                                                break;
                                        // Configure PWM frequency
                                        case 'P':
                                                if (get_arguments(2))
                                                    pwm_frequency = GET_16BIT_ARGUMENT(0);
                                                break;
                                        // Set PWM duty cycle for a specific port
                                        case 'p':
                                                if (get_arguments(3)) {
                                                    set_pwm();
                                                    duty = GET_16BIT_ARGUMENT(1);
                                                    if (arguments[0] == '0')
                                                        set_pwm0(duty);
                                                    else if (arguments[1] == '1')
                                                        set_pwm1(duty);
                                                    // could add else err();, but original firmware doesn't do this
                                                }
                                                break;
                                        // Set DAC voltage on one of the two DAC ports
                                        case 'd':
                                                temph = bt_getchar_timeout_echo();
                                                if(temph == 256) {
                                                        err();
                                                        break;
                                                }
                                                        if(temph == '0') {
                                                                temph = bt_getchar_timeout_echo();
                                                                if(temph == 256) {
                                                                        err();
                                                                        break;
                                                                }
                                                                else {
                                                                        set_dac0(temph);
                                                                }
                                                        }
                                                        else if(temph == '1') {
                                                                temph = bt_getchar_timeout_echo();
                                                                if(temph == 256) {
                                                                        err();
                                                                        break;
                                                                }
                                                                else {
                                                                        set_dac1(temph);
                                                                }
                                                        }
                                                break;
                                                // Go back to idle mode so you can be found again. Should be sent at end of host program.
                                        case 'Q':
                                                exit = 1;
                                                break;
                                                // Human-readable uart speed setting
                                        case 'u':
                                                temph = bt_getchar_timeout_echo();
                                                if(temph == 256) {
                                                        err();
                                                        break;
                                                }
                                                templ = bt_getchar_timeout_echo();
                                                if(templ == 256) {
                                                        err();
                                                        break;
                                                }
                                                baud = ((temph)<<8) + templ;
                                                switch(baud) {
                                                    case ('1'<<8) + '2': // 1200
                                                        baud = 6663;
                                                        scale = -2;
                                                        break;
                                                    case ('4'<<8) + '8': // 4800
                                                        baud = 3325;
                                                        scale = -3;
                                                        break;
                                                    case ('9'<<8) + '6': // 9600
                                                        baud = 829;
                                                        scale = -2;
                                                        break;
                                                    case ('1'<<8) + '9': // 19200
                                                        baud = 825;
                                                        scale = -3;
                                                        break;
                                                    case ('3'<<8) + '8': // 38400
                                                        baud = 204;
                                                        scale = -2;
                                                        break;
                                                    case ('5'<<8) + '7': // 57600
                                                        baud = 135;
                                                        scale = -2;
                                                        break;
                                                    case ('1'<<8) + '1': // 115200
                                                        baud = 131;
                                                        scale = -3;
                                                        break;
                                                    default:
                                                        err();
                                                        goto BAUD_DONE;
                                                }
                                                set_aux_baud_rate(baud, scale);

                                                BAUD_DONE:
                                                break;

                                        // Configures the baud rate of the auxiliary UART
                                        case 'C': // baud(2) scale(1)
                                          // e.g., 9600 = C\x03\x3D\xFE
                                                if (! get_arguments(3))
                                                    break;

                                                bt_putchar(arguments[2]); // duplicate buggy behavior from official firmware; delete if unwanted

                                                set_aux_baud_rate( GET_16BIT_ARGUMENT(0), arguments[2]);
                                                break;
                                        // BT-serial high speed bridge mode
                                        case 'Z':
                                                serial_bridge();
                                                break;
                                        case 'w': // channel(1) type(1) duty(1) amplitude(1) frequency(3)
                                                  // w0s\x20\xFF\x02\x00\x00
                                                if (!get_arguments(7))
                                                     break;
                                                if (arguments[0] < '0' || arguments[0] > '1' || arguments[2] > WAVEFORM_SIZE) {
                                                     err();
                                                     break;
                                                }

                                                play_wave_dac(arguments[0]-'0', (char)arguments[1], arguments[2], arguments[3], get_24bit_argument(4));

                                                break;
                                        case 'W': // channel(1) frequency(3) length(1) data(length)
                                                if (!get_arguments(5))
                                                    break;
                                                if (arguments[0] < '0' || arguments[0] > '1' || arguments[4] > WAVEFORM_SIZE || arguments[4] == 0 ) {
                                                        err();
                                                        break;
                                                }
                                                channel = arguments[0] - '0';
                                                if (bt_to_buffer(waveform[channel], arguments[4])) {
                                                     disable_waveform(channel);
                                                     play_arb_wave(channel, waveform[channel], arguments[4], get_24bit_argument(1));
                                                }
                                                break;

                                        case '@':
                                                channel = bt_getchar_timeout_echo();
                                                if (channel == '0')
                                                    disable_waveform0();
                                                else if (channel == '1')
                                                    disable_waveform1();
                                                else
                                                    err();
                                                break;
                                        case 'r':
                                                i = USART_RXBufferData_AvailableCount(&AUX_data);
                                                bt_putchar((uint8_t)(i+1));
                                                while(i-- > 0) {
                                                        bt_putchar(USART_RXBuffer_GetByte(&AUX_data));
                                                }
                                                break;
                                        // Transmit a stream of characters from bluetooth to auxiliary serial
                                        case 't':
                                                temph= bt_getchar_timeout_echo();
                                                if (temph == 256) {
                                                    err();
                                                    break;
                                                }

                                                for(; temph>0; temph--) {
                                                        templ= bt_getchar_timeout_echo();

                                                        if(templ == 256) {
                                                                err();
                                                                break;
                                                        }
                                                        else {
                                                                aux_putchar( templ);
                                                        }
                                                }
                                                break;
                                        default:
                                                break;
                                }
                        }
예제 #15
0
파일: main.c 프로젝트: bobeber/capmeter
/*
 * Our main
 */
int main(void)
{    
    /* Check if the firmware asked to start the bootloader */
    if (bootloader_start_var == 0xBEEF)
    {
        wdt_disable();
        start_bootloader();
    }
    
    /* Pull PC3 low to enable boot loader */
    PORTC_DIRCLR = PIN3_bm;                         // PC3 input
    PORTC.PIN3CTRL = PORT_OPC_PULLUP_gc;            // Pullup PC3
    _delay_ms(10);                                  // Small delay
    if((PORTC_IN & PIN3_bm) == 0)                   // Check PC3
    {
        start_bootloader();
    }
    
    /* Normal boot */
    switch_to_32MHz_clock();                        // Switch to 32MHz
    _delay_ms(1000);                                // Wait for power to settle
    init_serial_port();                             // Initialize serial port    
    init_dac();                                     // Init DAC
    init_adc();                                     // Init ADC
    init_ios();                                     // Init IOs
    init_calibration();                             // Init calibration
    enable_interrupts();                            // Enable interrupts
    init_usb();                                     // Init USB comms
    functional_test();                              // Functional test if started for the first time

    uint8_t current_fw_mode = MODE_IDLE;
    while(1)
    {
        if (current_fw_mode == MODE_CAP_MES)
        {
            // If we are in cap measurement mode and have a report to send
            if(cap_measurement_loop(&cap_report) == TRUE)
            {
                maindprintf_P(PSTR("*"));
                usb_packet.length = sizeof(cap_report);
                usb_packet.command_id = CMD_CAP_MES_REPORT;
                memcpy((void*)usb_packet.payload, (void*)&cap_report, sizeof(cap_report));
                usb_send_data((uint8_t*)&usb_packet);
            }
        }
        
        // USB command parser
        if (usb_receive_data((uint8_t*)&usb_packet) == TRUE)
        {
            switch(usb_packet.command_id)
            {
                case CMD_BOOTLOADER_START:
                {
                    maindprintf_P(PSTR("USB- Bootloader start"));
                    bootloader_start_var = 0xBEEF;
                    wdt_enable(WDTO_1S);
                    while(1);
                }
                case CMD_PING: 
                {
                    maindprintf_P(PSTR("."));
                    // Ping packet, resend the same one
                    usb_send_data((uint8_t*)&usb_packet);
                    break;
                }
                case CMD_VERSION:
                {
                    maindprintf_P(PSTR("USB- Version\r\n"));
                    // Version request packet
                    strcpy((char*)usb_packet.payload, CAPMETER_VER);
                    usb_packet.length = sizeof(CAPMETER_VER);
                    usb_send_data((uint8_t*)&usb_packet);
                    break;
                }
                case CMD_OE_CALIB_STATE:
                {
                    maindprintf_P(PSTR("USB- Calib state\r\n"));
                    // Get open ended calibration state.
                    if (is_platform_calibrated() == TRUE)
                    {
                        // Calibrated, return calibration data
                        usb_packet.length = get_openended_calibration_data(usb_packet.payload);
                    } 
                    else
                    {
                        // Not calibrated, return 0
                        usb_packet.length = 1;
                        usb_packet.payload[0] = 0;
                    }
                    usb_send_data((uint8_t*)&usb_packet);    
                    break;                
                }
                case CMD_OE_CALIB_START:
                {
                    maindprintf_P(PSTR("USB- Calib start\r\n"));
                    // Check if we are in idle mode
                    if (current_fw_mode == MODE_IDLE)
                    {
                        // Calibration start
                        start_openended_calibration(usb_packet.payload[0], usb_packet.payload[1], usb_packet.payload[2]);
                        usb_packet.length = get_openended_calibration_data(usb_packet.payload);
                    }
                    else
                    {
                        usb_packet.length = 1;
                        usb_packet.payload[0] = USB_RETURN_ERROR;
                    }
                    usb_send_data((uint8_t*)&usb_packet);    
                    break;                
                }
                case CMD_GET_OE_CALIB:
                {
                    maindprintf_P(PSTR("USB- Calib data\r\n"));
                    // Get calibration data
                    usb_packet.length = get_openended_calibration_data(usb_packet.payload);
                    usb_send_data((uint8_t*)&usb_packet);    
                    break;                
                }
                case CMD_SET_VBIAS:
                {
                    // Check that we are not measuring anything and if so, skip samples and stop oscillation
                    if (current_fw_mode == MODE_CAP_MES)
                    {
                        pause_capacitance_measurement_mode();
                    }
                    
                    // Enable and set vbias... can also be called to update it
                    uint16_t* temp_vbias = (uint16_t*)usb_packet.payload;
                    uint16_t set_vbias = enable_bias_voltage(*temp_vbias);
                    uint16_t cur_dacv = get_current_vbias_dac_value();
                    usb_packet.length = 4;
                    memcpy((void*)usb_packet.payload, (void*)&set_vbias, sizeof(set_vbias));
                    memcpy((void*)&usb_packet.payload[2], (void*)&cur_dacv, sizeof(cur_dacv));
                    usb_send_data((uint8_t*)&usb_packet);
                    
                    // If we are measuring anything, resume measurements
                    if (current_fw_mode == MODE_CAP_MES)
                    {
                        resume_capacitance_measurement_mode();
                    }                    
                    break;
                }
                case CMD_DISABLE_VBIAS:
                {
                    // Disable vbias
                    usb_packet.length = 0;
                    disable_bias_voltage();
                    usb_send_data((uint8_t*)&usb_packet);
                    break;
                }
                case CMD_CUR_MES_MODE:
                {
                    // Enable current measurement or start another measurement
                    if (current_fw_mode == MODE_IDLE)
                    {
                        set_current_measurement_mode(usb_packet.payload[0]);
                        current_fw_mode = MODE_CURRENT_MES;
                    } 
                    // Check if we are in the right mode to start a measurement
                    if (current_fw_mode == MODE_CURRENT_MES)
                    {
                        // We either just set current measurement mode or another measurement was requested
                        if (get_configured_adc_ampl() != usb_packet.payload[0])
                        {
                            // If the amplification isn't the same one as requested
                            set_current_measurement_mode(usb_packet.payload[0]);
                        }
                        // Start measurement
                        usb_packet.length = 2;
                        uint16_t return_value = cur_measurement_loop(usb_packet.payload[1]);
                        memcpy((void*)usb_packet.payload, (void*)&return_value, sizeof(return_value));
                        usb_send_data((uint8_t*)&usb_packet);
                    }
                    else
                    {
                        usb_packet.length = 1;
                        usb_packet.payload[0] = USB_RETURN_ERROR;
                        usb_send_data((uint8_t*)&usb_packet);
                    }
                    break;
                }
                case CMD_CUR_MES_MODE_EXIT:
                {
                    if (current_fw_mode == MODE_CURRENT_MES)
                    {
                        usb_packet.payload[0] = USB_RETURN_OK;
                        disable_current_measurement_mode();
                        current_fw_mode = MODE_IDLE;
                    }
                    else
                    {
                        usb_packet.payload[0] = USB_RETURN_ERROR;
                    }
                    usb_packet.length = 1;
                    usb_send_data((uint8_t*)&usb_packet);
                    break;                    
                }
                case CMD_CAP_REPORT_FREQ:
                {
                    if (current_fw_mode == MODE_IDLE)
                    {
                        set_capacitance_report_frequency(usb_packet.payload[0]);
                        usb_packet.payload[0] = USB_RETURN_OK;
                    }
                    else
                    {
                        usb_packet.payload[0] = USB_RETURN_ERROR;
                    }
                    usb_packet.length = 1;
                    usb_send_data((uint8_t*)&usb_packet);
                    break;
                }
                case CMD_CAP_MES_START:
                {
                    if (current_fw_mode == MODE_IDLE)
                    {
                        current_fw_mode = MODE_CAP_MES;
                        set_capacitance_measurement_mode();
                        usb_packet.payload[0] = USB_RETURN_OK;
                    }
                    else
                    {
                        usb_packet.payload[0] = USB_RETURN_ERROR;
                    }
                    usb_packet.length = 1;
                    usb_send_data((uint8_t*)&usb_packet);
                    break;
                }
                case CMD_CAP_MES_EXIT:
                {
                    if (current_fw_mode == MODE_CAP_MES)
                    {
                        current_fw_mode = MODE_IDLE;
                        disable_capacitance_measurement_mode();
                        usb_packet.payload[0] = USB_RETURN_OK;
                    }
                    else
                    {
                        usb_packet.payload[0] = USB_RETURN_ERROR;
                    }
                    usb_packet.length = 1;
                    usb_send_data((uint8_t*)&usb_packet);
                    break;
                }
                case CMD_SET_VBIAS_DAC:
                {
                    uint16_t* requested_dac_val = (uint16_t*)usb_packet.payload;
                    uint16_t* requested_wait = (uint16_t*)&usb_packet.payload[2];
                    
                    usb_packet.length = 2;
                    if (is_ldo_enabled() == TRUE)
                    {
                        uint16_t set_vbias = force_vbias_dac_change(*requested_dac_val, *requested_wait);
                        memcpy((void*)usb_packet.payload, (void*)&set_vbias, sizeof(set_vbias));
                    } 
                    else
                    {
                        usb_packet.payload[0] = 0;
                        usb_packet.payload[1] = 0;
                    }        
                    usb_send_data((uint8_t*)&usb_packet);            
                    break;
                }
                case CMD_RESET_STATE:
                {
                    maindprintf_P(PSTR("USB- Reset\r\n"));
                    usb_packet.length = 1;
                    current_fw_mode = MODE_IDLE;
                    if(is_platform_calibrated() == TRUE)
                    {
                        disable_bias_voltage();
                        disable_current_measurement_mode();
                        disable_capacitance_measurement_mode();
                        usb_packet.payload[0] = USB_RETURN_OK;                        
                    }
                    else
                    {
                        usb_packet.payload[0] = USB_RETURN_ERROR;
                    }
                    usb_send_data((uint8_t*)&usb_packet);
                    break;
                }
                case CMD_SET_EEPROM_VALS:
                {
                    uint16_t* addr = (uint16_t*)usb_packet.payload;
                    uint16_t size = usb_packet.payload[2];
                    if(((*addr) + size > APP_STORED_DATA_MAX_SIZE) || (size > (RAWHID_RX_SIZE-5)))
                    {
                         usb_packet.payload[0] = USB_RETURN_ERROR;
                    }
                    else
                    {
                        eeprom_write_block((void*)&usb_packet.payload[3], (void*)(EEP_APP_STORED_DATA + (*addr)), size);
                        usb_packet.payload[0] = USB_RETURN_OK;
                    }
                    usb_packet.length = 1;
                    usb_send_data((uint8_t*)&usb_packet);
                    break;
                }
                case CMD_READ_EEPROM_VALS:
                {
                    uint16_t* addr = (uint16_t*)usb_packet.payload;
                    uint16_t size = usb_packet.payload[2];
                    if(((*addr) + size > APP_STORED_DATA_MAX_SIZE) || (size > (RAWHID_TX_SIZE-2)))
                    {
                        usb_packet.length = 1;
                        usb_packet.payload[0] = USB_RETURN_ERROR;
                    }
                    else
                    {
                        usb_packet.length = size;
                        eeprom_read_block(usb_packet.payload, (void*)(EEP_APP_STORED_DATA + (*addr)), size);
                    }
                    usb_send_data((uint8_t*)&usb_packet);
                    break;
                }
                default: break;
            }
        }
    }
    
    // Left here for reference
    //enable_bias_voltage(850);while(1);
    //automated_current_testing();
    //ramp_bias_voltage_test();
    //voltage_settling_test();
    //automated_vbias_testing();
    //automated_current_testing();
    //peak_to_peak_adc_noise_measurement_test();
    //ramp_bias_voltage_test();
    //printf("blah\r\n");_delay_ms(3333);
    //ramp_current_test();
    //functional_test();
    //while(1);
    //calibrate_thresholds();                         // Calibrate vup vlow & thresholds
    //calibrate_cur_mos_0nA();                        // Calibrate 0nA point and store values in eeprom
    //calibrate_current_measurement();                // Calibrate the ADC for current measurements
}
예제 #16
0
int main(void)
{
	char out_buf[20+1];
	measured_val[0]=0;
	measured_val[1]=0;
	init_dac();
	lcd_init(LCD_DISP_ON);
	init_kbd();
	set_val[0]=15;set_val[1]=50; // 150mA and 5V
	if (eeprom_read_byte((uint8_t *)0x0) == 19){
		// ok magic number matches accept values
		set_val[1]=eeprom_read_word((uint16_t *)0x04);
		set_val[0]=eeprom_read_word((uint16_t *)0x02);
	}
	// I2C also called TWI
	i2c_init(3,1,0);
	sei();
	i2c_send_data("on");
	init_analog();
	while (1) {

		// current
		measured_val[0]=adc_i_to_disp(getanalogresult(0));
		set_val_adcUnits[0]=disp_i_to_adc(set_val[0]);
		set_target_adc_val(0,set_val_adcUnits[0]);
		// voltage
		measured_val[1]=adc_u_to_disp(getanalogresult(1),measured_val[0]);
		set_val_adcUnits[1]=disp_u_to_adc(set_val[1])+disp_i_to_u_adc_offset(measured_val[0]);
		set_target_adc_val(1,set_val_adcUnits[1]);

		// voltage
		lcd_clrscr();
		int_to_ascii(measured_val[1],out_buf,1,1);
		lcd_puts(out_buf);
		lcd_puts("V ");
		int_to_ascii(set_val[1],out_buf,1,1);
		lcd_putc('[');
		lcd_puts(out_buf);
		lcd_putc(']');
		if (!is_current_limit()){
			// put a marker to show which value is currenlty limiting
			lcd_puts("<-");
		}

		// current
		lcd_gotoxy(0,1);
		int_to_ascii(measured_val[0],out_buf,2,0);
		lcd_puts(out_buf);
		lcd_puts("A ");
		int_to_ascii(set_val[0],out_buf,2,0);
		lcd_putc('[');
		lcd_puts(out_buf);
		lcd_putc(']');
		if (is_current_limit()){
			// put a marker to show which value is currenlty limiting
			lcd_puts("<-");
		}
		//dbg
		//int_to_ascii(is_dacval(),out_buf,0,0);
		//lcd_puts(out_buf);
		check_i2c_interface();

		// the buttons must be responsive but they must not 
		// scroll too fast if pressed permanently
		if (check_buttons()==0){
			// no buttons pressed
			delay_ms(100);
			bpress=0;
			check_i2c_interface();
			check_buttons();
			delay_ms(150);
		}else{
			// button press
			if (bpress > 11){
				// somebody pressed permanetly the button=>scroll fast
				delay_ms(10);
				check_i2c_interface();
				delay_ms(40);
			}else{
				bpress++;
				delay_ms(100);
				check_i2c_interface();
				delay_ms(150);
			}
		}
	}
	return(0);
}
예제 #17
0
int main(int argc, char *argv[])
{
	int blink[3], flip[2] = {0, 0};
	int do_ao_only = FALSE;
	uint8_t i = 0;

	if (do_ao_only) {
		if (init_dac(0.0, 25.0, FALSE) < 0) {
			printf("Missing Analog AO subdevice\n");
			return -1;
		}
		while (TRUE) {
			set_dac_volts(1, ((double) sine_wave[i])*0.007);
			set_dac_volts(0, ((double) sine_wave[255 - i++])*0.007);
			usleep(10);
			//			printf("%d\n", i);
		}
	} else {

		if (init_daq(0.0, 25.0, FALSE) < 0) {
			printf("Missing Analog subdevice(s)\n");
			return -1;
		}
		if (init_dio() < 0) {
			printf("Missing Digital subdevice(s)\n");
			return -1;
		}
		set_dio_output(0);
		set_dio_output(1);
		set_dio_input(6);
		set_dio_input(7);
		put_dio_bit(0, 1);
		put_dio_bit(1, 1);
		blink[2] = 0;

		while (1) {

			get_data_sample();
			if (blink[2]++ >= 100) {
				printf("         \r");
				printf(" %2.3fV %2.3fV %2.3fV %2.3fV %2.3fV %2.3fV %2.3fV %u %u %u %u %u %u raw %x, %x",
					bmc.pv_voltage, bmc.cc_voltage, bmc.input_voltage, bmc.b1_voltage, bmc.b2_voltage, bmc.system_voltage, bmc.logic_voltage,
					bmc.datain.D0, bmc.datain.D1, bmc.datain.D2, bmc.datain.D3, bmc.datain.D6, bmc.datain.D7, bmc.adc_sample[0], bmc.adc_sample[1]);
				//        usleep(4990);
				blink[2] = 0;

				if ((bmc.datain.D0 == 0)) {
					if (((blink[0]++) % 150) == 0) {
						flip[0] = !flip[0];
					}
					printf(" Flip led 0 %x ", flip[0]);
					bmc.dataout.D0 = flip[0];
					set_dac_volts(0, bmc.cc_voltage);
				} else {
					set_dac_volts(0, 0.666);
					bmc.dataout.D0 = 0;
				}
				if ((bmc.datain.D1 == 0)) {
					if (((blink[1]++) % 150) == 0) {
						flip[1] = !flip[1];
					}
					printf(" Flip led 1 %x ", flip[1]);
					set_dac_volts(1, 0.333);
					bmc.dataout.D1 = flip[1];
				} else {
					set_dac_volts(1, 1.666);
					bmc.dataout.D1 = 0;
				}
			}
		}
	}
	return 0;
}
예제 #18
0
파일: mtxvpro.c 프로젝트: Gaikokujin/WinNT4
bool initVideoMode(word mode, byte pwidth)
{
   int dacAdjust = 0;

   if ( !(encBaseAddr = detectVideoBoard()) ) 
      return mtxFAIL;

   gain = 10000;
   if ( (inp(encBaseAddr + 2) & 0x7) > 0 ) 
      {
      switch (mode)
         {
         case NTSC_STD: 
            ptrEncReg = &ntsca_1;
            gain = 14100;
            break;
         case PAL_STD:  
            ptrEncReg = &pala_1;  
            gain = 14100;
            break;
         case NTSC_STD | VAFC:
            ptrEncReg = &ntsc_1;
            break;

         case PAL_STD | VAFC:
            ptrEncReg = &pal_1;
            break;
         }
      if ( mode & VAFC )
         {
         switch( pwidth )
            {
            case  8:
               dacAdjust = 4;
               break;

            case 16:
               dacAdjust = 2;
               break;

            case 32:
               dacAdjust = 0;
               break;
            }
         }
      else
         {
	      switch(Hw[iBoard].DacType)
            {
		      case BT482:
		      case BT485: 
               switch( pwidth )
                  {
                  case  8:
                     dacAdjust = 0;
                     break;

                  case 16:
                  case 32:
                     dacAdjust = 1;
                     break;
                  }
               break;
            
		      case VIEWPOINT: 
               dacAdjust = 5;
               break;


            case TVP3026:   
               switch( pwidth )
                  {
                  case  8:
                     dacAdjust = 18;
                     break;

                  case 16:
                     dacAdjust = 22;
                     break;

                  case 32:
                     dacAdjust = 26;
                     break;
                  }
               break;
            }

         }

      }
   else
      switch (mode)
         {
         case NTSC_STD: 
            ptrEncReg = &ntsca_0;
            break;
         case PAL_STD:  
            ptrEncReg = &pala_0;  
            break;
         case NTSC_STD | VAFC: 
            switch (pwidth)
               {
               case  8: ptrEncReg = &ntsc8_0;  break;
               case 16: ptrEncReg = &ntsc16_0; break;
               case 32: ptrEncReg = &ntsc32_0; break;
               }
            break;
         case PAL_STD | VAFC: 
            switch (pwidth)
               {
               case  8: ptrEncReg = &pal8_0;  break;
               case 16: ptrEncReg = &pal16_0; break;
               case 32: ptrEncReg = &pal32_0; break;
               }
            break;
         }


   init_denc();
   init_dac();
   init_adc();
   init_psg( dacAdjust );
   init_ctrl();
   init_luts(); 

   return mtxOK;
}
예제 #19
0
int main(void) {
	volatile int16_t* samples;
	unsigned int i;
	DISABLE_GLOBAL_INT();
	/* stop watchdog timer */
	WDTCTL = WDTPW +WDTHOLD;
	/* SET CPU to 5MHz */
	/* max DCO
	   MCLK = DCOCLK
	   SMCLK = DCOCLK
	   ACLK = 8KHz
	*/
	DCOCTL = DCO0 + DCO1 + DCO2;
	BCSCTL1 = RSEL0 + RSEL1 + RSEL2 + XT2OFF;
	BCSCTL2 = 0x00;

	delay_us(10000);

	/* activate Active Mode */
	__bic_SR_register(LPM4_bits);

	/* set LEDs when loaded */
	P5SEL = 0x00;
	P5DIR = 0x70;
	LED_RED_ON();
	LED_GREEN_OFF();
	LED_BLUE_OFF();

	check_for_clock();
	init_usb_serial();
#ifdef USE_DMA
	init_dma(&g_sample_flag);
#endif

#ifdef TX
	init_adc(&g_sample_flag);
#else
	init_dac();
#endif
	init_rf(RF_CHANNEL, PAN_ID, NODE_ADDR, &g_sample_flag);

	debug_print("Successfully booted.\n");
	/* set LEDS to signalize finished initilizing */
	LED_RED_OFF();
	ENABLE_GLOBAL_INT();

#ifdef TX
	/* TX */
	while(1) {
		if(g_sample_flag == 1) {
			g_sample_flag = 0;
#ifdef USE_DMA
			/* get samples */
			samples = get_samples_dma();
#else
			/* get samples */
			samples = get_samples();
#endif
			/* send oder radio, 2*num_words */
			send_rf_data(RF_RX_ADDR, (uint8_t*) samples, NUM_SAMPLES*2);
		}
		/* reset WDT */
		WDTCTL = WDTPW + WDTCNTCL;

	}
#else
	/* RX */
	while(1) {
		if(g_sample_flag == 1) {
			g_sample_flag = 0;
			samples = get_samples_rf();
#if 0
			uint8_t err = 0;
			for(i = 0; i < NUM_SAMPLES; ++i) {
				//samples[i] = 4095-7*i;
				usb_printf("%d\n", samples[i]);
				//if( ((uint16_t) samples[i]) > 4095) {
				//	usb_printf("i=%u\n", i);
				//	++err;
				//}
			}
			usb_printf("#error: %u\n", err);
			usb_printf("\n\n");
#endif			
			set_dma_data(samples, NUM_SAMPLES);
		}
		/* reset WDT */
		WDTCTL = WDTPW + WDTCNTCL;
	}
#endif
	return 0;
}
예제 #20
0
int main(void)
{
	int16_t dac_val=511;
	int16_t cnt;
	int8_t dac_dir=0;
	char out_buf[21];
	DDRD|= (1<<DDD0); // LED, enable PD0, LED as output
	LEDOFF;
	init_dac();
	lcd_init();
	lcd_clrscr();
	lcd_puts("use U+/U-");
	lcd_gotoxy(0,1);
	lcd_puts("and store");
	init_kbd();
	delay_ms(500);
	delay_ms(500);
	lcd_clrscr();
	lcd_puts_p(PSTR("pause"));
	while (1) {
		if (dac_dir==1){
			dac_val++;
		}
		if (dac_dir==-1){
			dac_val--;
		}
		if (dac_val>0xFFF){
			dac_val=0xFFF; //max, 13bit
		}
		if (dac_val<0){
			dac_val=0;
		}
		lcd_gotoxy(0,1);
		itoa(dac_val,out_buf,10);
		lcd_puts(out_buf);
		lcd_puts("    ");
		dac(dac_val);
		cnt=1;
		check_u_button(&cnt);
		if (cnt>1){
			lcd_clrscr();
			// u+ pressed
			lcd_puts_p(PSTR("up"));
			dac_dir=1;
			LEDOFF;
		}
		if (cnt<1){
			lcd_clrscr();
			// u- pressed
			lcd_puts_p(PSTR("down"));
			dac_dir=-1;
			LEDON;
		}
		if (check_store_button()){
			lcd_clrscr();
			lcd_puts_p(PSTR("pause"));
			dac_dir=0;
		}
		delay_ms(100);
		cnt=1;
		check_u_button(&cnt);
		if (cnt>1){
			lcd_clrscr();
			// u+ pressed
			lcd_puts_p(PSTR("up"));
			dac_dir=1;
			LEDOFF;
		}
		if (cnt<1){
			lcd_clrscr();
			// u- pressed
			lcd_puts_p(PSTR("down"));
			dac_dir=-1;
			LEDON;
		}
		if (check_store_button()){
			lcd_clrscr();
			lcd_puts_p(PSTR("pause"));
			dac_dir=0;
		}
		delay_ms(100);
	}
	return(0);
}