TWR60N512 ADC_LDD problem

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

TWR60N512 ADC_LDD problem

Jump to solution
2,612 Views
georgiad
Contributor III

Hi

I try to read 2 analog channels using PE bean ADC_LDD. I think I set up correctly the inputs  , the sampling group etc in the

inspector. My problem is that I always read only the first channel in the MeasuredValues array. The 2nd is

always 0. If I exchange the index order I read the 2nd channel but always in the first position the 2nd is again 0.

I opened the file AD1.c created by PE and everything seems to be ok. This is the code in the main file:

 

/* MODULE ProcessorExpert */
/* Including needed modules to compile this module/procedure */
#include "Cpu.h"
#include "Events.h"
#include "AD1.h"
/* Including shared modules, which are used for whole project */
#include "PE_Types.h"
#include "PE_Error.h"
#include "PE_Const.h"
#include "IO_Map.h"


/* User includes (#include below this line is not maintained by Processor Expert) */

    LDD_TDeviceData *adcDevData;
    LDD_TError           err;
    #define SAMPLE_GROUP_SIZE  2
    AD1_TResultData MeasuredValues[SAMPLE_GROUP_SIZE];
       
void main(void)
{
  /* Write your local variable definition here */

    adcDevData = AD1_Init(NULL);
  /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
  PE_low_level_init();
  /*** End of Processor Expert internal initialization.                    ***/

  /* Write your code here */
  /* For example: for(;:smileywink: { } */
      AD1_SelectSampleGroup(adcDevData, 0);
      AD1_StartLoopMeasurement(adcDevData);
  while(1){
     // Measure(adcDevData);
   
    while (!AD1_GetMeasurementCompleteStatus(adcDevData)) ;
    AD1_GetMeasuredValues(adcDevData, (LDD_TData *)&MeasuredValues);
  }
  /*** Don't write any code pass this line, or it will be deleted during code generation. ***/
  /*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
  for(;:smileywink:{}
  /*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/

/* END ProcessorExpert */

 

Thanks

Labels (1)
Tags (1)
1 Solution
1,565 Views
ProcessorExpert
Senior Contributor III

Please find attached an example project  configured the way the PDB peripheral is triggering two ADC channels so their measurement is anternating in a loop.

You can tune sampling period and delay between channel in Init_PDB component, using properties: Settings / Clock settings and Channels / Channel to ADC1 / Trigger x / trigger x delay value.

Channels and other ADC options can be chaned in Init_ADC component settings.

Just a note - be careful during debugging - the triggering seems to be sensitive to breaks in debugger so it sometimes stop working after being run after a breakpoint.

 

best regards
Petr Hradsky
Processor Expert Support and Servicepacks Team

View solution in original post

0 Kudos
9 Replies
1,565 Views
ProcessorExpert
Senior Contributor III

 

Hello,

 

please find the enclosed example project which demonstrates measurement of two ADC channels using Software trigger to start measurement.

 

You can find more details about ADC_LDD in the help available using “Help on Component” menu command from it´s pop-up menu.

 

best regards
Vojtech Filip
Processor Expert Support Team

0 Kudos
1,565 Views
drb
Contributor II

thank you so much. this helped me :smileyhappy:

0 Kudos
1,565 Views
georgiad
Contributor III

Dear Filip

Thank you for the fast response.

I tried your example project, modifying slightly the code in order to be able to read 2 channels

but I still can read only one. I suppose that the idea behind sample groups, indexes etc. is that

starting a loop measurement from the first group, you get all groups measurements without the

need for a command for each group. Is this correct? I migrated from TI dsc where you can start

a scan of all inputs defined with a single command.

I attach the example project modified.

Thanks

0 Kudos
1,565 Views
ProcessorExpert
Senior Contributor III

Hello,

Generally, this ADC hardware does not provide direct support for"scanning" through channels using hardware. The ADC_LDD provides only functionality which corresponds to functionality that is supported by ADC device.

In case of normal software triggering, as you may have noticed, it's possible to place only one sample to each sample group. The sample group needs to be switched using SelectSampleGroup method before the measurement, it can be done after each measurement in the event code.

However, the Kinetis family supports a possiblity to use hardware trigger and hold results for two measurements on one ADC - it has  two hardware trigger inputs and two result registers ADC0_RA, ADC0_RB (and also the same set of registers for control of the conversion). This means you are able to measure only two static channels without any additional SW command in case usage of HW trigger. This configuration requires to set "Discontinuous mode" to yes (avaliable in Exper view mode) and configure two Triggers within the Trigger property - it's necessary to add two Init_PDB components and configured their timing. In that case you can start measurement using StartLoopTriggeredMeasurement().

We'll prepare a sample for the triggered option and post it here on the forum.

best regards
Petr Hradsky
Processor Expert Support and Servicepacks Team

0 Kudos
1,566 Views
ProcessorExpert
Senior Contributor III

Please find attached an example project  configured the way the PDB peripheral is triggering two ADC channels so their measurement is anternating in a loop.

You can tune sampling period and delay between channel in Init_PDB component, using properties: Settings / Clock settings and Channels / Channel to ADC1 / Trigger x / trigger x delay value.

Channels and other ADC options can be chaned in Init_ADC component settings.

Just a note - be careful during debugging - the triggering seems to be sensitive to breaks in debugger so it sometimes stop working after being run after a breakpoint.

 

best regards
Petr Hradsky
Processor Expert Support and Servicepacks Team

0 Kudos
1,565 Views
georgiad
Contributor III

Dear Petr

Thanks for the example project. Now I understood who it works. But I have another question. I tried to

start a new project using PE initialization instead of PE. In the MCUinit file comes out an interrupt,

PE_ISR(isr_default) which I don't know where it comes from and what to do with it.

Another question, maybe this is the wrong place, is about MQX. I tried to add the MQX component

in a PE project but I cannot figure out how to use it. There is no documentation about it.

I tried the PE mqx demo which works fine, but how I can create my own project instead of modyfying

this template?

I think that documentation about PE and MQX is very limited and development is done by trial and error.

Thanks

 

0 Kudos
1,565 Views
ProcessorExpert
Senior Contributor III

Hi,

 

The 'isr_default' in MCUinit.c is  an empty interrupt handling routine generated by Processor Expert. All unhandled interrupts are redirected to this ISR. If you are encountering unexpected jumps to this routine, your application is probably enabling some interrupt that is not handled.

 

Regarding MQX - The usage of Processor Expert together with MQX in one project is currently possible only via BSP (Board Support Package) which is a library that provides an interface to the hardware and that can be implemented with use of Processor Expert. If you need to add new components or change component settings, you need to do that in BSP project and re-build it.

 

There is a project inside MQX 3.7 of such Processor Expert enabled BSP for Kinetis TWR-K60 board insed MQX directory ...\Freescale MQX 3.7\mqx\build\cw10\bsp_twrk60n512_pe.

 

Usage of this BSP in application code is demonstrated in pe_demo project in the demo directory: ...\Freescale MQX 3.7\demo\pe_demo

 

Using these project as a start is the best because otherwise you would need to configure many settings if you like to start from an empty project.

You can find some basic instruction also on the forum:

https://community.freescale.com/message/83868#83868

 

I agree that there should be more documentation on this.

 

best regards
Petr Hradsky
Processor Expert Support Team

1,565 Views
ProcessorExpert
Senior Contributor III

Additional note regarding isr_default - The unhandled interrupts are often caused by desiabled Clock Gate. Ensure that settings for peripherals you use that 'Clock Gate' is set to Enabled.

You can see it also in this thread: http://forums.freescale.com/t5/Kinetis-ARM-Cortex-M4/K60-Interrupt-Issue/m-p/69413#M50

 

 

best regards
Petr Hradsky
Processor Expert Support and Servicepacks Team

0 Kudos
1,565 Views
georgiad
Contributor III

Hi Petr

Indeed the problem was the clock gate inizialization. Now it works fine.

By the way the link above is dead.

Thanks for the information about PE and MQX, although I think that the whole

procedure is too complicated and quite a lot "black box" .

Thanks

0 Kudos