Counter_WriteCounter() API Doesn't work for Fixed Function Implementation of Counter/ Timer | Cypress Semiconductor
Support & Community
Counter_WriteCounter() API Doesn't work for Fixed Function Implementation of Counter/ Timer
Why Does "Counter_WriteCounter()/Timer_WriteCounter()" API's doesn't seem to write to the Count Register of Counter/Timer Component of PSoC Creator?
The API "Counter_WriteCounter(uint8)" is supposed to write to the Count register of the Counter. The API description says that, timer should be disabled before doing this. So, after disabling the timer by "Counter_Stop()" API, if we write to the counter using the above API and Enable it back using "Counter_Enable()" , then the Counter regitser won't acquire the new value.
Root Cause: There is a flaw in the "Counter_Stop()" API that is available in the Counter. The Stop API does two things. It disables the counter and it powers down the Fixed Function block. When the block is powered down it still maintains the values of its registers, but it doesn't allow access to those registers to write. So in this case when the WriteCounter() function is called the Counter is not powered on to accept that write, so that function call has no effect.
Workaround : A workaround for this problem is to just do the first part of the Stop() function directly using following statement. This will only disable the counter and doesn't power down the FF block.
Counter_1_CONTROL &= ~Counter_1_CTRL_ENABLE; (If Counter's Name is "Counter_1")
Now, Write to the counter using "Counter_WriteCounter()" and Enable it back using "Counter_Enable()".
This also applies to Timer implemented in FF Block. This API issue will be fixed in next release of PSoC Creator.