Reply by Edward Karpicz●October 13, 20082008-10-13
> Im trying to use input capture to sense the rising
edge from the encoder.
> It seems like my program cant go into the interrupt function. After i
> sense 100 times rising edge, i set ptm.0 to be 1. Im using channel 5 as
> input capture.
>
> void interrupt TIC5 (void)
> {
> int i;
i is not static and you don't initialize it. So i is probably random!
Reply by leonardo_u3000●October 13, 20082008-10-13
Here is my code for Reading Motor's Speed , use PulseAcc-A and TOC2
+> TOC2 make a Timer Interrupt 20ms
+> PulseAcc-A detect Rising Edge, PulseAcc-A connect with pin-PT7.
I use CodeWarrior 4.7- Special Version.
#include /* common defines and macros */
#include /* derivative information */
#include
#include "pll.h" /* Use PLL --> Bus Clock: 24Mhz/
#include "SCI0.H"
#pragma LINK_INFO DERIVATIVE "mc9s12dp512"
//------------ GLOBAL VARAIBLE --------------//
int count_pulse,count=0 ,speed_temp=0 ,speed_exac=0 ;
unsigned char ngan,length,index=0;
int toc_do_dat= 80,toc_do_do ,prior_OCR0@,set_speed = 2400;
int bnn_ET[3],bnn_DET[3]; // for Fuzzy-Rule-Table
int u[3][3];
signed int ET,DET,ss_cu = 0,ss_moi = 0 ;
float temp_value, temp_add ;
signed int Kp,Ki,alpha,Kd, du ; //PID varaible
I hope you would success.
Regards,
Minh Thao(HoangLongU)
-------
VietNam National University
University of Technology, Ho Chi Minh city
Automatic Control Deparment.
Reply by chai...@hotmail.com●October 12, 20082008-10-12
Im using it to control the motor speed and know the direction of rotation.
Can you send me the code or post it here?
Thanks for your help
Reply by leonardo_u3000●October 12, 20082008-10-12
When you want to read Encoder's Pulses ( --> R.P.M) , you can use
HCS12's PulseAcculator.
HCS12 have two 16bit-PulseAcculators : PulseAcc A (PT7) , PulseAcc B
(PT0) or four 8bit- Pulse Accs.
Method for read Encodef's pulses:
+ Enable PulseAcculator A ( Detect rising Edge or Falling Egde)
+ Enable Timer and use Interrupt ( example TOC2 )
+ When Timer Interrupt (ex: 20ms), you read value Pulses (from PAC32
register - if you use PulseAcc-A)
If you use PulseAcc to measure Motor's Speed, i will post my code . (i
am using MC9S12DP512 to Control Speed DC-Motor with PID-fuzzy logic)
Regards,
HoangLongU
Reply by chai...@hotmail.com●October 12, 20082008-10-12
Hi,
Im trying to use input capture to sense the rising edge from the encoder.
It seems like my program cant go into the interrupt function. After i sense 100
times rising edge, i set ptm.0 to be 1. Im using channel 5 as input capture.
void interrupt TIC5 (void)
{
int i;
i = i + 1;
if(i == 100)
{
PTM = 0xFF;
}