I wrote this example, so I'm excited to hear your feedback. I'll check in regularly and answer questions if any arise.
Before you tell me, yeah I know bit-banging is a pretty silly way to drive the shift register. We can also do it very easily with the SPI component, but that example will have to wait for another day.
Couple of questions if I may.
1) Why do you effectively invert the ADC value? ie a low voltage will give you a high reading.
2) Why do you bit bang 8 bits, and not just the one you are interested in? (I haven't looked at any documentation so I may be talking rubish) does not togeling 8 (potentially) bits consume more power than just 1?
Thanks for the questions!
1. The sliders on the danger shield are hooked up "backwards". The potentiometer voltage is high when the sliders are "low" (towards the user) and low when the sliders are "high" (away from the user). This requires an inversion somewhere in the system to achieve the desired functionality.
2. We are shifting in 8 bits to drive the 8 segments of the LED display. We have to shift in all 8 bits to re-fill the serial-in, parralel-out. I'm not sure what the behavior is when you try to shift in less bits than the SIPO has, but you can't specify which bit you are shifting in, as the place is inferred from the position within the byte.
Thanks for your answers. I think we're talking at crossed purposes on the second one though.
This line writes one bit (high) of the 8 serial bits to the serial to parallel shift register, but the parameter passed is 8 bits (0xff), why is it not 0x01?
3) Why are there offsets on the max and min readings, why those particular values, and why are they different?
I'm very much enjoying this series of examples, an extremely good idea.
I understand your question now. The Pin Write API does in fact only set 1 bit. Writing 0x01 and 0xff will have the same effect. I use 0xff because it is more readable to me, but it's a matter of preference.
I chose the max and min ADC limits after observing the voltages generated by the linear slider. I did not employ the potentiometer datasheet or any theoretical derivation of these values, I simply looked at them while debugging and set them that way.
Glad you're enjoying the examples! We will keep them coming!
I would liked to see pictures of the board you setup for this project. It sounds like you have many components involved.
Today’s example project uses the “Danger Shield” which includes a list of hardware features such as three large sliding potentiometers, LEDs, LDR light sensor, push buttons, buzzer, and a small 7 segment LED display. The example and descriptions are included in this post.
This example project uses the 7 segment LED display along with one of the Linear Potentiometers. The user will slide the potentiometer and the PSoC 4 will read the voltage value, scale that value and then display the value on the 7 segment display.
Forum Post Attachments:
At the bottom of this post we are including the following items:
- Example Project Zip File
- Zip File of Project Images
- Project Schematic
- Component Configurations
The user can download the example project at the bottom of this post. The project uses the following list of Creator Components:
- ADC SAR
The components are configured by right clicking on the component in your Top Design schematic view and selecting Configure. Please enable the following selections in the Configuration windows for the listed components above.
The main.c firmware is included in the example project. Please review the commented sections for more details.
This example project makes use of the large A0 Linear Potentiometer. The user can slide this potentiometer back and forth (adding an evil scientist cackle not necessary, but encouraged). The PSoC 4 will then use the ADC SAR component to read the voltage output from the A0 potentiometer and then scale that value and output the scaled value to the 7 segment LED display included on the Danger Shield board.
There are no hardware connections outside of connecting the Danger Shield to the Pioneer Kit.
Test Your Project:
Once programmed with this project, you can slide the A0 potentiometer to see the output on the 7 segment LED display.
I hope this example can help you out in your design.