PIT interrupts
"sripathy23" <[email protected]>
| Newsgroups | gmane.comp.hardware.motorola.microcontrollers |
|---|---|
| Message-ID | <[email protected]> |
Dear members
I am trying to run the PIT interrupt. I have taken the example of the
sci interrupt in AN2109( example 7.3.4 ISR using C only-One interrupt
source) Instead of using SCI i am using a PIT interrupt. I have taken
the PIT initialization routine from PIT FROM EXAMPLE 7.3.1 IN an
2109). When I created a new project The linker command file generated
automatically. I want to know whether we should use the debug version
or the auto flash version for executing the ISR. I tried to use the
debug version. the problem is when i run the program the PIT counter
is decrementing and when it reaches 0 it sets the PS bit, Sipend
Register, Sivec register. But after that it is executing without
returning to the main program. When i tried to find if there a code
in 0x500 i couldn't find any code there. should i change the lcf file.
I am getting a warning that says can't find irqsection in lcf file.
Ii would appreciate if you can answer these question. i have attached
the main program and lcf file for your reference. should i change any
of thse files to make my program work or should i set any jumpers or
switches.
#include "mpc555.h"
#include <iostream>
#include<math.h>
using namespace std;
void init_555();
void init_mios();
void initPIT();
UINT32 loopctr = 0 ;
int flag1 = 0;
int pitctra1,countera1;
unsigned long x1[2],y1[2],z1[2],a1[2],b1[2],c1[2],m1[2],n1[2],c2[2];
int i=0;
int j=0;
double z2[2],z3[2],d1[2],p1[2],p2[2];
#pragma push
#pragma section code_type".text" code_mode=far_abs
void PIT_Int(void);
#pragma section code_type ".IrqSect"
void Ext_Isr();
#pragma pop
void init_555()
{
USIU.SYPCR.R = 0xffffff03;
USIU.PLPRCR.B.MF = 0x009;
//while(USIU.PLPRCR.B.SPLS==0)
UIMB.UMCR.B.HSPEED = 0;
}
void init_mios()
{
MIOS1.MCPSMSCR.B.PSL = 0x4;
MIOS1.MCPSMSCR.B.PREN = 1;
MIOS1.MPWMSM2SCR.B.CP = 0xf6;
MIOS1.MPWMSM2PERR.R = 2000;
MIOS1.MPWMSM2PULR.R = 500;
MIOS1.MPWMSM2SCR.B.EN = 1;
}
void initPIT()
{
USIU.PITC.B.PITC = 0x1000;
USIU.PISCR.B.PITF = 0;
USIU.PISCR.B.PTE = 1;
USIU.PISCR.B.PIRQ = 0x80;
USIU.PISCR.B.PIE = 1;
USIU.SIMASK.R = 0x40000000;
}
void main()
{
init_555();
init_mios();
initPIT();
asm(" mtspr EIE, r0");
while (1==1) {
loopctr++;
if(flag1==1)
{
// The code below is used to measure the period and frequency of
pwm signal.
// I have taken reference from the Motorola AN1778.pdf(Programming
the MDASM)
MIOS1.MMCSM6SCR.R = 0x0eff; /* Set clock prescalerto follow
MMCSM with a prescaler
division of 1. This means
counter runs at 100ns per count*/
MIOS1.MMCSM6MLR.R = 0x0000; /*Resetting counter to ensure it
starts properly */
MIOS1.MDASM11SCR.R =0x0002; /* Used to initialize MDASM
channel */
while(j<2)
{
x1[0] = MIOS1.MDASM11AR.R; /* Using an array to store the two
consecutive rising edges*/
y1[0] = MIOS1.MDASM11BR.R;
if(x1[0]> y1[0])
{
z1[0]=x1[0]-y1[0];
z2[0] = ((z1[0] * 100 )* pow(10.0,(-6.0)));
z3[0] = 1/(z2[0] * pow(10.0,(-3.0)));
cout<<"\nThe time period of pwm signal is:"<<z2[0]
<<"ms\r"<<endl;
cout<<"\nThe frequency of pwm signal is :"<<z3[0]
<<"Hz\r"<<endl;
j++;
}
else
{
m1[0]=65535-y1[0];
n1[0]=x1[0]+m1[0];
p1[0]= ((n1[0]*100)*pow(10.0,(-6.0)));
p2[0]= 1/(p1[0]*pow(10.0,(-3.0)));
cout<<"\nThe time period of pwm signal is:"<<p1[0]<<"ms\r"<<endl;
cout<<"\nThe frequency of pwm signal is :"<<p2[0]<<"Hz\r"<<endl;
j++;
}
}
// The code below is used to measure on time of pwm signal
MIOS1.MMCSM6SCR.R = 0x0eff; /* Set clock prescalerto follow
MMCSM with a prescaler
division of 1. This means
counter runs at 100ns per count*/
MIOS1.MMCSM6MLR.R = 0x0000; /*Resetting counter to ensure it
starts properly */
MIOS1.MDASM11SCR.R =0x0001; /* Used to initialize MDASM
channel */
while(i<2)
{
a1[0] = MIOS1.MDASM11AR.R; /* Using an array to store rising and
falling edges*/
b1[0] = MIOS1.MDASM11BR.R;
if(a1[0]> b1[0])
{
c1[0] = a1[0]-b1[0];
d1[0] = ((c1[0] * 100 )* pow(10.0,(-6.0)));
cout<<"\nThe time period from falling to rising edge is:"<<d1
[0]<<"ms\r"<<endl;
cout<<"\nThe On time of pwm signal is:"<<z2[0] - d1[0]
<<"ms\r"<<endl;
i++;
}
else
{
c1[0]=65535-b1[0];
c2[0] = a1[0]+c1[0];
d1[0] = ((c2[0] * 100 )* pow(10.0,(-6.0)));
cout<<"\nThe time period from falling to rising edge is:"<<d1[0]
<<"ms\r"<<endl;
cout<<"\nThe On time of pwm signal is:"<<z2[0] - d1[0]
<<"ms\r"<<endl;
i++;
}
}
flag1=0;
}
}
}
#pragma interrupt SRR on
void Ext_Isr()
{
#define LEVEL0 0x40000000
asm (" mtspr EID, r0 "); // Set MSR.RI - now recoverable
if (USIU.SIPEND.R&LEVEL0) // Check if IRQ is level 0
{
PIT_Int(); // Call PIT C interrupt handler
}
else
{
// Just return
}
asm (" mtspr NRI, r0 "); // Clear MSR.RI - now irrecoverable
};
#pragma interrupt off
void PIT_Int()
{
if(USIU.PISCR.B.PS == 1)
{
pitctra1++; // Increment
PIT interrupt counter
if(pitctra1==100)
{
countera1 = countera1+100;
MIOS1.MPWMSM2PULR.R = 100; /* Set Duty Cycle to 25%*/
MIOS1.MPWMSM2SCR.B.EN = 1; /* Enable output on PWM2 */
USIU.PISCR.B.PS = 1; // Negate interrupt request
flag1=1;
pitctra1 = 0;
}
else
{
}
}
else
{
}
}
LINKER COMMAND FILE
_flash_source = 0x00c10000; // **NOTE: MUST match RAM
buffer address
// setting in linker preference panel
/* Default linker command file for 555 ETAS board */
MEMORY {
ram : org = 0x00c02000
rom : org = 0x00000000 // desired ROM address (boot address
for 555)
}
/* We use FORCEFILES so that the linker will not deadstrip the file
reset.s. The function
reset would be deadstripped since it is not ever called by
anything */
FORCEACTIVE { gInterruptVectorTable, __reset }
SECTIONS {
.reset : {} > rom
.init : {} > rom
GROUP : {
.text (TEXT) ALIGN(0x1000) : {}
.rodata (CONST) : {
*(.rdata)
*(.rodata)
}
.ctors : {}
.dtors : {}
extab : {}
extabindex : {}
} > rom // for ROM images, this can be 'rom' if you
want to execute in ROM
// or 'code' if you want to execute
in RAM
GROUP : {
.data : {}
.sdata : {}
.sbss : {}
.sdata2 : {}
.sbss2 : {}
.bss : {}
.PPC.EMB.sdata0 : {}
.PPC.EMB.sbss0 : {}
} > ram
// The dummy section is just a placeholder. The linker
automatically
// generates an address for it in the ROM image, which tells
us
// where the end of the ROM image is.
.dummy ALIGN(64): {}
_flash_dest = _f_reset; // true flash address
starts w/.init section
_flash_size = _f_dummy_rom - _flash_dest;
// The .fcopy section contains a small piece of code that
copies the
// ROM image to flash. We don't copy the .fcopy section
itself to flash
// because it could erase the flash if it were accidentally
executed
// at a later time.
//
// Bind it to the address it will occupy in the RAM buffer so
we can
// execute it directly from the RAM buffer.
.fcopy BIND(_flash_source + _flash_size) ALIGN(64) : {
*(.fcopy)
}
.fcopy_data : {}
// The internal flash algorithms provided by Motorola are
// packaged in a binary file. The linker includes the
contents
// in the .BINARY section.
.BINARY : {}
}
------------------------ Yahoo! Groups Sponsor --------------------~-->
Most low income households are not online. Help bridge the digital divide today!
http://us.click.yahoo.com/cd_AJB/QnQLAA/TtwFAA/dN_tlB/TM
--------------------------------------------------------------------~->
-----------------------------------------------------------
To learn more about Freescale Microcontrollers, please visit
http://www.freescale.com/mcu
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/MPC500/
<*> To unsubscribe from this group, send an email to:
[email protected]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/