Hello Gaston,
I have analyzed you application and I have found out following issues:
- The hard fault exception (CPU_Interrupt subroutine) is caused by unitialized pointer in your application. You are using AD1_DeviceDataPtr pointer that is initialized in the appInit() function but the TU1 component is intialized in the PE_low_level_init (timer is enabled). The TU1_OnCounterRestart is invoked before the AD1_DeviceDataPtr is initialized (null pointer exception). Therefore you must disable the timer in the initialization (set the Enabled in Init. Code property to no) and call TU1_Enable() method after the AD1_DeviceDataPtr pointer is initialized in the acqInit() function.
- The AD1 component (driver) initialization is executed twice in your application. There is enabled autoinitialization in the AD1 component (the Autoinitialization property is set to yes; the AD1_Init() is called in the PE_low_level_init()) and you also call AD1_Init() function in the acqInit() function. If you want to use the AD1_DeviceDataPtr you can just do assignment AD1_DeviceDataPtr = AD1_DeviceData; (AD1_DeviceData is macro defined in the AD1.h and it provides initialized pointer to device data).
See for example you code in the Event.c:
void TU1_OnCounterRestart(LDD_TUserData *UserDataPtr)
{
/* Write your code here ... */
word i;
LDD_TError Error;
. . .
Error = AD1_SelectSampleGroup(AD1_DeviceDataPtr, 0U);
Error = AD1_StartSingleMeasurement(AD1_DeviceDataPtr);
while ((ADC_PDD_GetConversionCompleteFlag(ADC_BASE_PTR, NULL)) == FALSE);
AD1_Main(AD1_DeviceDataPtr);
while (!AD1_GetMeasurementCompleteStatus(AD1_DeviceDataPtr)); // Wait for conversion completeness
AD1_GetMeasuredValues(AD1_DeviceData, acqValueGroup0);
acqValueGroup0[0] -= 2047;
. . .
I.e. you use AD1_DeviceDataPtr pointer and AD1_DeviceData macro in one function (the same pointers).
I have fixed your application, see the attached archive. I have also checked the you can measure any sample group in the TU1_OnCounterRestart() event, i.e. you can call
Error = AD1_SelectSampleGroup(AD1_DeviceDataPtr, 0U);
or
Error = AD1_SelectSampleGroup(AD1_DeviceDataPtr, 1U);
Both sample groups can be measured in this event.
I see also another synchronization issue in your application. There are measurement executed in an interrupt (TU1_OnCounterRestart() event) and in the main process - acqProcess() function. I am not sure but it seems to me that these measurement are not synchronized. i.e. you must ensure that acqProcess() function (measurement of the AD1 channels) is not interrupt by TU1 interrupt (TU1_OnCounterRestart() event call). Otherwise AD1 results can corrupted.
Best Regards,
Marek Neuzil