/******************************************************************************* * Function Name: ADC_DelSig_1_IRQ_Stop ******************************************************************************** * * Summary: * Disables and removes the interrupt. * * Parameters: * None * * Return: * None * *******************************************************************************/ void ADC_DelSig_1_IRQ_Stop(void) { /* Disable this interrupt. */ ADC_DelSig_1_IRQ_Disable(); /* Set the ISR to point to the passive one. */ ADC_DelSig_1_IRQ_SetVector(&IntDefaultHandler); }
/******************************************************************************* * Function Name: ADC_DelSig_1_IRQ_Start ******************************************************************************** * * Summary: * Set up the interrupt and enable it. This function disables the interrupt, * sets the default interrupt vector, sets the priority from the value in the * Design Wide Resources Interrupt Editor, then enables the interrupt to the * interrupt controller. * * Parameters: * None * * Return: * None * *******************************************************************************/ void ADC_DelSig_1_IRQ_Start(void) { /* For all we know the interrupt is active. */ ADC_DelSig_1_IRQ_Disable(); /* Set the ISR to point to the ADC_DelSig_1_IRQ Interrupt. */ ADC_DelSig_1_IRQ_SetVector(&ADC_DelSig_1_IRQ_Interrupt); /* Set the priority. */ ADC_DelSig_1_IRQ_SetPriority((uint8)ADC_DelSig_1_IRQ_INTC_PRIOR_NUMBER); /* Enable it. */ ADC_DelSig_1_IRQ_Enable(); }
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; } } }
/******************************************************************************* * Function Name: ADC_DelSig_1_IRQ_Stop ******************************************************************************** * * Summary: * Disables and removes the interrupt. * * Parameters: * None * * Return: * None * *******************************************************************************/ void ADC_DelSig_1_IRQ_Stop(void) { /* Disable this interrupt. */ ADC_DelSig_1_IRQ_Disable(); }