The default API is intended to have very diverse usage, so it essentially provides “a little bit of everything.” The folliwng section shows exactly what you have to play with by default, but an advanced user might have different needs based on their unique design constraints. Luckily, the code was designed to easily facilitate this kind of need, and changing it to fit any project should not be too difficult.
By default, the API (V1.2) is configured with the following components available:
All are 16-bit resolution by default
PWM channel 0 is available on P0[2]
PWM channels 1-7 are available on Port 6 Pins 1-7
Wave DAC connected to P0[0]
Ultrasonic Range Finding capability on all GPIO using 3, 4, or 5 pin form factor standards - Be sure that the logic level is correct though.
NeoPixel control through P6[0]
This should be very simple.
Open the PSoC_2_Pi .cywrk file
Navigate to your schematic (the .cysch file)
Double click on the GPIO page at the bottom of your schematic
To delete, for example, P0[5] as a GPIO, simply click the component named GPIO_0_5, and press delete.
Once the pin component is in place, make sure that you name it in the same way the other pins are named. It needs to be named GPIO_0_7 in this case, or GPIO_<PORT#>_<PIN#> more generally
Now, navigate to your design wide resources page (.cydwr)
Find your new pin in the list of pins shown on the right (it should be highlighted in white since it hasn’t been assigned a location yet)
Assign the pin to your desired location (P0[7])
And that should do it! No code changes needed!
This is the only change that will require a slight change to the code, but it is not extreme, you will mostly just be changing a couple numbers. I simply couldn’t conceive a better way to handle this. First though, you only need to change the schematic, similar to the GPIO modification.
Open the PSoC_2_Pi .cywrk file
Navigate to your schematic (the .cysch file)
Double click on the PWM page at the bottom of your schematic
To add a PWM, simply find the PWM component in your components tab to the right and drag and drop it into your build. You should not have to change the name (it defaults to the expected name)
Double click on the components to configure it, and make sure that your Implementation is selected as “UDB” and your PWM mode is selected as “One Output.”
Modify the remaining parameters as you see fit
Connect the PWM output to a digital output pin, with HW connection
In PWM_Control_n, go to the switch-case, and find case 0xFF Here change the code to call the correct clock. If you tied PWM_9 to PWM_CLK_2, make sure that case 0xFF in PWM_Control_8 reads as:
case 0xFF: PWM_CLK_2_SetDividerValue(val); result = PWM_CLK_2_GetDividerRegister(); return_flag = 1; break;
Navigate to mem1.h
Find the section which asks you to match the clocks together, it should be the section towards the bottom, but just above all the function prototypes
Essentially what you do here, is define you PWM_x_CLK to be using PWM_CLK_y. So lets consider the same example as earlier. You are adding PWM_9, and it is sharing PWM_CLK_2. In this case, find the block of code associated with PWM_9 (it should already exist!) and change it so that it reads:
#ifdef CY_PWM_PWM_9_H #define PWM_9_CLK (PWM_CLK_2) #endif
And now you should be all set with your PWM changes.
This again should be quite simple, and can be done without code changes.
Open the PSoC_2_Pi .cywrk file
Navigate to your schematic (the .cysch file)
Double click on the ANALOG page at the bottom of your schematic
If you want to remove all of the analog pins, you can simply delete the entire Sequenced SAR ADC (named ADC_SAR_Seq_1), and make sure to delete the pins connected to it.
Note that when you call analog pin N, it is referring to whatever pin is connected to index N on the sequenced SAR, where 0 is the top pin.
This is a similar process to the analog pin modifications.
Open the PSoC_2_Pi .cywrk file
Navigate to your schematic (the .cysch file)
Double click on the ANALOG page at the bottom of your schematic
If you want to remove all of the CapSense buttons, you can simply delete the entire CapSense component (named CapSense_1), this saves a lot of analog resources
Here I will discuss how to add/remove general analog features, like the WaveDAC, IDACs, VDACs, and ADC’s. They all share the same process, so I will explain them all in the same section. First, note that the API makes available the following general analog features, in addition to the Analog Pins and the CapSense Buttons
To remove any of these feature, you only need to navigate to the schematic file (.cysch) and delete the components that are named as shown above, and anything connected to them.
To add these features back:
Open the PSoC_2_Pi .cywrk file
Navigate to your schematic (the .cysch file)
Double click on the ANALOG page at the bottom of your schematic
To add any component, simply find it in the components catalog to the right, and drop it into your schematic. It should be named appropriately by default, but confirm that it is named according to my comments above anyway.
Double click on the component to configure it as desired
I prefer to buffer the outputs of all Voltage DACs (including the WaveDac), but it isn’t necessary. For the WaveDAC you can choose that the output be buffered. For the VDACs, you can simply connect an Op-Amp in “follower” configuration operating at Med or High power between your output pin and the output of your DAC. Keep in mind that I am not suggesting you physically connect an external op-amp – There are op-amps internal to the PSoC, and you can find them in the component catalog to the right
Also for the WaveDAC component, be sure to attach the “ws” connection to a “Logic High” component from the component catalog to the right.
For the ADCs, I traditionally use Single-Ended, but you can use differential inputs if you desire, just know that if you leave the differential inputs floating, it will produce bad results, so the lesson is to pay close attention to the parameters you choose.
Make sure to attach your component outputs to an analog pin, and then assign that pin to a physical location in your design wide resources (.cydwr)
In this case, certain components are restricted to certain pin assignments. For instance, the IDAC’s will want to be placed at only a couple different locations, otherwise they cannot operate at full power. When you search for a pin location in the drop down menu, next to the pin location will be the suggested use. For an IDAC_out pin, find one with a label that reads “IDAC:HI” – If you are buffering your DACs, you need you connect the pin to a location labled with “OpAmp:out”
You will notice an extra page on the schematic file which contains a StripLights custom component, and a Timer block. Both of these are needed, configured exactly as they are, for the NeoPixels shield and Ultrasonic Range Finder, respectively. If you do not need one or both of these, you can simply delete them to save your resources
I like to think I included the overwhelming majority of use cases with this API, but for more advanced users, this is of course not entirely the case. There are a number of components that could be added, but don’t have support, such as quadrature decoding, op-amps, digital filters, etc. I did keep this in mind when designing the software architecture though, and so there exists a very specific, and relatively easy to follow procedure for how to work these kinds of things in, but for now, I will ask that any requests for new features be sent to me, and we can work on getting your suggested feature into the official version. In the future, I will add a new section to explain exactly the procedure to follow for handling this.