In my other post I was asking about the led_Read() and led_Write(1) as I wanted to know if i could just use the read and write command to manipulate port pins rather than using the PRT0DR etc command,
I also noticed that if i made the input pin "high" resulting in the LED/Output port being "low" and I reset the PSoC chip then when i make the input port low then output port/LED would stay the same and not change.
At first sight I can see that you did nor obey the hint of either using a shadow-register or using an LED-component.
PRT1DR |= 0x01 is a read-modify-write instruction for a port. The read gets the voltage currently connected to the pin (NOT the value you wrote to the pin the last time) which will be about 1.7V (due to the LED-voltage) which will be interpreted as a logical Zero (0).
To circumvent this problem see above: Use a shadow-register or an LED-component.
I will take your advice and try using a shadow-register or an LED component,
thank you for your assistance
Taken from LED datashsheet -
The project using the LED User Module which manipulates pins on a port shared with an instance of the LED
User Module must avoid direct PRTxDR writes. The Shadow Registers should be used for such manipulation
to prevent incorrect LED User Module operation.
I was following up on the shadow register guide and video here: http://www.cypress.com/?rID=2900
I downloaded the project files and had a look at the sample code for the shadow registers, it seems a bit much for a sample code for all i want my code to do,
I followed the video as much as I could understand, I set up a shadow register on port 1 and from the psocconfig.asm file in the source folder I see its called Port_1_Data_Shade
I set up a small program that has P1.1 as a constant output, P1.1 as an output to drive and LED for example, and P1.0 as the input which when high will activate the LED on port 1.2.
Port_1_Data_Shade |= 0x04;
PRT1DR = Port_1_Data_SHADE; // not sure if this required as this should always be high
if (PRT1DR & 0X01)
Port_1_Data_Shade |= 0x02;
PRT1DR = Port_1_Data_Shade;
Port_1_Data_SHADE &= ~0x02;
PRT1DR = Port_1_Data_SHADE;
This seems to work ok,
You need to setup switch debounce for mechanical switches/buttons.
Use Sleep timer, and set up an ISR for it. Inside ISR set a flag,
return, then inc a cnttime variable, looking for ~ > 100 mS key down.
Essentially same for key release.
Thanks for your reply, I am using a switch for now but eventually the signal will be a digital input, in that application with a digital output can i still use stdCPU and strong drive to make the output high and can the output still be stdCPU in pulldown mode to toggle an LED or something on another output. I plan on not using a mechanical switch and just stick to using a wire which when cut or damaged will illuminate an led
If you are driving an LED normally you drive it with low side MOSFET in the
output (on when output low), open drain, or just STDCPU is fine as well. Driving
with low side MOSFET is a lower RDSon device than high side device, due to
source bulk effect affecting high side MOSFET threshold.
So preferred drive is LED to port, other side thru current limit R to Vdd.
Thanks for your input, very helpful indeed,
I have the output set to strong at the moment and the LEDs have a current limiting resistor before them,
is strong ok if i want to make an output high to drive a transistor to say trigger a relay?
thanks very much
You may use strong or strong-slow to drive the transistor. Use strong if you need fast switching, use strong-slow if you have EMC issues.
Thanks so much for your useful info,
The diagram is excellent, thank you for that,
My own wiring diagram is the same as that although nowhere near as tidy. lol
thanks for your help, very helpful community here