Flag terminate compute operation

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

Flag terminate compute operation

Jump to solution
562 Views
Transidico
Contributor II

Hello,

I am using the frdm-mcuxc242 board and I would like to know how I can know if a certain operation has been performed.

For example:  If I have to do the sum between two variables A and B and it gives me result C (A+B=C) how can I know if the operation has been performed and finished before reading the result of the variable C?

Is there a computational operation performed interrupt flag? Or can I know how many clock cycles my operation takes? 

Thank you.

Regards

0 Kudos
Reply
1 Solution
503 Views
Pablo_Ramos
NXP Employee
NXP Employee

Hi @Transidico.,

Analyzing the code you share, one option that could be happening is that ADC has not finish the conversion when the calculation is being made, what I recommend you is to check the SDK example for ADC, adc16_interrupt and adc16_polling, in this examples it shows two options in order to wait the ADC to finish the conversion. In this way you can assure that the ADC has the value of the current voltage on the pin.

Pablo_Ramos_0-1744306261083.png

Best Regards,
Pablo

View solution in original post

0 Kudos
Reply
3 Replies
545 Views
Pablo_Ramos
NXP Employee
NXP Employee

Hi @Transidico,

You can calculate the clock cycles required for the operation with the assembly instruction.

MCUXpresso has the option to see the assembly instruction required for each line in C

Pablo_Ramos_0-1744136989528.png

The instruction will appear while debugging.

Pablo_Ramos_2-1744137015557.png

On the core documentation you should be able to find the number of cycles spend on each instruction.

Cortex-M0+ Technical Reference Manual r0p1

However, I suggest you double check directly with ARM to ensure performance on each instruction.

Best Regards,

Pablo

 

0 Kudos
Reply
530 Views
Transidico
Contributor II

Good morning pablo,
thank you for your reply and the documentation sent. I found how many clock cycles my instruction takes. I am sampling an input signal from pin A0 of the adc at 1ms and I noticed that if I don't put a delay of about 100uS, as you can see in the attached program, the first calculations I get are not accurate. I don't know if I have to put a delay every time I perform an operation, I don't think so because it would affect the timing. I don't know if the delay I am putting in is correct and there is a better way to put it in. Also, I have seen that it is possible to use MSDK_EnableCpuCycleCounter() and MSDK_GetCpuCycleCount() to read the number of cycles the program is doing, but if I implement them in my code it gives me an error. Could you give me some advice?

 

0 Kudos
Reply
504 Views
Pablo_Ramos
NXP Employee
NXP Employee

Hi @Transidico.,

Analyzing the code you share, one option that could be happening is that ADC has not finish the conversion when the calculation is being made, what I recommend you is to check the SDK example for ADC, adc16_interrupt and adc16_polling, in this examples it shows two options in order to wait the ADC to finish the conversion. In this way you can assure that the ADC has the value of the current voltage on the pin.

Pablo_Ramos_0-1744306261083.png

Best Regards,
Pablo

0 Kudos
Reply