- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I recently had a look at the following API call of a PSoC4 Pulse Width Modulation component.
void PWM_Start(void) { if (0u == PWM_initVar) { PWM_Init(); PWM_initVar = 1u; }
PWM_Enable(); }
The routine documentation clearly states that the PWM will be initialized upon first call to PWM_Start(), which is fine. What I don't like about this implementation is that the PWM_Start() routine sets PWM_initVar. In my opinion, this should be done within PWM_Init() because then I can initialize the PWM without immediately starting it, allowing me to defer the actual start to the point where I need it.
Could you please fix this in the next version of PSoC Creator?
Cheers,
Adrian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
A call to the PWM_Start() function will automatically call the PWM_Init() and PWM_Enable() functions (as the case with most of the PSoC components). So, in most of the cases, there is no need to call them again.
Regards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Well, the problem is that with this implementation you cannot configure the PWM in software before actually starting the PWM. Any configurations that you do will be overwritten by PWM_Init() called from within PWM_Start().
For example, using the setup below, the following piece of code won't have the desired effect, which is making the RGB LED emit orange light:
Configurator setup:
- 2 PWMs driving the two LED pins on the PSoC 4 Pioneer board
- Both PWMs have period=255, and compare=0
PWM_LED_Red_WriteCompare(128u); PWM_LED_Red_Start(); PWM_LED_Green_Start(); CyDelay(1000); PWM_LED_Red_Stop(); PWM_LED_Green_Stop();
When you run this code, the PWMs will output 'low' (and thus the pins go 'high') for the entire period. The LED will emit yellow light.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You could of course fix it by writing:
PWM_LED_Red_Start(); PWM_LED_Red_WriteCompare(128u); PWM_LED_Green_Start(); CyDelay(1000); PWM_LED_Red_Stop(); PWM_LED_Green_Stop();
Personally, I find this very unintuitive…
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In that case, you in fact need to call Init() and Enable() on your own. Maybe you can send a request to Cypress to somehow provide this capability, or at least explain (in the data sheet or an AppNote) how to do this properly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This is actually desired and correct behavior.
See page 16 of the datasheet:
Basically, if you call start, stop, change settings and start again it will not overwrite your settings. That said the first time start is called, it is expected the settings in the customizer are correct.
This is true with other components such as UART.