generate artificial encoder signal using demo9S12XEP100

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

generate artificial encoder signal using demo9S12XEP100

545 Views
joodaesung
Contributor I

Hello 

I am novice for this microchip controller.

artificial encoder signal will generate 5V clockwise and counter clockwise depending on some sensor through A/D port.

Your  support would be appreciated.

Thanks,

0 Kudos
1 Reply

342 Views
RadekS
NXP Employee
NXP Employee

Hi David,

If I understood correctly, you want to generate two PWM signals with variable phase shift – for example for the driving stepper motor. Right?
Since the temperature signal is changing slowly, I suppose that simplest way will be using two PWM channels (let say Phase A and Phase B).
The phase shift may be generated by temporary increasing or decreasing PWM period at Phase B.
For example: Let’s assume PWM period 200 and both signals aligned, then increasing Phase B PWM period to 202 during 25 PWM periods will generate 90° phase shift (Clockwise rotation).
The PWM module does not generate an interrupt at end of period, however, you may connect Phase A or Phase B into any pin with port interrupt feature and use it for the end of period detection. The advantage of this solution is in fact, that you may enable interrupt only during phase modification – the stable phase shift does not need any interrupt.


Yes, you may use also two timer channels, but implementation will be more complicated (you need to execute 4 interrupt routines for generating complete Phase A and Phase B periods).

In fact, you may use directly GPIO pins for generating that signal as it is described in our older application note AN2974 Quick Start for Beginners to Drive a Stepper Motor:
http://www.nxp.com/files/microcontrollers/doc/app_note/AN2974.pdf

The next option is using external PWM generator like PCA9685 – especially for cases when you need drive more channels:
http://www.nxp.com/products/interfaces/ic-bus-portfolio/ic-led-display-control/16-channel-12-bit-pwm...

About sensor)
You didn’t specify whether you will use analog sensors like PTC, NTC, some active sensor with ratiometric output, or whether you will use a digital sensor with PWM or any other output.
The most typical NTC sensors are connected in series with fix pull-up and ADC module measure voltage at this voltage divider. You may use equations or create look-up-table in the code for translating ADC result into temperature (if necessary).
The PWM signals may be measured by the timer in input capture mode.

The S12XE examples may be found for example at:
https://community.nxp.com/docs/DOC-95116
or at https://community.nxp.com/docs/DOC-329209

I hope it helps you.

Have a great day,
Radek

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos