K60 ADC PDB relation

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

K60 ADC PDB relation

3,432 次查看
mehmetekici
Contributor II

Hello,

I have recently started to work with K60. I have been looking MQX ADC driver but unfortunatly I find it extremely complicated to be understood.

Would someone please describe how PDB works and it is relation to the ADC?  I really think it could have been very simpler to have an ADC to run. I read the related documentation two times already.

Regards,

标签 (1)
标记 (3)
0 项奖励
6 回复数

866 次查看
aloblaw
Contributor II

Hopefully I can shed some light on the pre-trigger and trigger.

First, I would suggest looking at the PDB Block diagram, as this really explained things for me.

The PDB0_MOD is used for overall timing of the PDB block or how long it takes for the PDB to restart (if in continuous mode).

The pre-trigger delay values are for individual timing of the channel triggers (e.g. ADC0-SC1A, ADC0-SC1B, ADC1-SC1A, ADC1-SC1B, etc.). The values of these delays MUST be less than or equal to the MOD value otherwise they will never activate.

To clarify:

In one-shot mode, the value of MOD is almost completely irrelevant since the actual timing of the pre-triggers are defined by their own pre-trigger delay. Just as long as the pre-trigger delays are less than the MOD value.

In continuous mode, the MOD value defines how frequently the whole cycle of pre-triggers repeats.

Also, if it wasn't clear, there is an input trigger that starts the PDB block. This can come from a bunch of different modules but I usually just set the PDB0_SC software trigger once to start it and leave it running in continuous mode.

One thing I struggled with for a bit: the bypass mode of the pre-triggers completely ignores any timing as soon as an input trigger is received. If you are in continuous mode, this means that the trigger will re-issue (with a 2 cycle delay) indefinitely after each ADC conversion is completed, which is almost always undesirable behaviour. I'm not really sure what the point of the bypass feature is. Maybe somebody can clarify?

0 项奖励

866 次查看
SortoVaritu
Contributor III

Hello. Meybe this code can help you:

SIM_SCGC3|=SIM_SCGC3_ADC1_MASK;    //enable clk for adc

ADC1_CFG1|=ADC_CFG1_ADIV(3)|ADC_CFG1_MODE(3);//clk/8, 16-bit mode

ADC1_SC2|=ADC_SC2_ADTRG_MASK;//hardware trigger

//ADC1_SC3|=ADC_SC3_ADCO_MASK;//continous mode

ADC1_SC1A=ADC_SC1_AIEN_MASK|ADC_SC1_DIFF_MASK|0x01;//interrupt on, chanell 1

   

   

SIM_SCGC6|=SIM_SCGC6_PDB_MASK;

PDB0_SC=PDB_SC_PDBEN_MASK|PDB_SC_CONT_MASK|PDB_SC_PDBIE_MASK|PDB_SC_TRGSEL(15)|PDB_SC_LDOK_MASK;//enable pdb, continous mode, software trigger

PDB0_MOD=9600;

PDB0_CH1C1|=PDB_C1_EN(1)|PDB_C1_TOS(3);

PDB0_SC|=PDB_SC_SWTRIG_MASK|PDB_SC_LDOK_MASK;   //software trigger (start PDB)
0 项奖励

866 次查看
mehmetekici
Contributor II

Hi Dimitry,

Thanks for the information.  PDB is a seperate module so that we can configure that to have trigger outputs at cirtain times.

As in your program example you have configured the PDB channel 1 to generate a trigger but you didn't provide a delay for the trigger time. I assume you did it and forget to put here.

You have also configured the PDB to generate interrupt. What actions you take in the ISR? to trig PDB again ?

Here are my confusing points may be you can help me understood.

- There is a term "pre-trigger" and trigger. I can not differentiate them and don't understand them. Actually documentation says trigger is asserted after two peripheral clock later than pre-trigger.

-  Assume a trigger or pre-trigger fired and ADC started a convertion cycle. PDB will continueu to count and will generate another trigger after some time. ADC at the same time does his job and finishes convertion. If a new trigger happens before ADC finishes the convertion, or even if ADC finishes and result register not read and PDB triggers for a second time  etc.

As in your example probably you would get many trigger events before ADC completes a convertion.

- Can I use ADC module without PDB ? I would set up an ISR for ADC and read the previous result then software trigger a new convertion.

-  Configuring more than one channell is even much more confusing. I don't know if  one can give a usefull example for usege of it ?

Regards,

0 项奖励

866 次查看
SortoVaritu
Contributor III

Hi Mehmet!

I also cant clearly understand about pre-trigger and trigger. Right now im trying to find a relationship.

As in your program example you have configured the PDB channel 1 to generate a trigger but you didn't provide a delay for the trigger time. I assume you did it and forget to put here.


I did it like this
PDB0_MOD=9600;

You have also configured the PDB to generate interrupt. What actions you take in the ISR? to trig PDB again ?

No. I configured PDB to work in continuous mode:

PDB0_SC=PDB_SC_PDBEN_MASK|PDB_SC_CONT_MASK|PDB_SC_PDBIE_MASK|PDB_SC_TRGSEL(15)|PDB_SC_LDOK_MASK;

You can switch-off interrupt if you want.

Assume a trigger or pre-trigger fired and ADC started a convertion cycle. PDB will continueu to count and will generate another trigger after some time. ADC at the same time does his job and finishes convertion. If a new trigger happens before ADC finishes the convertion, or even if ADC finishes and result register not read and PDB triggers for a second time  etc.

As in your example probably you would get many trigger events before ADC completes a convertion.

- Can I use ADC module without PDB ? I would set up an ISR for ADC and read the previous result then software trigger a new convertion.


ADC must complete conversion before PDB trigger will be fired next time. If you want to get the maximum speed of ADC you can run ADC in continuous mode and no need to use PDB. Also you can configure ADC to work with DMA and in this case no need to use ADC interrupt for data collection.

0 项奖励

866 次查看
mehmetekici
Contributor II

Are you sure that PDB will wait for the ADC to complete the conversion to trig again ?

The PDB has got sequencing error flags has to be dealt with in these cases. I didn't understand them as well.

I have read in another  thread ADC and DMA has problems to wortk together. Did you run any examples of ADC and DMA ?

If yes would you please reveal a simple project for TWR-K60DN512 kit so that we can execute too.

Regards,

0 项奖励

866 次查看
SortoVaritu
Contributor III

Are you sure that PDB will wait for the ADC to complete the conversion to trig again ?

No. PDB will not wait.You need to calculate timings. PDB trigger events  time should be more then conversion time of ADC. In other case no sense in PDB - you can run ADC in continuous mode.

In my example:

PDB0_MOD=9600; If PDB clock source is 48Mhz(~21ns)  - 21ns*9600=201,6 us.

But you can set clk divider for input clock ADC1_CFG1|=ADC_CFG1_ADIV(3).

I have read in another  thread ADC and DMA has problems to wortk together. Did you run any examples of ADC and DMA ?

I have read it also and researcher reported that this problem was resolved in MQX 3.8.1 version.

Sorry but i do not have useful example for ADC and DMA. But i also want to use it in my project. If i will face with some problems or incorrect work - i will use simple ISR. It will take more resources from CPU but also will work.

0 项奖励