ADC Conversion- Event Based for MPC5744P

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

ADC Conversion- Event Based for MPC5744P

1,247 Views
abhishek_kumar1
Contributor IV

Hello All

I would like to use ADC conversion which is triggered by an event. (FlexPWM ->  Programmable Delay -> ADC)

So, This is what I want to achieve in MPC5744P (Model Based Design Toolbox)

pastedImage_1.png

I see in the MDB toolbox that events are triggered for "End of Conversion" but I can not find where do I use an External trigger for start of sampling. Please see my try below.

pastedImage_1.png

Inside the triggered ADC Phase A block (below)

pastedImage_2.png

Please help on this topic.

Kind Regards

Abhishek

5 Replies

791 Views
mariuslucianand
NXP Employee
NXP Employee

Hello abhishek.kumar@chassisbrakes.com‌,

Sorry for our delayed answer.

For the MPC5744P the Programmable delay is achieved using the Cross-Triggering Unit (CTU). So for more information please read the Chapter 41 from the MPC5744PRM.pdf.

Now, to be more helpful I have attached an example that converts two ADC channels triggered by the PWM blocks on a channel's rising edge. Because I have tested the example on the MPC5744PDevKit, I used the ADC 1 module and other pin to have access to a potentiometer, but for your need the workflow is the same.  

I started adding a Complementary PWM Output block to generate a 25Hz PWM signal. For some visual feedback I also added the Green LED to blink every second. 

2.JPG

Now, the CTU Block has the Input Selection configured to have the PWM channel 0 odd on Rising event. Here you can select which action will launch the conversions. in our case, the Triggered 0 ADC command was enabled. 

 3.JPG

In the same mask(CTU configuration), but in the ADC Commands tab, the ADC commands number was set to 2, it your case it will be 3. Also, the channels on which the conversion will be started are set here: in our case 6 and 11. Also, in the ADC Config block the CTU checkbox was set.

5.JPG

Now, the ADC interrupt was added to be triggered at the End of CTU conversion. In this handler, the converted values from the channel 6 (the one on which the potentiometer is connected on the evaluation board) and the channel 11 (randomly selected) are read into the value_A and value_B.

I also added a FreeMASTER connection to the board to see in real time the converted values. Here, the Red LED is toggled every time also for a visual feedback. 

Attached to this replay you can find the model and the freeMaster files on which we tested the program explained above. 

Hope this helps you!

Best regards,

Marius

791 Views
smuley
Contributor III

Hello Marius,

I am trying to implement the exact opposite process using model based design. I want to read the ADC as fast as possible and generate PWM with variable duty cycle. For eg. the input to the ADC is a 200Hz sine wave, i am dividing the ADC output by 4096 to get the duty cycle between 0 and 1 and providing it as an input to the FlexPWM generator block. But when i check the output on the Oscilloscope the duty cycle of the output PWM signal changes extrmely slowly as compared to the change in the input sine wave. I checked the output of the ADC and that seems to be updating according to the input wave. I also tried to implement it using ADC interrupt but got the same result.

Please let me know if there is another way to implement it.

Below is my current setup.

1) pastedImage_1.png

2) pastedImage_2.png

Inside the ADC ISR Handler:

pastedImage_3.png

Please let me know.

Thanks and regards,

Saurabh

0 Kudos

791 Views
mariuslucianand
NXP Employee
NXP Employee

Hello smuley@tae.com‌,

From the screenshot you have attached, it seems like you started from our adc_isr_mpc574xP example model and is easier for me to have a discussion based on that. 

So the model works like this: the ADC Start block is called on the step, which is set at 0.1 seconds. 

pastedImage_1.png

After the conversion is complete the ADC ISR block is called. So for the beginning, the conversions are performed at each 100ms. 

Now, you have multiple approaches to get conversion after conversion, or to get conversions at specified sample time:

1. You can try using the "Scan" conversion mode "a specified sequential conversion is continuously performed"

pastedImage_2.png

2. If 1 is not working, you can also add the ADC Start block inside the ADC ISR S-function but be sure that it will be called after the PWM block (you can use lower block priority) and also you should have an ADC start block at the beginning of the model.

3. IF you need a specific sample time for the ADC conversion, you can use a PIT interrupt to call the ADC start block at the sample time you need.

Hope this helps,

Marius

0 Kudos

791 Views
abhishek_kumar1
Contributor IV

Dear smuley@tae.com‌ 

The idea is to use the latest value of ADC and do some calculation and update the PWM (I think, this is what you want). If you want to discretize the Sine wave at 200Hz. Choose a PWM switching frequency (20000 Hz will get you 100 sample in one sine wave). From then, it remains the same. You can Synchronize PWM -> CTU->ADC. It does not matter as on PWM side you will receive the latest ADC value. 

I hope this helps. 

0 Kudos

791 Views
abhishek_kumar1
Contributor IV

Dear Marius,

I'll implement it and share lessons learnt for others!

Thank you very much.

Regards

Abhishek

0 Kudos