//Enables the peripherals associated with the strain amplifier and //sets the default values. //Make sure that you initialize I2C1 first! void init_strain(void) { int i = 0, j = 0; //Array prep: //=-=-=-=-=-= init_adc_delsig_dma_array(); //Peripherals: //=-=-=-=-=-= //16-bits ADC: ADC_DelSig_1_Start(); //ADC_DelSig_1_IRQ_Enable(); dma_2_config(); isr_delsig_StartEx(isr_delsig_Interrupt_InterruptCallback); //Defaults: //=-=-=-=-=-= for(i = 0; i < STRAIN_CHANNELS; i++) { strain[i].offset = STRAIN_DEFAULT_OFFSET; for(j = 0; j < STRAIN_BUF_LEN; j++) { strain[i].strain_raw[j] = 0; } strain[i].strain_filtered = 0; strain_config(i, strain[i].offset); } ADC_DelSig_1_StartConvert(); }
/******************************************************************************* * Function Name: main ******************************************************************************** * * Summary: * main() performs following functions: * 1: Initializes the LCD * 2: Starts ADC * 3: Starts ADC converstion. * 4: Gets the converted result and displays it in LCD. * * Parameters: * None. * * Return: * None. * *******************************************************************************/ int main() { int16 output; /* Start the components */ LCD_Start(); ADC_DelSig_1_Start(); /* Start the ADC conversion */ ADC_DelSig_1_StartConvert(); /* Display the value of ADC output on LCD */ LCD_Position(0u, 0u); LCD_PrintString("ADC_Output"); for(;;) { if(ADC_DelSig_1_IsEndConversion(ADC_DelSig_1_RETURN_STATUS)) { output = ADC_DelSig_1_GetResult16(); /* Saturate ADC result to positive numbers. */ if(output < 0) { output = 0; } LCD_Position(1u, 0u); LCD_PrintInt16(output); } } }
uint8 campbell_cond_start(){ /* Start of all components */ ADC_DelSig_1_Start(); ADC_DelSig_1_SelectConfiguration(1u, 1u); Comp_1_Start(); Comp_2_Start(); Comp_3_Start(); //Comp_4_Start(); AMux_1_Start(); //AMuxSeq_1_Next(); // Connect Mux to first Sample_Hold_1_Start(); Sample_Hold_2_Start(); Sample_Hold_3_Start(); //Sample_Hold_4_Start(); PWM_1_Start(); PWM_2_Start(); Cond_Vout_Write(0u); return 1u; }
/******************************************************************************* * 初始化函数 ********************************************************************************/ void init() { CyGlobalIntEnable; //全局中断开启 ADC_DelSig_1_Start(); /* 配置并开启ADC */ ADC_DelSig_1_StartConvert(); /* 开始进行转换 */ Uart_Rx_ISR_StartEx(RxInterruptHandler); /* 开启 Uart Rx 中断 并连接到 RxInterruptHandler */ Uart_Tx_ISR_StartEx(TxInterruptHandler); /* 开启 Uart Tx 并连接到 TxInterruptHandler */ UART_Start(); /* 开启 UART */ Uart_Rx_ISR_1_StartEx(Rx_1_InterruptHandler); /* 开启 Uart Rx 中断 并连接到 RxInterruptHandler */ Uart_Tx_ISR_1_StartEx(Tx_1_InterruptHandler); /* 开启 Uart Tx 并连接到 TxInterruptHandler */ UART_1_Start(); /* 开启 UART1 */ Uart_Rx_ISR_2_StartEx(Rx_1_InterruptHandler); /* 开启 Uart Rx 中断 并连接到 RxInterruptHandler */ Uart_Tx_ISR_2_StartEx(Tx_1_InterruptHandler); /* 开启 Uart Tx 并连接到 TxInterruptHandler */ UART_2_Start(); /* 开启 UART2 */ Timer_ISR_StartEx(TimerInterruptHandler); /* 开启 Timer 中断并连接到 TimerInterruptHandler */ Timer_Start(); /* 开启定时器 */ LCD_Char_1_Start(); /* 初始化并清除LCD */ //LCD_Char_1_PrintString("init"); }
uint8 campbell_temp_start(){ /* Start of all components */ AMux_1_Start(); ADC_DelSig_1_Start(); Temp_Vout_Write(0u); ADC_DelSig_1_SelectConfiguration(1u, 1u); return 1u; }
void main() { /* Place your initialization/startup code here (e.g. MyInst_Start()) */ Opamp_1_Start(); Opamp_3_Start(); Clock_1_Start(); ADC_DelSig_1_Start(); ADC_DelSig_1_StartConvert(); VDAC8_1_Start(); VDAC8_2_Start(); CyGlobalIntEnable; /* Uncomment this line to enable global interrupts. */ isr_StartEx(filterVDAC); for(;;) { /* Place your application code here. */ } }
/*main*/ void main(void) { /*Preliminary parts not important*/ LCD_Char_1_Start(); ADC_DelSig_1_Start(); ADC_DelSig_1_StartConvert(); Configure_DMA(); isr_1_StartEx(Buffer_complete); isr_2_StartEx(LPF_buffer_complete); ADC_DelSig_1_SetCoherency(ADC_DelSig_1_COHER_MID); Filter_SetDalign(Filter_STAGEA_DALIGN,Filter_ENABLED); Filter_SetDalign(Filter_HOLDA_DALIGN,Filter_ENABLED); Filter_SetCoherency(Filter_STAGEA_COHER,Filter_KEY_MID); Filter_SetCoherency(Filter_HOLDA_COHER,Filter_KEY_MID); Filter_SetCoherency(Filter_CHANNEL_A,Filter_KEY_MID); Filter_SetDalign(Filter_STAGEB_DALIGN,Filter_ENABLED); Filter_SetDalign(Filter_HOLDB_DALIGN,Filter_ENABLED); Filter_SetCoherency(Filter_STAGEB_COHER,Filter_KEY_MID); Filter_SetCoherency(Filter_HOLDB_COHER,Filter_KEY_MID); Filter_SetCoherency(Filter_CHANNEL_B,Filter_KEY_MID); CyGlobalIntEnable; Filter_Start(); /*Writes ADC values to ADC_samples array*/ while(1){ if (isr_BC_flag==1){ arm_cfft_q15(&arm_cfft_sR_q15_len256, Buffer_samples, 0, 1); arm_cmplx_mag_q15(Buffer_samples, magoutput, fftlength); CyDmaChEnable(DMA_2_Chan, 1); isr_BC_flag=0; isr_1_ClearPending(); } } }
void main() { uint8 state, var_mask, ADC_in, auto_mode, continous_mode; uint8 DigitsPrecision, MaximumWeight; int16 MaxAvgReading = null, \ MinAvgReading = null, \ ScaledRange = null; //uint8 Digit[5], ScaledRange, LastFractionResult, Remainder; /* Start the components */ ADC_DelSig_1_Start(); //ADC_DelSig_1_IRQ_Start(); //disable for manual polling instead so can single step CYGlobalIntEnable; //enable for ADC and USB interrupts /* Start the ADC conversion */ ADC_DelSig_1_StartConvert(); ADC_DelSig_1_IRQ_Disable(); //disable for manual polling instead so can single step /* Start USBFS Operation with 5V operation */ USBFS_1_Start(0u, USBFS_1_5V_OPERATION); //USBFS_1_5V_OPERATION); /* Wait for Device to enumerate i.e. detects USB settings from host PC */ while(USBFS_1_GetConfiguration() != 0u); /* Enumeration is done, enable OUT endpoint for receive data from Host */ USBFS_1_EnableOutEP(OUT_EP); state=0u; for(;;) // this is infinite state loop { if(state==0u) { /* Check that configuration is changed (there is only one configured on the USBFS )*/ if(USBFS_1_IsConfigurationChanged() != 0u) { /* Re-enable endpoint when device is configured */ if(USBFS_1_GetConfiguration() != 0u) { USBFS_1_EnableOutEP(OUT_EP); } } /* GET MODE STATE Read USB PC host application*/ if(USBFS_1_GetEPState(OUT_EP) == USBFS_1_OUT_BUFFER_FULL) { /* Read received bytes count */ length = USBFS_1_GetEPCount(OUT_EP); /* Unload the OUT buffer */ USBFS_1_ReadOutEP(OUT_EP, &in_buffer[0u], length); state= in_buffer[MODE_BYTE]; var_mask=in_buffer[SET_VARS_MASK_BYTE]; if(var_mask & CONTINOUS_MODE_MASK_BIT) continous_mode = TRUE; else continous_mode = FALSE; } } if(state & INIT_SCALE_VARS) { if(var_mask & MAX_WEIGHT_VAR_MASK_BIT) MaximumWeight=in_buffer[MAX_WEIGHT_VAR_BYTE]; if(MaximumWeight<MIN_WEIGHT_SCALE) MaximumWeight=MIN_WEIGHT_SCALE; if(MaximumWeight>MAX_WEIGHT_SCALE) MaximumWeight=MAX_WEIGHT_SCALE; if(var_mask & PRECISION_VAR_MASK_BIT) DigitsPrecision=in_buffer[PRECISION_VAR_BYTE]; if(DigitsPrecision<MIN_PRECISION_DIGITS) DigitsPrecision=MIN_PRECISION_DIGITS; if(DigitsPrecision>MAX_PRECISION_DIGITS) DigitsPrecision=MAX_PRECISION_DIGITS; if(var_mask & AUTO_MODE_MASK_BIT) auto_mode=TRUE; else auto_mode=FALSE; state=0u; } if(state & GET_SCALE_LOW_LIMIT) { MinAvgReading = get_adc_average(NUMBER_SAMPLES); clear_buffer(out_buffer,BUF_SIZE); out_buffer[0u]=(uint8)MinAvgReading; //respond with min avg adc value (this requires host request) SendOutData(out_buffer); state=0u; } if(state & GET_SCALE_HIGH_LIMIT) { MaxAvgReading = get_adc_average(NUMBER_SAMPLES); clear_buffer(out_buffer,BUF_SIZE); out_buffer[0u]=(uint8)MaxAvgReading; //respond with max avg adc value (this requires host request) SendOutData(out_buffer); state=0u; } if(state & SEND_SCALE_WEIGHT) { do { //this flag tests if the ADC interrupt occurred meaning data is ready adc_flag=Status_Reg_1_Read(); //note the interrupt is disabled so read EOC bit instead if(adc_flag==1u) { ADC_in=ADC_DelSig_1_GetResult8(); //read adc byte adc_flag=0u; clear_buffer(out_buffer,BUF_SIZE); if(auto_mode==FALSE) calculate_fixed_weight(ADC_in, out_buffer); if(auto_mode==TRUE) if( (MaxAvgReading == null) || (MinAvgReading == null) ) // Send Error Message continue; ScaledRange = (MaxAvgReading - MinAvgReading) / MaximumWeight; calculate_scaled_weight(ADC_in, out_buffer, ScaledRange); //send weight data (this requires host request) SendOutData(out_buffer); } }while(USBFS_1_GetEPState(OUT_EP) != USBFS_1_OUT_BUFFER_FULL \ && continous_mode == TRUE); state=0u; } } }
void main() { CYGlobalIntEnable; /* Enable global interrupts */ ADC_DelSig_1_Start();/* Configure and power up ADC */ LCD_Char_1_Start(); /* Initialize and clear the LCD */ /* Move the cursor to Row 0 Column 0 */ LCD_Char_1_Position(ROW_0,COLUMN_0); /* Print Label for the pot voltage raw count */ LCD_Char_1_PrintString("TEMP NOW: C"); LCD_Char_1_Position(ROW_1,COLUMN_0); LCD_Char_1_PrintString("TEMP SET: C"); ADC_DelSig_1_StartConvert(); /* Force ADC to initiate a conversion */ /* Start capsense and initialize baselines and enable scan */ CapSense_Start(); CapSense_InitializeAllBaselines(); CapSense_ScanEnabledWidgets(); /* CyGlobalIntEnable; */ /* Uncomment this line to enable global interrupts. */ //Start the pwm; PWM_1_Start(); for(;;) { /* If scanning is completed update the baseline count and check if sensor is active */ while(CapSense_IsBusy()); /* Update baseline for all the sensors */ CapSense_UpdateEnabledBaselines(); CapSense_ScanEnabledWidgets(); /* Test if button widget is active */ stateB_1 = CapSense_CheckIsWidgetActive(CapSense_BUTTON0__BTN); stateB_2 = CapSense_CheckIsWidgetActive(CapSense_BUTTON1__BTN); /* Wait for end of conversion */ ADC_DelSig_1_IsEndConversion(ADC_DelSig_1_WAIT_FOR_RESULT); /* Get converted result */ voltageRawCount = ADC_DelSig_1_GetResult16(); //Change voltageRawCount to Temperature; temp = voltageRawCount / 3.870 * 0.1017 + 0.5; cold = (9999 - (temp > temp_set ? temp - temp_set : 0) * 50); if(cold < 1000) cold = 1000; if(cold > 9999) cold = 9999; //Change the pwm; PWM_1_WriteCompare(cold); /* Set range limit */ if (temp > 0x7FFF) { temp = 0; } else { /* Continue on */ } if(show < 10) { show++; } else { show = 0; UpdateDisplay(temp, 0); /* Print result on LCD */ UpdateButtonState(stateB_1, stateB_2); } } }