Problem with ISR TImer PSOC 1

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Hello my name is Felipe and i know the Psoc 1 is a litlle bit obsolet but i think for some case it's ok, anyway i've tried to create a software Pwm, because in my proyect i'm using a PSOC CY8C211223 but it only has 4 digital modules and i need 10 pwm, i'm using this PSOC Model because it's very small, i've configured the timer24 like a source clock for my counter for the cycleduty, the timer create a interrupt every 200Khz, it's working but my CycleDuty doesn't work, it doesn't change in the main routine, i've read some articles and notes application about the timer and i think the problem is the global variables declaration, i declared volatile but nothing. this is my code: 

   

 

   

//----------------------------------------------------------------------------
// C main line
//----------------------------------------------------------------------------

   

#include <m8c.h>        // part specific constants and macros
#include "PSoCAPI.h"    // PSoC API definitions for all User Modules

   

volatile BYTE counter=0;
volatile BYTE Cycleduty=10;
volatile BYTE CycleDutyTemp=0;

   

#pragma interrupt_handler SoftPwm2

   

void main(void)
{
     M8C_EnableGInt ; // Uncomment this line to enable Global Interrupts
    // Insert your main routine code here.
    Timer24_Start();
    Timer24_EnableInt();
    
    for (;;)
    {
        for (CycleDutyTemp=0;CycleDutyTemp<100;CycleDutyTemp++)
        {
            M8C_DisableGInt ;
            Cycleduty=CycleDutyTemp;
            M8C_EnableGInt ;
        }
    }
    
}

   

void SoftPwm2(void)
{
    if(counter<100)
    {
        counter=counter+1;
    }
    else 
    {
        counter=0;    
    }

   

        if(counter<Cycleduty)
        PRT0DR=1;
        else 
        PRT0DR=0;
    
}

   

i've attached my project with the source code, i hope some one can help me 
thanks in advance!

0 Likes
2 Replies
SampathS_11
Moderator
Moderator
Moderator
250 sign-ins 250 solutions authored 5 questions asked

Hello Felipe,

   

I can see that you are updating the duty cycle too fast, to observe a proper PWM. (for() loop in main()). Instead try this:

   

if (counter == 0)

   

{

   

            CycleDutyTemp++;

   

            if (CycleDutyTemp >= 100) CycleDutyTemp = 0;

   

            M8C_DisableGInt ;
            Cycleduty=CycleDutyTemp;
            M8C_EnableGInt ;

   

}

   

 

   

Hope this will help you see the PWM waveform.

   

 

   

Thanks,

   

Sampath

0 Likes
Anonymous
Not applicable

Hello Sampath, thank you for your reply, i can see the Pwm form(oscilloscope) but it doesn't work for high frecuencies it's working about 650Hz, but when i try with 1Khz or 10Khz, doesn't work, i would like to know if  is there any limit Frecuency for the timer module? or for the CPU clock?? because in the global resources i've configured sysclk = 24Mhz, CPU clock= sysclk / 4 = 6MHZ, VC1=1,VC2=4, VC3=8, and the timer's clock is VC3, (when i change VC3 to VC2 it's doesn't work or when i change the CPU clock to sysclk/ 2), i hope you can help me with this, thanks in advance and i'm going to change muy source code with your code, regards!

0 Likes