To use ADC by CW 10.2 Processor Expert

cancel
Showing results for 
Search instead for 
Did you mean: 

To use ADC by CW 10.2 Processor Expert

Jump to solution
3,206 Views
WGH
Contributor I

Hi ,

I'm designing an ADC input in K40N256 with TWR-K40X256 board . And I create a project by CW 10.2  Processor Expert .

I create  a ADC component and initial it . But how to read the ADC convert result ?  Is there any example project for it ?

Channel - AD1DM1

 

 

Labels (1)
Tags (1)
0 Kudos
1 Solution
388 Views
ProcessorExpert
Senior Contributor III

Hi,

 

please find attached a demo project for Kinetis Kwikstik board (using K40).

This demo project is created with use of Processor Expert and it's Peripheral Initialization Components.
Microphone signal is periodically sampled and displayed on the display.

ADC is periodically triggered for  8 kHz (Influenced by Init_PDB period setting).
The ADC (ADC0, channel 10) results are read and automatically stored using DMA into a memory buffer so the CPU is informed after the buffer is full and doesn't have to care for reading each value individually.

 

best regards

Petr Hradsky

Processor Expert Support Team

 

View solution in original post

0 Kudos
11 Replies
388 Views
ProcessorExpert
Senior Contributor III

Hi,

Could you be more specific what component do you use ? ADC_LDD or Init_ADC ?

 

Anyway, if you are using ADC_LDD there are generated functions(methods)  that you can use. Please see the Typical usage page of the documentation. It's accessible via pop-up menu for the component by selection the command "Help on component" and in the page that opens  select the link "Typical Usage".

 

I you are using Init_ADC, you need to access the ADC registers directly according to the K40X256 manual.

 

best regards
Petr Hradsky
Processor Expert Support  Team

 

0 Kudos
388 Views
jordimerc
Contributor II

Hi all,

 

By the way I'm also using the same ADC_LDD but my problem is that I'm doing an audio application and I must set the sampling freq exactly to 16kHz, 

I have to set an external counter to set the exactly freq or could it be done using the differrent properties of the component

 

Br's

Jordi

 

0 Kudos
389 Views
ProcessorExpert
Senior Contributor III

Hi,

 

please find attached a demo project for Kinetis Kwikstik board (using K40).

This demo project is created with use of Processor Expert and it's Peripheral Initialization Components.
Microphone signal is periodically sampled and displayed on the display.

ADC is periodically triggered for  8 kHz (Influenced by Init_PDB period setting).
The ADC (ADC0, channel 10) results are read and automatically stored using DMA into a memory buffer so the CPU is informed after the buffer is full and doesn't have to care for reading each value individually.

 

best regards

Petr Hradsky

Processor Expert Support Team

 

View solution in original post

0 Kudos
388 Views
greglapin
Contributor I

You say "please find the attached demo project..."

I don't see the attachment.

Would you please tell me how to get it?

Thanks,

Greg

0 Kudos
388 Views
Petr_H
NXP Employee
NXP Employee

Unfortunately, the attachment has disappeared when old forums were migrated.

Please find it attached to this post.

best regards

Petr Hradsky

Processor Expert Support Team

0 Kudos
388 Views
DustyStew
Contributor V

Surely there is a register to write to trigger a conversion, a bit to poll for end-of-conversion, and a data register to read. Just trying to verify hardware at this stage, need the simplest way to do a conversion.

0 Kudos
388 Views
BlackNight
NXP Employee
NXP Employee

Here is a tutorial which might be useful:

Tutorial: ADC with the Freedom Board

I hope this helps.

0 Kudos
388 Views
DustyStew
Contributor V

Erich

Yes I found your blog post, awesome. That is good documentation. It just works. You rock. I tried the other two ADC components (init & LDD), couldn't figure out what to do with them, there seemed to be no API for getting a value. I spent 2 hours on that. Then 10 minutes with your tutorial and had it going.

One point that is not absolutely clear is how to get multiple values. It seems you are meant to pass the address of an array, and the values for each channel are stored sequentially. Kind of a dangerous way of doing things. It would make more sense to pass a channel number.

0 Kudos
388 Views
Petr_H
NXP Employee
NXP Employee

Hi,

you can also find simple examples of code for using a component on the "Typical usage" page accessible from help of each component. You can get this help using component pop-up menu command "Help on component" and then click the "Typical usage" link in the left side of the help pages.

I'm not sure what do you mean by passing a channel number, but if the component should return the numbers of channels, this would be quite a wasting of memory space, if you application knows the order of channels. RAM is usually quite limited resource in embedded system...

best regards

Petr Hradsky

Processor Expert Support Team

0 Kudos
388 Views
DustyStew
Contributor V

Petr

I am suggesting a better API would have a function something like

word AD1_GetValue16ByChannel(int channel);

which would return the value of the measurement for the particular ADC channel. This function is safe. It's just your basic "getter" function.

Whereas passing a pointer (as in the current implementation) requires that the caller has allocated a buffer of suitable size. If the buffer is too small, you have a problem.

I disagree about saving RAM, I think the current implementation would use more RAM, as the measurements are being buffered both in the driver and in the application code.

0 Kudos
388 Views
jordimerc
Contributor II

Thanks for your help Petr, it has been very helpful!!!

 

BR's

 

Jordi

0 Kudos