- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am using the PWM v3 30, in a PSOC 4M series board.
I have set up two compare values in the structure along with the interrupt on pwm1 and pwm2.
I have created the ISR:
CY_ISR(pwm_isr_ON_OFF)
{
status = PWM_ReadStatusRegister() ;
// Pseudo code
if (stats & COMPARE_FLAG_1)
do_stuff(pwm1);
else if(status & COMPARE_FLAG_2)
do_stuff(pwm2);
pwm_on_off_flag = 1;
}
I was hoping to identify the source of the interrupt; compare1 or compare2. I have checked the documentation and tried looking for examples but have not been successful so far.
Help would be appreciated,
Thanks,
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I tried this with CY8CKIT-044.
Being a lazy, I made the PWM very slow and let pins light LED Red and LED Green.
I picked the status values from PWM.c
=====================
/*******************************************************************************
* Function Name: PWM_ReadStatusRegister
********************************************************************************
*
* Summary:
* This function returns the current state of the status register.
*
* Parameters:
* None
*
* Return:
* uint8 : Current status register value. The status register bits are:
* [7:6] : Unused(0)
* [5] : Kill event output
* [4] : FIFO not empty
* [3] : FIFO full
* [2] : Terminal count
* [1] : Compare output 2
* [0] : Compare output 1
*
*******************************************************************************/
=====================
schematic
PWM config
FreqDiv Config
pins
main.c
=======================
#include "project.h"
#include "stdio.h"
#define STR_LEN 64
char str[STR_LEN+1] ;
void print(char *str)
{
UART_UartPutString(str) ;
}
void cls(void)
{
print("\033c") ; /* reset */
CyDelay(20) ;
print("\033[2J") ; /* clear screen */
CyDelay(20) ;
}
void splash(void)
{
cls() ;
print("CY8CKIT-044 PWM 2 Compares Test") ;
snprintf(str, STR_LEN, "(%s %s)\n", __DATE__, __TIME__) ;
print(str) ;
}
#define COMPARE_FLAG_1 0x01
#define COMPARE_FLAG_2 0x02
volatile int red_flag = 0 ;
volatile int green_flag = 0 ;
volatile int pwm_on_off_flag = 0 ;
CY_ISR(pwm_isr_ON_OFF)
{
uint8_t status ;
status = PWM_ReadStatusRegister() ;
if (status & COMPARE_FLAG_1)
red_flag = 1 ;
else if(status & COMPARE_FLAG_2)
green_flag = 1 ;
pwm_on_off_flag = 1;
}
void init_hardware(void)
{
CyGlobalIntEnable; /* Enable global interrupts. */
UART_Start() ;
splash() ;
isr_pwm_ClearPending() ;
isr_pwm_StartEx(pwm_isr_ON_OFF) ;
PWM_Start() ;
}
int main(void)
{
init_hardware() ;
for(;;)
{
if (pwm_on_off_flag) {
pwm_on_off_flag = 0 ;
print("INTR : ") ;
if (red_flag) {
red_flag = 0 ;
print("RED ") ;
}
if (green_flag) {
green_flag = 0 ;
print("GREEN ") ;
}
print("\n\r") ;
}
}
}
=======================
Tera Term Log
moto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I tried this with CY8CKIT-044.
Being a lazy, I made the PWM very slow and let pins light LED Red and LED Green.
I picked the status values from PWM.c
=====================
/*******************************************************************************
* Function Name: PWM_ReadStatusRegister
********************************************************************************
*
* Summary:
* This function returns the current state of the status register.
*
* Parameters:
* None
*
* Return:
* uint8 : Current status register value. The status register bits are:
* [7:6] : Unused(0)
* [5] : Kill event output
* [4] : FIFO not empty
* [3] : FIFO full
* [2] : Terminal count
* [1] : Compare output 2
* [0] : Compare output 1
*
*******************************************************************************/
=====================
schematic
PWM config
FreqDiv Config
pins
main.c
=======================
#include "project.h"
#include "stdio.h"
#define STR_LEN 64
char str[STR_LEN+1] ;
void print(char *str)
{
UART_UartPutString(str) ;
}
void cls(void)
{
print("\033c") ; /* reset */
CyDelay(20) ;
print("\033[2J") ; /* clear screen */
CyDelay(20) ;
}
void splash(void)
{
cls() ;
print("CY8CKIT-044 PWM 2 Compares Test") ;
snprintf(str, STR_LEN, "(%s %s)\n", __DATE__, __TIME__) ;
print(str) ;
}
#define COMPARE_FLAG_1 0x01
#define COMPARE_FLAG_2 0x02
volatile int red_flag = 0 ;
volatile int green_flag = 0 ;
volatile int pwm_on_off_flag = 0 ;
CY_ISR(pwm_isr_ON_OFF)
{
uint8_t status ;
status = PWM_ReadStatusRegister() ;
if (status & COMPARE_FLAG_1)
red_flag = 1 ;
else if(status & COMPARE_FLAG_2)
green_flag = 1 ;
pwm_on_off_flag = 1;
}
void init_hardware(void)
{
CyGlobalIntEnable; /* Enable global interrupts. */
UART_Start() ;
splash() ;
isr_pwm_ClearPending() ;
isr_pwm_StartEx(pwm_isr_ON_OFF) ;
PWM_Start() ;
}
int main(void)
{
init_hardware() ;
for(;;)
{
if (pwm_on_off_flag) {
pwm_on_off_flag = 0 ;
print("INTR : ") ;
if (red_flag) {
red_flag = 0 ;
print("RED ") ;
}
if (green_flag) {
green_flag = 0 ;
print("GREEN ") ;
}
print("\n\r") ;
}
}
}
=======================
Tera Term Log
moto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Motoo.
This works in the continuous mode.
Regards.
Ken.