- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I am using one PWM, one Delay and one Counter to implement two different functions. These are 1) Create a single pulse with a certain delay 2) Create a certain number of pulses again starting with a delay. Please find below how I configured the TCPWM's for that purpose.
Here are the two functions I use to get all running:
void SinglePulse(Mode_Parameter *mode_parameter)
{
uint32_t compare1, pwm_period ;
cy_stc_tcpwm_pwm_config_t *ptr = (cy_stc_tcpwm_pwm_config_t *) &Pulse_Gen_1_config;
ptr->runMode = CY_TCPWM_PWM_ONESHOT; //One Shot Configuration
ptr->compare0 = 75000;
ptr->period0 = 100000;
Delay_Counter_1_Start();
Delay_Counter_1_SetPeriod(400000);
Pulse_Gen_1_Start();
}
The second one is to generate a PWM for a certain number of pulses (controlled by the Counter_1)
void MultiPulse (Mode_Parameter *mode_parameter)
{
uint32_t compare1, pwm_period ;
cy_stc_tcpwm_pwm_config_t *ptr = (cy_stc_tcpwm_pwm_config_t *) &Pulse_Gen_1_config;
ptr->runMode = CY_TCPWM_PWM_CONTINUOUS; //Continuous Run
ptr->compare0 = 75000;
ptr->period0 = 100000;
Delay_Counter_1_Start();
Delay_Counter_1_SetPeriod(0);
Counter_1_Start(); //This is pretty much the only difference from the previous function
Pulse_Gen_1_Start();
}
They seem to work fine the first time after boot. If you call the other one as second, the counter behaves like the previous configuration.
Scenario 1: (After reset)
1) Call the SinglePulse first. Single pulse achieved.
2) Call next the MultiPulse. I don't get multiple passes, one a single pass.
Scenario 2: (After reset)
1) Call the MultiplePulse first. I get the exact number of pulses I need and it it stops.
2) Call next the Single Pulse. I get the delay and the first pulse but then the pulse never stops. It just keeps coming.
I guess I need somehow to reinitialize the TCPWM's to get the effect of a board reset, but I could't do that.
Thanks in advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear EmBa-san,
I hacked a little today.
Then I found that Pulse_Gen_config is defined as "const".
So when I assigned a value to ptr->runMode, the program jumped to exception handling.
Then I provided local variable of same type "pulse_gen_config" and tested with a minimum circuit
using CY8CKIT-062-BLE.
When I set break points at each CyDelay(1000) ;
After SinglePulse(), one time black to light
After MultiPulse() , LED blinks till the next SinglePulse() will be called.
schematic
pins
main.c
Note: In the "init_hardware()",
I copy Pulse_Gen_config to pulse_gen_config.
==================
#include "project.h"
cy_stc_tcpwm_pwm_config_t pulse_gen_config ;
void init_hardware(void)
{
__enable_irq(); /* Enable global interrupts. */
pulse_gen_config = Pulse_Gen_config ;
}
void SinglePulse(void)
{
// uint32_t compare1, pwm_period ;
cy_stc_tcpwm_pwm_config_t *ptr = &pulse_gen_config ;
Pulse_Gen_Disable() ;
Pulse_Gen_DeInit() ;
ptr->runMode = CY_TCPWM_PWM_ONESHOT ;
ptr->compare0 = 5000 ;
ptr->period0 = 10000 ;
(void) Cy_TCPWM_PWM_Init(Pulse_Gen_HW, Pulse_Gen_CNT_NUM, ptr);
Cy_TCPWM_Enable_Multiple(Pulse_Gen_HW, Pulse_Gen_CNT_MASK);
#if (Pulse_Gen_INPUT_DISABLED == 7UL)
Cy_TCPWM_TriggerStart(Pulse_Gen_HW, Pulse_Gen_CNT_MASK);
#endif /* (Pulse_Gen_INPUT_DISABLED == 7UL) */
}
void MultiPulse(void)
{
// uint32_t compare1, pwm_period ;
cy_stc_tcpwm_pwm_config_t *ptr = &pulse_gen_config ;
Pulse_Gen_Disable() ;
Pulse_Gen_DeInit() ;
ptr->runMode = CY_TCPWM_PWM_CONTINUOUS ;
ptr->compare0 = 5000 ;
ptr->period0 = 10000 ;
// Pulse_Gen_Init(ptr) ;
(void) Cy_TCPWM_PWM_Init(Pulse_Gen_HW, Pulse_Gen_CNT_NUM, ptr);
Cy_TCPWM_Enable_Multiple(Pulse_Gen_HW, Pulse_Gen_CNT_MASK);
#if (Pulse_Gen_INPUT_DISABLED == 7UL)
Cy_TCPWM_TriggerStart(Pulse_Gen_HW, Pulse_Gen_CNT_MASK);
#endif /* (Pulse_Gen_INPUT_DISABLED == 7UL) */
}
int main(void)
{
init_hardware() ;
/* Enable CM4. CY_CORTEX_M4_APPL_ADDR must be updated if CM4 memory layout is changed. */
// Cy_SysEnableCM4(CY_CORTEX_M4_APPL_ADDR);
/* Place your initialization/startup code here (e.g. MyInst_Start()) */
for(;;)
{
SinglePulse() ;
CyDelay(1000) ;
MultiPulse() ;
CyDelay(1000) ;
}
}
==================
Best Regards,
8-Apr-2020
Motoo Tanaka
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Last time I played with PSoC6 PWM, I needed to call _TriggerStart() after _Enable() to restart a stopped PWM.
I wonder if calling
Delay_Counter_1_TriggerStart() ;
after
Delay_Counter_1_SetPeriod(x) ;
helps or not.
moto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello Moto,
Unfortuantely it didn't help. To be more clear, the problem is not restarting a stopped PWM. It is to change the run mode of the TCPWM from "continuous" to "one shot" or vice versa. Once the TCPWM starts in either mode, I cannot switch to the other one without resetting the board.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I'm sorry that I missed the point.
Then how about replacing
Pulse_Gen_1_Start() ;
with
Pulse_Gen_1_Init(&pulse_gen_1_config) ;
Pulse_Gen_1_Enable() ;
Because, _Start() call Init() only once.
From the 2nd time, it calls only Enable() ;
moto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear EmBa-san,
I hacked a little today.
Then I found that Pulse_Gen_config is defined as "const".
So when I assigned a value to ptr->runMode, the program jumped to exception handling.
Then I provided local variable of same type "pulse_gen_config" and tested with a minimum circuit
using CY8CKIT-062-BLE.
When I set break points at each CyDelay(1000) ;
After SinglePulse(), one time black to light
After MultiPulse() , LED blinks till the next SinglePulse() will be called.
schematic
pins
main.c
Note: In the "init_hardware()",
I copy Pulse_Gen_config to pulse_gen_config.
==================
#include "project.h"
cy_stc_tcpwm_pwm_config_t pulse_gen_config ;
void init_hardware(void)
{
__enable_irq(); /* Enable global interrupts. */
pulse_gen_config = Pulse_Gen_config ;
}
void SinglePulse(void)
{
// uint32_t compare1, pwm_period ;
cy_stc_tcpwm_pwm_config_t *ptr = &pulse_gen_config ;
Pulse_Gen_Disable() ;
Pulse_Gen_DeInit() ;
ptr->runMode = CY_TCPWM_PWM_ONESHOT ;
ptr->compare0 = 5000 ;
ptr->period0 = 10000 ;
(void) Cy_TCPWM_PWM_Init(Pulse_Gen_HW, Pulse_Gen_CNT_NUM, ptr);
Cy_TCPWM_Enable_Multiple(Pulse_Gen_HW, Pulse_Gen_CNT_MASK);
#if (Pulse_Gen_INPUT_DISABLED == 7UL)
Cy_TCPWM_TriggerStart(Pulse_Gen_HW, Pulse_Gen_CNT_MASK);
#endif /* (Pulse_Gen_INPUT_DISABLED == 7UL) */
}
void MultiPulse(void)
{
// uint32_t compare1, pwm_period ;
cy_stc_tcpwm_pwm_config_t *ptr = &pulse_gen_config ;
Pulse_Gen_Disable() ;
Pulse_Gen_DeInit() ;
ptr->runMode = CY_TCPWM_PWM_CONTINUOUS ;
ptr->compare0 = 5000 ;
ptr->period0 = 10000 ;
// Pulse_Gen_Init(ptr) ;
(void) Cy_TCPWM_PWM_Init(Pulse_Gen_HW, Pulse_Gen_CNT_NUM, ptr);
Cy_TCPWM_Enable_Multiple(Pulse_Gen_HW, Pulse_Gen_CNT_MASK);
#if (Pulse_Gen_INPUT_DISABLED == 7UL)
Cy_TCPWM_TriggerStart(Pulse_Gen_HW, Pulse_Gen_CNT_MASK);
#endif /* (Pulse_Gen_INPUT_DISABLED == 7UL) */
}
int main(void)
{
init_hardware() ;
/* Enable CM4. CY_CORTEX_M4_APPL_ADDR must be updated if CM4 memory layout is changed. */
// Cy_SysEnableCM4(CY_CORTEX_M4_APPL_ADDR);
/* Place your initialization/startup code here (e.g. MyInst_Start()) */
for(;;)
{
SinglePulse() ;
CyDelay(1000) ;
MultiPulse() ;
CyDelay(1000) ;
}
}
==================
Best Regards,
8-Apr-2020
Motoo Tanaka