cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 5, 3 & 1 MCU

Anonymous
Not applicable

hi i am trying to use timers .

   

i have seen 1 example project in cypress. i've used that code, but i am unable to get the output. LED is continuously glowing.

   

please help me.

   

here is the code

   

 

   

   

//-------------------------------------------------------------------

   

// Include Files

//-------------------------------------------------------------------

   

#include

   

   

<m8c.h> // part specific constants and macros

   

#include

   

//-------------------------------------------------------------------

// C Interrupt Handlers

//-------------------------------------------------------------------

        "PSoCAPI.h"        // PSoC API definitions for all User Modules   

#pragma

    interrupt_handler Timer8_1_ISR_C   

//-----------------------------------------------------------------------------

// FUNCTION NAME: Main

//

// DESCRIPTION:

// Main function. Performs system initialization and loops infinitely.

//

//-----------------------------------------------------------------------------

//

// ARGUMENTS: None

// RETURNS: None.

// SIDE EFFECTS: None.

//

// THEORY of OPERATION or PROCEDURE:

// 1) Start the user modules

// 2) Loop Infinitely

//

//-----------------------------------------------------------------------------

//

   

void

{

 

    mainc()    //Enable the Global Interrupt   

M8C_EnableGInt;

 

 

    //Enable the Timer interrupt and Start the UM   

Timer8_1_EnableInt();

Timer8_1_Start();

 

    //infinte loop. Processing done only at Timer_ISR.   

 

}

    while    (1);   

//-----------------------------------------------------------------------------

// FUNCTION NAME: Timer8_1_ISR_C

//

// DESCRIPTION:

// Interrupt Service routine of Timer8_1 usermodule written in C.

// The _Timer8_1_ISR subroutine In the Timer8_1INT.asm file,

// redirects the flow to this subroutine.

//-----------------------------------------------------------------------------

//

// ARGUMENTS: None

// RETURNS: None.

// SIDE EFFECTS: None.

//

// THEORY of OPERATION or PROCEDURE:

// A Terminal Count interrupt occurs at an interval of 0.5 secs.

// The state of pin P2[0] is determined and reversed.

//

//

   

void

{

 

    Timer8_1_ISR_C()    //Read Port2 and XOR it with 0x01 to change the status from On to Off and vice-versa.   

PRT2DR ^= 0x01;

}

0 Likes
Reply
9 Replies
Anonymous
Not applicable

Vishnu,

   

It is difficult to find out the problem only with the main.c code.  Can you zip the complete project folder and attach it here?

   

Best Regards,

   

Ganesh

0 Likes
Reply
Anonymous
Not applicable

Your main.c code also has some problem.

   

 

   

You have declared TIMER8_1_ISR_C as an interrupt handler.  But you have not defined the function correctly.  This is the correct way of writing the function.

   

void TIMER8_1_ISR_C(void)

   

{

   

PRT2DR ^= 0x01;

   

}

   

In the Timer8's ISR file, you should have the below code in the user code marker area.

   

ljmp _TIMER8_1_ISR_C

0 Likes
Reply
Anonymous
Not applicable

sir i am attaching the complete zip file.

0 Likes
Reply
Anonymous
Not applicable

sir I am attached the file here

0 Likes
Reply
Anonymous
Not applicable

sir  i am trying to attach the file but i am getting exception.

   

is there any alternate solution to send the file to u

   

Thanks & Regards

   

vishnu

0 Likes
Reply
Anonymous
Not applicable

yaa finally got it attached

0 Likes
Reply
Anonymous
Not applicable

Following changes are required in your project.

1. In your project, this parameter is set to UseSysClkDirect.  This will override the VC3 Clock setting and set the clock to 24MHz.  Due to this, the interrupt from the timer will be too fast and you will see the LED to be always On.  Set this parameter to "SyncToSysClk"

2. I guess you are trying to get a 2Hz interrupt from the Timer.  For this, set the VC3 source to VC2.

3. I dont understand the logic you have used in main.c using the count variable.  If you set the VC3 source to VC2 and set the SysClk parameter right, the Timer will generate an interrupt every 500mS.  So, you can have the  "PRT2DR ^= 0x80" instruction inside the ISR

4. You should not add an underscore before the function name when writing it in C.  When a C function is called from assembly, an underscore has to be added in the assembly function call.

   

Make the above corrections in device editor and replace main.c code with below code and you should see the LED blinking at 1Hz (I have tested this)

   

#pragma interrupt_handler Timer8_1_ISR

void main(void)
{  
   M8C_EnableGInt;
   Timer8_1_EnableInt();
   Timer8_1_Start();
  
   while(1)
   {
   }
}

void Timer8_1_ISR(void)
{  
   PRT2DR ^= 0x80;
}

   

Best Regards, Ganesh

0 Likes
Reply
Anonymous
Not applicable

Thank u so much sir. i got the result.

   

Thanks & Regards

   

Vishnu

0 Likes
Reply
Anonymous
Not applicable

You are most welcome!!

0 Likes
Reply