How to generate a variable frequency of square wave in S12ZVCA?

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

How to generate a variable frequency of square wave in S12ZVCA?

1,016 Views
aaronlee
Contributor V

Hi,

We can generate 500 Hz of square wave to PT7. It can work fine in fixed frequency. How to modify the frequency in my code?

We use  TimeOut component in PE. Is it correct?

How to generate a varible FrequencyHow to generate a varible Frequency

Any we try to add PulseAccumulator component , and using GetCounterValue(), but Counter Value still 0.

Do you have any recommendations?

 

Best Regards,

Aaron

0 Kudos
1 Reply

998 Views
lama
NXP TechSupport
NXP TechSupport

Hi,

When you use timer then you need to always calculate a value for another OC event and the new value to the TC register. Then there are two ways how to toggle the pin... toggle on OC event automatically or toggle pin manually in the interrupt . As you can see this freq can vary in both cases if happens that interrupt with higher frequency is served before toggle is performed (if manual toggling approach is used) and change of a new OC is enabled.
I believe you are able to perform analysis of all possible issues when the frequency can be influenced.

The PE uses toggle pin on OC event automatically so it calculates always a new value for another OC event using value corresponding a half period because duty cycle is 50%.

You see in the code something like this:

#pragma CODE_SEG __NEAR_SEG NON_BANKED
ISR(TO1_Interrupt)
{
TIM0TC7 += 0x89U; /* Add value corresponding with period */
TIM0TFLG1 = 0x80U; /* Reset interrupt request flag */
}

#pragma CODE_SEG TO1_CODE

This part of the code sets a new event.
TIM0TC7 += 0x89U; /* Add value corresponding with period */

so you can modify it to

TIM0TC7 += my_halfperiod; /* Add value corresponding with period */

where my_halfperiod is a global variable created by you this purpose. (note, it is possible the modification will be reset if you run the code creation). Because of this, my personal advice, the PE is not good to be used in mor complex project where additional impacts are require. PE, however, can be as a helper using extra project how to do something and as well as source code generator which we use a modify in our extra project.

Finally, I have processed the answer only theoretically and have not tested it.

Let’s add additional function into a interrupt function – picture above shows also result in the code.

Best regards,

Ladislav

0 Kudos