Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
IvanoBono
Level 3
Level 3
10 sign-ins 10 replies posted 10 questions asked

hi all, using a illd, I configured a fast compare channel like this:

void FastCompare_Init(void) {
IfxEvadc_Adc_FastCompareChannelConfig config;
IfxEvadc_Adc_initFastCompareChannelConfig(&config,&g_evadc);
config.fastCompareChannelId=IfxEvadc_GroupId_14;
config.channelEventMode=IfxEvadc_ChannelEventMode_aboveOrBelowCompareValue;
config.serviceRequestGenerationEvent=IfxEvadc_FastCompareServiceRequestGeneration_newResult;
config.boundaryFlagNodePointer=IfxEvadc_BoundaryFlagNodePointer_sharedServiceRequestLine0;
config.referenceValue=512;
config.runMode=IfxEvadc_FastCompareRunControl_alwaysRun;
config.triggerInterval=0; //16/fADC 16/160mhz= 1mhz
IfxEvadc_Adc_FastCompareChannel fc;
IfxEvadc_Adc_initFastCompareChannel(&fc,&config);
}

with this function I can read correctly if the voltage value applied to the input is higher or lower than VREF / 2:

bool FastCompare_Get(void) {
return IfxEvadc_getFastCompareBoundaryFlagStatus(&g_evadc.evadc->FC[2]);
}

I would need to trigger an interrupt when the "Boundary Flag Status" changes in value. Can anyone help me?

0 Likes
1 Solution
IvanoBono
Level 3
Level 3
10 sign-ins 10 replies posted 10 questions asked

ok, it works. thank you.
for anyone interested the final c source code is:

 

#define ISR_ADC_PRIORITY 20
IfxEvadc_Adc         g_evadc;

void AdcGroup_Init(void) {
    /* Create configuration */
    IfxEvadc_Adc_Config adcConfig;
    /* Assign default values to the configuration */
    IfxEvadc_Adc_initModuleConfig(&adcConfig, &MODULE_EVADC);
    /* Initialize the module */
    (void)IfxEvadc_Adc_initModule(&g_evadc, &adcConfig);
}

void FastCompare_Init(void) {
	IfxEvadc_Adc_FastCompareChannelConfig config;
	IfxEvadc_Adc_initFastCompareChannelConfig(&config,&g_evadc);
	config.fastCompareChannelId=IfxEvadc_GroupId_14;
	config.channelEventMode=IfxEvadc_ChannelEventMode_aboveOrBelowCompareValue;
	config.serviceRequestGenerationEvent=IfxEvadc_FastCompareServiceRequestGeneration_newResult;
	config.boundaryFlagNodePointer=IfxEvadc_BoundaryFlagNodePointer_sharedServiceRequestLine0;
	config.referenceValue=512; //max 1024
	config.runMode=IfxEvadc_FastCompareRunControl_alwaysRun;
	config.triggerInterval=0; //16/fADC 16/160mhz= 1mhz
	IfxEvadc_Adc_FastCompareChannel fc;
	IfxEvadc_Adc_initFastCompareChannel(&fc,&config);
	IfxSrc_init(&SRC_VADCFC2SR0, IfxSrc_Tos_cpu0, ISR_ADC_PRIORITY);
	IfxSrc_enable(&SRC_VADCFC2SR0);
}
/* ADC Interrupt Service Routine */

IFX_INTERRUPT(ISR_ADC_result, 0, ISR_ADC_PRIORITY);
void ISR_ADC_result(void)
{
	//...interrupt code
 }


bool FastCompare_Get(void) {
	return IfxEvadc_getFastCompareBoundaryFlagStatus(&g_evadc.evadc->FC[2]);
}

 

in main run first AdcGroup_Init(); 

then: FastCompare_Init();

View solution in original post

0 Likes
16 Replies
Di_W
Moderator
Moderator
Moderator
1000 replies posted 250 solutions authored 100 likes received
typedef enum
{
    IfxEvadc_FastCompareServiceRequestGeneration_off       = 0, /**< \brief No service requests are generated */
    IfxEvadc_FastCompareServiceRequestGeneration_rampEnd   = 1, /**< \brief Issue service request when the ramp counter stops */
    IfxEvadc_FastCompareServiceRequestGeneration_newValue  = 2, /**< \brief Issue service request when a value is written to FCREF */
    IfxEvadc_FastCompareServiceRequestGeneration_newResult = 3  /**< \brief Issue service request when a new result available */
} IfxEvadc_FastCompareServiceRequestGeneration;
config->serviceRequestGenerationEvent   = IfxEvadc_FastCompareServiceRequestGeneration_off;

Hi, 

Could you try generate Fast Compare Request Service?   Also refer to AURIX-v1.5.4-workspace\CCU6_ADC_1_KIT_TC397_TFT

0 Likes
IvanoBono
Level 3
Level 3
10 sign-ins 10 replies posted 10 questions asked

hi,

I have already examined the code of the example: CCU6_ADC_1_KIT_TC397_TFT
but it concerns the AD channel group 0:

#define ADC_CHANNEL 0 /* ADC channel number */
#define ADC_GROUP IfxEvadc_GroupId_0 /* EVADC group

on the TC377 I have these groups:

IfxEvadc_GroupId_0 = 0, /**< \brief EVADC Group 0(Primary Group 0) */
IfxEvadc_GroupId_1 = 1, /**< \brief EVADC Group 1(Primary Group 1) */
IfxEvadc_GroupId_2 = 2, /**< \brief EVADC Group 2(Primary Group 2) */
IfxEvadc_GroupId_3 = 3, /**< \brief EVADC Group 3(Primary Group 3) */
IfxEvadc_GroupId_8 = 8, /**< \brief EVADC Group 8(Secondary Group 0) */
IfxEvadc_GroupId_9 = 9, /**< \brief EVADC Group 9(Secondary Group 1) */
IfxEvadc_GroupId_10 = 10, /**< \brief EVADC Group 10(Secondary Group 2) */
IfxEvadc_GroupId_11 = 11, /**< \brief EVADC Group 11(Secondary Group 3) */
IfxEvadc_GroupId_12 = 12, /**< \brief EVADC group 12 (Fast compare channel 0) */
IfxEvadc_GroupId_13 = 13, /**< \brief EVADC group 13 (Fast compare channel 1) */
IfxEvadc_GroupId_14 = 14, /**< \brief EVADC group 14 (Fast compare channel 2) */
IfxEvadc_GroupId_15 = 15, /**< \brief EVADC group 15 (Fast compare channel 3) */

I have already verified that with groups 0-3 and 8-11 I can use:
IfxEvadc_Adc_initGroup
instead with groups 12-15 ("fast compare") it goes into trap.
with the "fast compare" you must use the function:

IfxEvadc_Adc_initFastCompareChannel

but in IfxEvadc_Adc_FastCompareChannelConfig there is no structure to set isr priority  and service provider  like the IfxEvadc_Adc_ChannelConfig:

adcChannelConfig.resultPriority = ISR_PRIORITY_ADC; /* Set the EVADC interrupt priority */
adcChannelConfig.resultServProvider = IfxSrc_Tos_cpu0; /* Set the EVADC interrupt service provider */

 

it seems to me that by setting: 

config->serviceRequestGenerationEvent   = IfxEvadc_FastCompareServiceRequestGeneration_newResult;

it should generate an interrupt when the value changes, but how do I set the interrupt priority and consequently the function it is to perform?

 

0 Likes
Di_W
Moderator
Moderator
Moderator
1000 replies posted 250 solutions authored 100 likes received
IfxEvadc_Adc_initChannel

        IfxEvadc_clearChannelRequest(evadcG, config->channelId);
        IfxSrc_init(src, config->channelServProvider, config->channelPriority);
        IfxSrc_enable(src);

Hi Ivano, 

The interrupt priority is in above funtion.    Below is the struct of ADC channel config. 

typedef struct
{
    boolean                           globalResultUsage;              /**< \brief Specifies storage in global result register */
    boolean                           synchonize;                     /**< \brief Specifies synchronized conversion channel */
    boolean                           rightAlignedStorage;            /**< \brief Specifies result is right aligned */
    Ifx_Priority                      resultPriority;                 /**< \brief Interrupt priority of the result trigger interrupt, if 0 the interrupt is disable */
    Ifx_Priority                      channelPriority;                /**< \brief Interrupt priority of the channel trigger interrupt, if 0 the interrupt is disable */
    IfxSrc_Tos                        resultServProvider;             /**< \brief Interrupt service provider for the result trigger interrupt */
    IfxSrc_Tos                        channelServProvider;            /**< \brief Interrupt service provider for the channel trigger interrupt */
    IfxEvadc_SrcNr                    resultSrcNr;                    /**< \brief Service node of the result trigger */
    IfxEvadc_SrcNr                    channelSrcNr;                   /**< \brief Service node of the channel trigger */
    IfxEvadc_ChannelId                channelId;                      /**< \brief Specifies the channel index */
    IfxEvadc_InputClasses             inputClass;                     /**< \brief Specifies input class selection */
    IfxEvadc_ChannelReference         reference;                      /**< \brief Specifies Reference selection */
    IfxEvadc_ChannelResult            resultRegister;                 /**< \brief Specifies Result register selection */
    IfxEvadc_BoundarySelection        lowerBoundary;                  /**< \brief Specifies lower boundary selection */
    IfxEvadc_BoundarySelection        upperBoundary;                  /**< \brief Specifies upper boundary selection */
    IfxEvadc_BoundaryExtension        boundaryMode;                   /**< \brief Specifies Standard mode of fast compare mode */
    IfxEvadc_LimitCheck               limitCheck;                     /**< \brief Specifies boundary band selection upper/lower */
    IFX_CONST IfxEvadc_Adc_Group     *group;                          /**< \brief Specifies pointer to the IfxEvadc_Adc_Group group handle */
    IfxEvadc_DataModificationMode     dataModificationMode;           /**< \brief Specifies the Data Modification Mode.According to the value entered here, the meanings of values entered for dataReductionControlMode will mean either the number of results accumulated(GxRCRy.B.DMM=0) or filter coefficients(GxRCRy.B.DMM=1). */
    IfxEvadc_DataReductionControlMode dataReductionControlMode;       /**< \brief Depending on the valued of dataModificationMode, the meanings of values in this will differ.For details refer definition of IfxEvadc_DataReductionControlMode enum in IfxEvadc.h */
    IfxEvadc_WaitForRead              waitForReadMode;
    IfxEvadc_FifoMode                 fifoMode;
} IfxEvadc_Adc_ChannelConfig;

 

0 Likes
IvanoBono
Level 3
Level 3
10 sign-ins 10 replies posted 10 questions asked

are you telling me I have to execute:  IfxEvadc_Adc_initChannel also for the fastcompare channel?

the channel that i am using is:

IfxEvadc_GroupId_14 = 14, /**< \brief EVADC group 14 (Fast compare channel 2) */

IfxEvadc_Adc_initChannel needs IfxEvadc_Adc_ChannelConfig.

to create this config i use:

void IfxEvadc_Adc_initChannelConfig(IfxEvadc_Adc_ChannelConfig *config, const IfxEvadc_Adc_Group *group)

this function require IfxEvadc_Adc_Group that can be created with: 

IfxEvadc_Status IfxEvadc_Adc_initGroup(IfxEvadc_Adc_Group *group, const IfxEvadc_Adc_GroupConfig *config)

passing IfxEvadc_Adc_GroupConfig.

but if in IfxEvadc_Adc_GroupConfig I specify "IfxEvadc_GroupId_14" as "groupId" the system goes into trap.

are you sure I need to run "IfxEvadc_Adc_initChannel" for the fast compare channel?
if so, what parameters should I enter in the "IfxEvadc_Adc_ChannelConfig" structure?

0 Likes
Di_W
Moderator
Moderator
Moderator
1000 replies posted 250 solutions authored 100 likes received

Hi Ivano, 

It is not sure, will update to you if I get any information

dw

0 Likes
IvanoBono
Level 3
Level 3
10 sign-ins 10 replies posted 10 questions asked

any news about it?

0 Likes
Di_W
Moderator
Moderator
Moderator
1000 replies posted 250 solutions authored 100 likes received

Hi ivano,

I will keep update with you. Thanks!

 

dw

0 Likes
Di_W
Moderator
Moderator
Moderator
1000 replies posted 250 solutions authored 100 likes received

Hi Ivano,

Please refer to below sample

 

//Include:

#include "IfxEvadc_Adc.h"

#include "IfxSrc_regdef.h"

 

//Define ADC interrupt's priority:

#define ISR_PRIORITY_ADC                4                               /* ADC result interrupt's priority          */

//Define global variable
uint16 g_fastCompareCnt;

//At the begginig of the void FastCompare_Init(void) add following:   

/* Create configuration */   

IfxEvadc_Adc_Config adcConfig;   

IfxEvadc_Adc_initModuleConfig(&adcConfig, &MODULE_EVADC);   **   

/* Initialize module */   

IfxEvadc_Adc_initModule(&g_evadc, &adcConfig);

 

//After IfxEvadc_Adc_initFastCompareChannel(&fc,&config); add following:   

IfxSrc_init(&SRC_VADCFC2SR0, config->resultServProvider, config->resultPriority);   

IfxSrc_enable(&SRC_VADCFC2SR0);

/* ADC Interrupt Service Routine */

IFX_INTERRUPT(ISR_ADC_result, 0, ISR_PRIORITY_ADC);

void ISR_ADC_result(void)

{ g_fastCompareCnt++; }

 

0 Likes
IvanoBono
Level 3
Level 3
10 sign-ins 10 replies posted 10 questions asked

cattura.PNG

It is not possible. as already said before, the "config" structure (type: "IfxEvadc_Adc_FastCompareChannelConfig") does not contain the "resultPriority" element.
the only elements of the structure are:

 

typedef struct
{
    IfxEvadc_Adc                                       *module;
    IfxEvadc_GroupId                                    fastCompareChannelId;
    IfxEvadc_BoundaryFlagActivationMode                 boundaryFlagActivation;
    IfxEvadc_BoundaryFlagInversionControl               boundaryFlagInversion;
    IfxEvadc_BoundaryFlagNodePointer                    boundaryFlagNodePointer;
    IfxEvadc_BoundaryFlagSwControl                      boundaryFlagAction;
    IfxEvadc_ChannelEventMode                           channelEventMode;
    IfxEvadc_ClockDividerFactor                         clockDivider;
    IfxEvadc_ExternalTriggerPolarity                    externalTriggerPolarity;
    IfxEvadc_FastCompareAnalogClockSynchronizationDelay delay;
    IfxEvadc_FastCompareAnalogConverterControl          analogConverterControllerMode;
    IfxEvadc_FastCompareAutomaticUpdate                 automaticUpdateMode; 
    IfxEvadc_FastCompareRunControl                      runMode;
    IfxEvadc_RampRunControl                             rampGenerationMode;
    IfxEvadc_FastCompareServiceRequestGeneration        serviceRequestGenerationEvent;
    IfxEvadc_GateOperatingMode                          gateOperatingMode;
    IfxEvadc_RampDirection                              rampDirection;
    IfxEvadc_SampleSynchronization                      sampleTimingSynchronization;
    IfxEvadc_TriggerOperatingMode                       externalTriggerOperatingMode;
    uint8                                               additionalClockCycles;
    IfxEvadc_ReferencePrechargeControl                  referenceInputPrechargeDuration;
    IfxEvadc_AnalogInputPrechargeControl                analogInputPrechargeDuration;
    uint8                                               triggerInterval;
    uint16                                              referenceValue; 
    boolean                                             boundaryFlagValue;
} IfxEvadc_Adc_FastCompareChannelConfig;

 

i use iLLD version: 1_0_1_13_0__TC3xx,

maybe there is a newer version?

0 Likes
Di_W
Moderator
Moderator
Moderator
1000 replies posted 250 solutions authored 100 likes received

Hi Ivano, 

I have noticed the config has no this member, have you tried add resultServProvider and resultPriority into config's struct?

 

dw_0-1646295430665.png

 

0 Likes
IvanoBono
Level 3
Level 3
10 sign-ins 10 replies posted 10 questions asked

how can you think that by adding members to a structure everything starts to work magically? I have no time to waste making absurd tests.

0 Likes
Di_W
Moderator
Moderator
Moderator
1000 replies posted 250 solutions authored 100 likes received

Hi Ivano,

Because below call is to enable the interrupt service...

IfxSrc_init(&SRC_VADCFC2SR0, IfxSrc_Tos_cpu0, ISR_PRIORITY_ADC);   

IfxSrc_enable(&SRC_VADCFC2SR0);

 

0 Likes
IvanoBono
Level 3
Level 3
10 sign-ins 10 replies posted 10 questions asked

ok, then, without modifying the iLLD structures, after configuring my first example, I just need to add this code:

IfxSrc_init(&SRC_VADCFC2SR0, IfxSrc_Tos_cpu0, ISR_PRIORITY_ADC);   
IfxSrc_enable(&SRC_VADCFC2SR0);

/* ADC Interrupt Service Routine */

IFX_INTERRUPT(ISR_ADC_result, 0, ISR_PRIORITY_ADC);
void ISR_ADC_result(void)
{ 
//.. interrupt code
 }

now I try and post the results..

0 Likes
Di_W
Moderator
Moderator
Moderator
1000 replies posted 250 solutions authored 100 likes received

Hope to work, Ivano.

0 Likes
IvanoBono
Level 3
Level 3
10 sign-ins 10 replies posted 10 questions asked

ok, it works. thank you.
for anyone interested the final c source code is:

 

#define ISR_ADC_PRIORITY 20
IfxEvadc_Adc         g_evadc;

void AdcGroup_Init(void) {
    /* Create configuration */
    IfxEvadc_Adc_Config adcConfig;
    /* Assign default values to the configuration */
    IfxEvadc_Adc_initModuleConfig(&adcConfig, &MODULE_EVADC);
    /* Initialize the module */
    (void)IfxEvadc_Adc_initModule(&g_evadc, &adcConfig);
}

void FastCompare_Init(void) {
	IfxEvadc_Adc_FastCompareChannelConfig config;
	IfxEvadc_Adc_initFastCompareChannelConfig(&config,&g_evadc);
	config.fastCompareChannelId=IfxEvadc_GroupId_14;
	config.channelEventMode=IfxEvadc_ChannelEventMode_aboveOrBelowCompareValue;
	config.serviceRequestGenerationEvent=IfxEvadc_FastCompareServiceRequestGeneration_newResult;
	config.boundaryFlagNodePointer=IfxEvadc_BoundaryFlagNodePointer_sharedServiceRequestLine0;
	config.referenceValue=512; //max 1024
	config.runMode=IfxEvadc_FastCompareRunControl_alwaysRun;
	config.triggerInterval=0; //16/fADC 16/160mhz= 1mhz
	IfxEvadc_Adc_FastCompareChannel fc;
	IfxEvadc_Adc_initFastCompareChannel(&fc,&config);
	IfxSrc_init(&SRC_VADCFC2SR0, IfxSrc_Tos_cpu0, ISR_ADC_PRIORITY);
	IfxSrc_enable(&SRC_VADCFC2SR0);
}
/* ADC Interrupt Service Routine */

IFX_INTERRUPT(ISR_ADC_result, 0, ISR_ADC_PRIORITY);
void ISR_ADC_result(void)
{
	//...interrupt code
 }


bool FastCompare_Get(void) {
	return IfxEvadc_getFastCompareBoundaryFlagStatus(&g_evadc.evadc->FC[2]);
}

 

in main run first AdcGroup_Init(); 

then: FastCompare_Init();

0 Likes
Di_W
Moderator
Moderator
Moderator
1000 replies posted 250 solutions authored 100 likes received

Great

0 Likes