MCF5234 PIT problem :-(

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

MCF5234 PIT problem :-(

2,357件の閲覧回数
hek2007
Contributor I
I need a high resolution timer. I know that this may be done with PIT
(Programmable Interrupt Timer). I looked and used some examples about
this but CPU(MCF5234) was halted all time. I need examples which may
be useful.
Best regards.
 
#include "predef.h"
#include <stdio.h>
#include <ctype.h>
#include <startnet.h>
#include <autoupdate.h>
#include <dhcpclient.h>
#include <smarttrap.h>
#include <taskmon.h>
#include <sim5234.h>
#include <cfinter.h>
#include <pins.h>
 
extern "C"
 {
 void UserMain( void * pd );
 void SetIntc( long func, int vector, int level, int prio );
 }
 
const char * AppName = "MOD5234 PIT Example"; // App name for IPSetup
volatile DWORD pitr_count;        // Global count variable
///////////////////////////////////////////////////////////////////////
// INTERRUPT - PIT interrupt service routine
INTERRUPT( my_pitr_func, 0x2600 )
 {
 WORD tmp = sim.pit[ 1 ].pcsr;  // Get PIT1 Control & Status Register
            // data
            
 //
 // Clear PIT1 - Refer to table 21-3 for more information on what
 // bits are begin cleared and set
 //
 tmp &= 0xFF0F;    // Bits 4-7 cleared
 tmp |= 0x0F;    // Bits 0-3 set
 sim.pit[ 1 ].pcsr = tmp,
 
  pitr_count++;     // Increment when an interrupt occurs;
  }
 
void SetUpPITR( int pitr_ch, WORD clock_interval, BYTE pcsr_pre /* See
               table 21-3 in the reference manual for bits 8-11 */ )
 {
 WORD tmp;
 
 if ((pitr_ch < 1) || (pitr_ch > 3))
  {
  iprintf( "*** ERROR - PIT channel out of range ***\r\n" );
  return;
  }
  
 SetIntc( (long)&my_pitr_func, 36 + pitr_ch, 2 /* IRQ2 */, 3 );
 
 //
 // Configure the PIT for the specified time values
 //
 sim.pit[ pitr_ch ].pmr = clock_interval; // Set PIT modulus value
 tmp = pcsr_pre;
 tmp = (tmp << 8) | 0x0F;
 sim.pit[ pitr_ch ].pcsr = tmp; // Set system clock divisor to 16 and
            // set bits [3:0] in PCSR
 }
 
/////////////////////////////////////////////////////////////////////////
// UserMain
//
void UserMain( void * pd )
 {
 InitializeStack();
 if (EthernetIP == 0) GetDHCPAddress();
 OSChangePrio( MAIN_PRIO );
 EnableAutoUpdate();
 EnableSmartTraps();
 EnableTaskMonitor();
 //
 // Let us make bit happen at 1000 Hz. The base clock is
 // 147,456,000 Hz, so the equation is:
 //
 //                 System_Clock_Frequency / 2
 // PMR Value  =  -------------------------------  -  1
 //                Prescalar * Desired_Frequency
 //
 //               147456000 / 2
 // PMR Value  = ---------------  -  1
 //                 16 * 1000
 //
 // PMR Value  = 4607
 //
 // Not that the PIT Count Register is a 16-bit counter, so the
 // clock count maximum is 65,535
 //
 SetUpPITR( 1 /* Use PIT1 */, 4607 /* Wait 4607 clocks */, 4 /*
           Divide by 16 from table 21-3 (2^4) */ );
           
  iprintf( "Application started\r\n" );
  pitr_count = 0;
  
  while (1)
   {
   OSTimeDly( TICKS_PER_SECOND );
   iprintf( "PITR Count = %ld\r\n", pitr_count );
   }
   
 }
ラベル(1)
タグ(1)
0 件の賞賛
返信
1 返信

980件の閲覧回数
mccPaul
Contributor I
Hi
 
 
This is specifically aimed at the mcf5282, but the timers are very similar, if not identical between the Coldfire parts, just check the manual for the 5234 to be sure.
 
Paul.
0 件の賞賛
返信