You can use this demo project as an example.
It uses UART to receive commands from terminal and updates PWM duty cycle on RGB LEDs.
New value written to the Counter will take effect after reset.
About reset: is this external PSoC system reset or standard Counter reset through "res" terminal?
Thank you odissey1!! your example project was very helpful, I implemented it to my 3 counters instead of your 3 PWM and changed "PWM_WriteCompare" api to "Counter_WritePeriod" and kept all of your code structure the same. I was happy to see it build and program into my Cy8CKIT-043 without any issues. Before I further modify the code for my application I am running into some problems: First, I can read what the program sends to the hyper terminal (i.e. PWM + UART example type a command...) but I do not see any echo (when I try to type anything on the keyboard nothing shows up on my terminal). Second, my TCPWM counter output frequencies are changing and not fixed to a certain frequency when I send an external clock (using a function generator), I am not sure what could be causing this as I don't have good understanding of the code. I have attached the project file, I I hope it is something just minor that I have wrong! Thank you for your help!!
Regarding the reset, it is the external reset signal (n-rst)
I am traveling this week and won't be able to check your project, hopefully someone else can.
In my demo, PWMs were using fixed function SCB, which only works with internal clocks, no external signal generator will do. Do you use external generator for reset?
This KBA might be helpful:
I believe that in the demo, echo was enabled for errors only, but I might be wrong - too much time passed. Also some Terminal emulators do echo message themselves. Check that baud rate is the same on both ends.
Safe travels! I only use external generator to generate the input signal for my counters that will be divided down (based on the divisor number I input in the hyper terminal, through the Counter_WritePeriod API) . But I need an nRST signal that will sync all my output signals at To (time zero) right after I release my reset button, this is the only way I found to sync all my counter outputs frequencies at time zero
The PWM has the choice to enable a start and a stop input. You can controll al PWMs using a control register output and start all components at the very same time.
Thank you Bob for your feedback, ok I will stop the counter then write period and then then enable the counter. I have attached my block diagram to show what I am trying to do. I am not a coder and I am really stuck getting the UART communication firmware between the terminal and my counter APIs. I am also interested to sync all my output signals from my counters at Time zero and not necessary when my counter starts but making sure all my outputs from my counter toggle high when I let go of nRST, I drew it in the block diagram as well. I hope I made clear what I am trying to do thank you for your help!
counter block diagram.jpg 186.1 K
Thanks for this three days weekend in Japan, I had some time to play with my PSoC board.
I tried with CY8CKIT-044, so pin and other config may different with yours.
And this is a quick prototype so (as usual) may not work correctly.
Having written that, as you were writing that you want to run the board with given setting after reset,
I assumed that you need some non volatile memory to store the configuration.
So I used Em_EEPROM.
Note: The fourth PWM is used to generate 25kHz external clock, so if you have an external 25kHz clock
this PWM is not required. (I jumpered Clock_Out_25KHz with Clock_In_25KHz outside the board).
As you were using most of ISRs only to flip the signal, instead I used TCPWM with period and compare.
And I cheated terminal I/O using my tty utility sample.
When my program is down loaded to the board and get reset, its Em_EEPROM has no content
so the program uses the default value and start running after setting the default values.
All three signals are running with period = 100 and compare = 50.
(Actually in the TCPWM 99 and 49)
Then I stopped the PWM by typing "stop".
I could type "stop 1" to stop counter1, "stop 2" for Counter 2, "stop 4" for Counter3.
So typing stop is equal to typing "stop 7"
Then I set period of Counter2 to 200 by typing "period 2 200"
period of Coutner3 to 300 by typing "period 4 300" (Note period 3 300 will set Counter1 and Counter2 to 300)
Then again started all by typing "start"
Then to test "save" function, I typed "save" which will save current settings to Em_EEPROM.
Then I hit "reset" button of the board.
So the greeting message was displayed but this time each pwm has different values,
which was read from Em_EEPROM.
The waves on my Oscilloscope.
At first I was trying to make the project simple, but I'm afraid that I failed to accomplish orz.
Anyway, yet another sample for you ;-)