Skip to content

Commit

Permalink
diff gain working
Browse files Browse the repository at this point in the history
  • Loading branch information
boramonideep committed Apr 28, 2023
1 parent a514687 commit efaeb6d
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
50 changes: 50 additions & 0 deletions cores/wiring_analog.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,56 @@ if( channel < NUM_ANALOG_INPUTS )
return value;
}

uint32_t analogRead_special( uint8_t channel )
{
uint32_t value;

value = 0xFFFFFFFF;
if( channel < NUM_ANALOG_INPUTS )
{
XMC_ADC_t *adc = &mapping_adc[ channel ];

#if(XMC_VADC_GROUP_AVAILABLE == 1U)
// ADC grouping
if( !(adc->enabled) )
{
XMC_VADC_CHANNEL_CONFIG_t vadc_gobal_channel_config;
memset( &vadc_gobal_channel_config, 0, sizeof( XMC_VADC_CHANNEL_CONFIG_t ) );
vadc_gobal_channel_config.input_class = XMC_VADC_CHANNEL_CONV_GROUP_CLASS1;
vadc_gobal_channel_config.result_reg_number = adc->result_reg_num;
vadc_gobal_channel_config.alias_channel = XMC_VADC_CHANNEL_ALIAS_DISABLED;

XMC_VADC_RESULT_CONFIG_t vadc_gobal_result_config = { .g_rcr = 0 };
/* Configure a channel belonging to the aforesaid conversion kernel */
XMC_VADC_GROUP_ChannelInit( adc->group, adc->channel_num, &vadc_gobal_channel_config );
/* Configure a result resource belonging to the aforesaid conversion kernel */
XMC_VADC_GROUP_ResultInit( adc->group, adc->result_reg_num, &vadc_gobal_result_config );
/* Add channel into the Background Request Source Channel Select Register */
XMC_VADC_GLOBAL_BackgroundAddChannelToSequence( VADC, (uint32_t)adc->group_num,
(uint32_t)adc->channel_num );

XMC_VADC_GLOBAL_SHS_SetGainFactor(SHS0,3,XMC_VADC_GROUP_INDEX_0,(uint32_t)adc->channel_num);
}
/* Start conversion manually using load event trigger*/
XMC_VADC_GLOBAL_BackgroundTriggerConversion( VADC );
value = XMC_VADC_GROUP_GetResult( adc->group, adc->result_reg_num );
#else
// XMC1100 no ADC grouping
if( !(adc->enabled) )
/* Add a channel to the background source. */
VADC->BRSSEL[ ADC_CONVERSION_GROUP ] = (uint32_t)( 1U << adc->channel_num );
XMC_VADC_GLOBAL_SHS_SetGainFactor(SHS0,1,XMC_VADC_GROUP_INDEX_0,(uint32_t)adc->channel_num);
// Generates conversion request
XMC_VADC_GLOBAL_BackgroundTriggerConversion( VADC );

// Wait until conversion is ready
while( ( ( value = XMC_VADC_GLOBAL_GetDetailedResult( VADC ) ) & VADC_GLOBRES_VF_Msk) == 0u );
#endif
value = ( ( value & VADC_GLOBRES_RESULT_Msk) >> ( ADC_MAX_READ_RESOLUTION - _readResolution ) );
}
return value;
}


/* Helper function for analogWrite and setAnalogWriteFrequency to scan
mapping tables to determine for a given pin which PWM4, PWM8 or DAC
Expand Down
2 changes: 2 additions & 0 deletions cores/wiring_analog.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ extern "C" {
*/
extern uint32_t analogRead( uint8_t channel ) ;

extern uint32_t analogRead_special( uint8_t channel ) ;

/*
* \brief Set the resolution of analogRead return values in number of bits.
* \note Default is 10 bits (range from 0 to 1023).
Expand Down
1 change: 1 addition & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ getAnalogReadBits KEYWORD2
getAnalogWriteBits KEYWORD2
getAnalogReadMaximum KEYWORD2
getAnalogWriteMaximum KEYWORD2
analogRead_special KEYWORD2

#######################################
# Instances (KEYWORD2)
Expand Down

0 comments on commit efaeb6d

Please sign in to comment.