Tristan HIll

PWM read on HCS12 (Dragon 12)

Discussion created by Tristan HIll on Apr 23, 2009
Latest reply on Apr 28, 2009 by Tristan HIll

I am having a problem reading a pwm signal into my HCS12. I am using codewarrior. I have been working on this problem for a long time with limited to no success. I am using input capture to time rising and falling edges on the samee channel(0). At this point my interupt is only firing on rising eges, but i think i have the register set correctly for both rising and falling. Any advice would be greatly appreciated.

Here is what i have:

#include <hidef.h>      /* common defines and macros */
#include <mc9s12dg256.h>     /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12dg256b"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "main_asm.h" /* interface to the assembly module */
#define DLC_DELAY 300
#define PI 3.14159265

__interrupt void RealTimeInterrupt( void );
__interrupt void TC0Interrupt( void );
__interrupt void TOI (void);


int diff,rise,fall,last,ovcnt,avg,sum,cnt;
char string[17];
int debug = 55,debug1=60;
int flag = 0;
double dblsum;


void main( void ){
 
  PLL_init();
  LCD_init();
 
 
  DDRT= 0x00;                  //input

  TIOS &= ~0x01;               // channel 0 input capture
                                
  TSCR1= 0x80;                 // enable timer
   
  TIE = 1;                     // timer interupt enable
   
  TSCR2= 0b101;                // prescale 32
   
  TCTL4 = 0b11;                // capture any edge
   
  EnableInterrupts;
 
  
  while(1){   
   

    sum = sum + diff ;
  
 
    if (cnt==100){
   
   
      dblsum=sum ;
      avg = dblsum/cnt;
     

      cnt = 0;
      sum = 0;
    }
 
    }

}

__interrupt void RealTimeInterrupt( void )
{
  CRGFLG = 0x80;       /* clear rti flag */
}

__interrupt void TC0Interrupt( void )
{
  
  TFLG1 = 0x01;     //clear TC0 flag
 
  if(PTT &= 0x01){      //PT0 is high afte interupt   
    rise = TC0;
      
  } else                   //PT0 is low afte interupt
 
  {
  
    fall = TC0;
    diff = fall - rise;
    cnt++ ;
       
  }

}

__interrupt void TOI( void )
{
  
}

 

Outcomes