MBD SPI problem based MPC57**

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

MBD SPI problem based MPC57**

1,710 Views
haoxue1027
Contributor IV

Hello,community

Now I have  a trouble with the MBD SPI based MPC5744P-dev.

I want to use the stateflow to read the position of resolver of motor by SPI.

I did the stateflow like following which refered to the AD2s1205 referrence.

but it does work. Can you help me find the problem of the SPI configuration or modeling errors?

1,the problem of SPI configuration

pastedImage_1.pngpastedImage_3.png

here, I did choose the PSCn . beacuse I will control the CS port reading time later . When i set the PCS here, there is an error occuring.  Can you tell me if  this configuration is OK ?

2, According to the "Power Supply Sequencing and Reset" and"Serial Port Read Timing" 

pastedImage_4.pngpastedImage_5.png

I used the pit to trigger the stateflow like following. I used various methods to debug the positiong only , but the SO and CLOCK signals of ad2s1205 were always wrong, Can you help me check it ?

Any suggestions will be appreciated。

pastedImage_6.pngpastedImage_7.png

pastedImage_8.pngpastedImage_9.png

thank you very much.

best regards

hao

0 Kudos
12 Replies

1,501 Views
haoxue1027
Contributor IV

hello,constantinrazvan.chivumariuslucianandrei

Razvan,Marius,

I'm sorry to bother you, but could you spare me a moment to help me with this problem?

thank you very much.

best regards

hao

0 Kudos

1,501 Views
constantinrazva
NXP Employee
NXP Employee

Hello haoxue1027@qq.com,

Sorry for the late reply -- can you let me know how you control the timing for the CS? I'm asking this because when you are using the SPI Transfer block displayed in that image, that transfer would start right there. If you don't have the timing right for the CS and you start clocking out your data just before CS is active, you won't get a valid SPI frame sent over to your slave (the AD2S1205). I would suggest (if your application permits it) to choose a CS pin and let the transfer block handle all signals (CS, clock and data).

Kind regards,

Razvan.

0 Kudos

1,501 Views
haoxue1027
Contributor IV

Hello constantinrazvan.chivu

Thank you  for your suggestions.

In the hardware , CS and RD two pins are short circuited. So I have to control them together by GPOPTF4.

The CS_RD time is controlled by the stateflow like above figure. Every state change will cost the one cycle of PIT(100us). If I set the SPI-config like this,pastedImage_2.png.

Block error occurs like following:

 Pin check failed on block 'ADC_test20200723SPI/Speed_Measure /CS1_RD'. Pin is shared with other module: 'ADC_test20200723SPI/SPI_Config'.

Can I need to  close the SPI diagnostic in the  MBD_MPC574x_Config_Information→diagnostics?

In additon,  can you help me check if the SPI configuration is right according to the AD2s1205 timing?

pastedImage_4.png

thank you very much.

best regards

hao

0 Kudos

1,501 Views
constantinrazva
NXP Employee
NXP Employee

Hello haoxue1027@qq.com ,

I haven't got a chance to look at the AD2S1205 manual, so I'm not sure what RD signal is used for. Now I understand what problem you were talking about with the configuration block. Well that error you are getting is stating that you can't have that output pin with dual functionality - both SPI CS and GPO, so this would be the correct behavior - throwing an error. Before I get to take a look at that manual you should decide if you really need to control it from the GPO block.

Kind regards,

Razvan.

0 Kudos

1,501 Views
haoxue1027
Contributor IV

Hello constantinrazvan.chivu

In my opinion, PCSx  in the configuration is for the master 5744P, while in this application, 5744P only receives SPI signals from slave AD2S1205, so whether PCSx can be arbitrarily selected or not(except PTF4), and CS_RD which is  PCS  pin of  AD2S1205  needs to be configured for timing sequence, so it is used as GPO  port.

Now I changed the baud rate to 1M bps , and set the PCS1 as PTC12.

I can capture the SCLK and  SO signal in the hardware.  but  I can read any SPI SO data by the freemaster.

pastedImage_4.png

pastedImage_6.png

pastedImage_5.png

Can you help me check whether the signal in the figure is right or not.

Why can't I get the data in the freemaster?

thank you very much.

best regards 

hao

0 Kudos

1,501 Views
constantinrazva
NXP Employee
NXP Employee

Hello haoxue1027@qq.com ,

hao xue wrote:

Hello Constantin Razvan Chivu

In my opinion, PCSx  in the configuration is for the master 5744P, while in this application, 5744P only receives SPI signals from slave AD2S1205, so whether PCSx can be arbitrarily selected or not(except PTF4),

I want to make one remark here - it does not matter if the MPC5744P is only receiving messages from the slave, it is still the one that triggers the transfer, being the master - in SPI communication this is the one that sends out the clock and CS signals. Without those, there will be no transfer started over SPI. This is the reason why I was suggesting you use the CS from the SPI block. 

Now regarding the signal, I still haven't gone through the manual for AD2S1205 -- but can you send me a screenshot from your osciloscope with the CS, clock and data? Or if you only have 2 channels, you can send CS and clock.

Kind regards,

Razvan.

0 Kudos

1,501 Views
haoxue1027
Contributor IV

Hello,constantinrazvan.chivu

Thank you very much for replying.

In the following picture, the Ch1 is CS, the Ch2 is clock,the Ch3 is data.

I captured the singals at two different positons of the motor rotor.

Please confirm it.

pastedImage_1.png

pastedImage_1.png

But , I can read any data in the freemaster.

pastedImage_1.png

best regards

hao

0 Kudos

1,501 Views
constantinrazva
NXP Employee
NXP Employee

Hello haoxue1027@qq.com,

Maybe you should take a look at how you calculate THETA - you must be careful at what data types you set in the blocks you use for this. For example, I see you have a gain block that has a uint16 input and outputs a uint32, but the value for the gain is 2*pi/4096. If the data type of this would be any integer type, you will get 0 as output.

After you have made sure all the calculations are done correctly (with corresponding data types used), if it still shows 0 as value in FreeMASTER, you should watch the SPI raw data that you get, an calculate by hand to see if you get an accurate value.

Hope this helps,

Razvan.

0 Kudos

1,501 Views
haoxue1027
Contributor IV

Hello,Razvan,

Thank you for replying.

I am still confused to the  If the data type of this would be any integer type, you will get 0 as output.

Can you explain it further?

Thank you very much.

best regards

hao

0 Kudos

1,501 Views
constantinrazva
NXP Employee
NXP Employee

Hello haoxue1027@qq.com,

Sure - you can see in Simulink simulation or you can even try in MATLAB terminal the following:

value = 2*pi/4096  % this will give you the output 0.0015, if no data type is specified; this is because it will default to double as it's data type.

If you were to get this value and cast it to an integer (let's say int32), you will get the value 0. You can try by going further in the MATLAB terminal with:

int32(value) % This will produce the output 0

Now going back to your example, I see the output of the gain block is an integer, so that might be a problem for you. 

To make it easier, I would do the following:

start off a new model, only for simulation purposes. Get two constant blocks (instead of data you get on the SPI), and copy the rest of the blocks you use for getting the THETA value from the raw data. Think what you would get as values from the sensor if the angle was some value you choose, and write those values to the constant blocks (just as you received them over SPI). Then start the simulation and see what THETA outputs. You will change these blocks until you make it output the correct value for the angle. Once you have tested this thoroughly, just copy those blocks and get them back in your first model. Now you can go onto the hardware and see if it works. 

Kind regards,

Razvan.

0 Kudos

1,501 Views
haoxue1027
Contributor IV

Hello,Razvan

Thank you for your explaning.

Now,I think the failure reason of SPI is that Stateflow timing.

As the AD2S1205 SPI needed for strict timing requirements, the stateflow seems cannot satisfy that condition.

Error occurred when using oscilloscope to measure pin signal,

pin signal of AD terminal(voltage level:5V) is as follows,  the level of voltage and the 8th clock singal is abnormal.

pastedImage_2.png

I used 2K and 1K resistance to divided,  pin signal of 5744 terminal(voltage level:3V3) is as follows, the SO data is abnormal.

pastedImage_3.png

 I'm confused about this question now, Can you give me a  suggestion?

Thank you very much.

best regards

hao

0 Kudos

1,501 Views
constantinrazva
NXP Employee
NXP Employee

Hello again haoxue1027@qq.com ,

In terms of CS selected in the configuration block, that should not throw any error - just that it will not initialize any pin to be used as SPI CS. Note that for you to set which CS you are using for your transfer, this will be set in the transfer block. So you'll have to set-up which pin you use from the Configuratin block (pins tab), and which you'll be using (index) from the transfer block. This is done in order for the users to be able to send messages to multiple slaves.

Kind regards,

Razvan.

0 Kudos