- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello there, I have a project where I want the PIR motion sensor to detect motion, take the output of the PIR motion sensor and send it into psoc, triggering LED to turn on, and then after turning on LED, a timer user module will countdown and reach a specified time, therefore turning off the LED. Help as soon as possible would be much appreciated! I have attached my "thought-to-work" PSoC 1 CY3210 kit software/firmware below.
Solved! Go to Solution.
- Labels:
-
PSoC 1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This is an easy one:
The modules are named LCD_1 and LED_1, so the APIs are named LED_1_On() and LED_1_Off. By the way: The polarity of the LEDs on the Evaluation Kit is "Active Low", not Active High (as far as I remember)
The same is for the LCD: The API is named LCD_1_Init().
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Also, i want to be able to display the time (in seconds) or at least try to display it on the LCD.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Please help anyone? There is an error when I combine the ADC user module output to trigger the LED and timer countdown.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This is an easy one:
The modules are named LCD_1 and LED_1, so the APIs are named LED_1_On() and LED_1_Off. By the way: The polarity of the LEDs on the Evaluation Kit is "Active Low", not Active High (as far as I remember)
The same is for the LCD: The API is named LCD_1_Init().
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Some older application notes on the topic -
http://www.cypress.com/?rID=360 IP-360
http://www.cypress.com/?docID=20141 AN2414
Regards, Dana.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you! so I will just follow the application notes given. But it does not have any C coding to follow for the PSoC 1. Is there any way I can double check if I am on the right route with my already made PSoC Project? OR is it completely wrong? Your help would be much appreciated! Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Here's kind of the flow chart: (is this the correct procedure?)
1) Initiate all User Modules and PIR sensor
- Analog-->PGA-->ADC-->LED-->LCD--> DAC
- But how do I make the data that goes into the port for the ADC output on a different port to trigger the LED? I guess that is my biggest prolem here.
2) Software
- Check to see if data is available from PIR sensor
- #include <m8c.h>
- #include "PSoCAPI.h"
- #include "stdlib.h"
- #include "string.h"
- //~~~~~ global variables ~~~~~
- int stop = 0; // flag for spin loop
- int tick = 0; // variable to keep track of # of times terminal count
- // is reached on the LEDTimer8 UM
- int MAXTICK = 100; // number of count cycles for 10 seconds
- void main(void)
- {
- unsigned char bADCData;
- /* Enable Interrupt for ADC */
- M8C_EnableGInt ;
- /* Initialize all User Modules */
- LCD_1_Start();
- PGA_1_Start(PGA_1_HIGHPOWER);
- ADCINC_1_Start(ADCINC_1_HIGHPOWER);
- /* Run ADC continuously */
- ADCINC_1_GetSamples(0);
- while(1) /* Loop forever */
- {
- if(ADCINC_1_fIsDataAvailable() != 0)
- /* If data is valid display on LCD */
- {
- /* Read ADC Result */
- bADCData = ADCINC_1_bGetData();
- led();
- /* Display on LCD */
- LCD_1_Position(1,5);
- LCD_1_PrHexByte(bADCData);
- /* Clear ADC flag for next reading */
- ADCINC_1_fClearFlag();
- }
- }
- }
- void led()
- {
- char ASCII_String[7]; // for itoa
- int i = 0; // count index for spin loop
- InitLCD();
- LEDTimer8_Start();
- // M8C_EnableGInt ; // enable Global Interrupts
- LEDTimer8_EnableInt(); // enable Timer8 interrupts
- while (!stop)
- {
- PRT0DR |= 0x02; // turn ON LED at P0_1
- LCD_1_Position(0,6);
- LCD_1_PrString(itoa(ASCII_String,i/0x1CA,10));
- i++;
- } // end spin loop
- // concluding code - will not run until max time has been reached
- PRT0DR &= ~0x02; // Turn OFF LED at P0_1
- LCD_1_Position(0,0);
- LCD_1_PrCString("Max Time Reached");
- LCD_1_Position(1,0);
- LCD_1_PrCString("Lights Turn OFF");
- }
- void Timer_Interrupt(void ) //Timer ISR
- {
- tick++;
- if (tick == MAXTICK)
- { LEDTimer8_Stop();
- stop = 1; // change spin loop flag
- }
- } // end Timer_Interrupt
- void InitLCD(void )
- { LCD_1_Start();
- LCD_1_Position(0,0);
- LCD_1_PrCString("Time:");
- LCD_1_Position(0,9);
- LCD_1_PrCString("seconds");
- }// end InitLCD
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You are setting Port0 pin 1, but your LED is connected to Port0 pin 2. You still do not use the LED_1_xxx() APIs.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
How about we try this, I used the old PSoC sample code that was provided above in the application note. Which ports and pins do I plug in for the PIR and then which port_pin do I use for input to the LED? Let's try if anyone of you are able to help. So far all i have is port0_pin7 serving as the input for from the PIR output pin.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In your uploaded project you are using Port0 pin 1 (not seven) as input to the PGA.
Can you please upload a current project state for us to check?
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I cannot see where you
-Have an input mux and set that to connect your PGAs to your desired inputs
-Have an LED-component to safely(!!!) switch your LED on and off (You are using a read-modify-write when accessing the port directly)
Some useful hints:
Port0 is best for analog I/O, use port1 (or two) for digital I/O. Leave port2 free for using the LCD on the development kit
Use usermodules when they are availlabe for your purpose, do not "create" your own muxes, LED-usermodules can be used for other purposes as well, for instance to switch your relay-driver
While designing: Readability rules effectiveness, use bit setting/testing sparingly better use boolean TRUE or FALSE at the cost of additional 7 bits.
Avoid re-configuring usermodules by changing register values if not ABSOLUTELY necessary, any hardware design change may spoil that!
Your included .h-files are not listed in the workspace explorer. Left-click on Source or Header Files and add the file(s)
You do not exactly tell, what is working and what does not work. Getting some AD values and Switching some port bits are easy stuff but your project is a bit more complex. I would suggest you to make an exxample project for getting the ADC-values and display on LCD. This might help you to control the PIR values.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Some observations –
1) 1) The LEDs on the kit are active high to turn on. As Bob suggested use LED
components to control LEDs, they make life easy, instantiate shadow registers,
and have very little code/ram burden.
2) 2) I see your PGA, GainStage1, GainStage2, are respectively connected to
P0_1 and P0_4. P0_1 is not set to Analog Input, which it should be. Po_4
is connected to AnalogOutBuff2, the DAC, is that what you wanted ?
3) 3) You are fine on doing register writes to configure and control PSOC1, but
you have to read carefully the register TRM to make sure you understand
all side effects and constraints when you do. That is a strength of the architecture,
the ability to exercise great control over the HW.
4) 4) A link to the PIR datasheet would be helpful.
5) 5) It would help if you could post an electrical schematic, not absolutely necessary
but helpful.
6) 6) I do not see where the timer ISR code is, or that you have used a C ISR to
handle it (whiuch would require you mod the boot.tpl file or the tool generated
ISR placeholder for code) ?
Regards, Dana.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dana's point 3
Of course you may use registers to change component behaveour. I suggest to start doing that to optimize an already error-free running project. When something goes wrong it can turn out to be VERY difficult laying handsd on the error if there are multiple potential sources for misbehaveour.
To rule a project (in opposite to "The project rules me") I cling to the words "divide et impera"
Dividing the project into small parts, providing testcases for each of such a "module" together and finally integrate all the functionalities.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Note, you do some register writes that are redundant. That is when you set the
component proerties, they come into effect when program starts up and stay that
way until a reg write or applicable API is used. So if you set gain to 48, and never
change it, just set in properties and drop using equivalent reg write/API.
Note, there is one case where you would want to issue a no change write to a reg
or use of API, thats in high rel continuous computing type designs, where a dropped
bit is taken care of by fault tolerance design.
Regards, Dana.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am really confused now, but I'll start all over.
1) First, I will create a project to read the output of an analog signal going into the ADC user module and display the digital value on the LCD.
2) Implement the analog output signal from the PIR sensor and run that signal into the ADC port on the psoc eval board. Display the digital value on the LCD.
3) Create a separate project to implement the timer interrupt and ISR for the LED.
Now how do I comebine this? Considering I have both the ADC and the Timer projects working, Do i just use the ADC project as the main project then implement the Timer LED projecting into the IF statement?
example:
if (ADC data is available)
{trigger the TIMER LED project
counter timer
check again to see if data is available
exit
timer count runs out
turn off LED
is this project simple like this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
"
1) First, I will create a project to read the output of an analog signal going into the ADC user module and display the digital value on the LCD.
"
Let us start with that until it runs to your satisfaction.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Step 2 is easy, just remove the connection from the potentiometer you used to test point no. 1 and connect it to your PIR sensor. You may change the connection internally with a mux or change the wires. The former makes it easy to check in between (during integration phase) when something goes amiss.
"
3) Create a separate project to implement the timer interrupt and ISR for the LED.
"
No need to use a separate project. You may comment the initialization and the access to your ADC and use the same project. This will make the later integration much easier. Check and test the ISR-part and the associated LED. Then go to the next step in your list.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
http://pewa.panasonic.com/assets/pcsd/catalog/papirs-ekmc-catalog.pdf
Here's the data sheet for the PIR sensor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Bob, Here is what I put together so far. I am using port_0_1 for analog input from the PIR sensor.
I am not sure if my interconnect chip wiring is correct in the PSoC in the analog section
---I have Port 0_1 set for analog input that goes into the MUX_0. then from there, the ADC is taking the data passed through the PGA into the ADC. but from here it goes to a comparator, which i set to TRUE. I am stuck here, so i thought that there needs to be an output somewhere from the ADC connected to the port. I am lost here.
1) I need ADC output to go into a specific port.
2) The port then runs to LED and runs through the program to see if data is available.
3) If data is available, LED turns ON.
I have also attached my recent project. What I have here is the LED timer interrupt ( I Commented out the ADC project)
Port 0_1 is connected to an LED. LED initially turns ON when program initiated.
After loop runs out, timer interrupt stops the LED and turns OFF.
Now I want to Combine the ADC program and the LEDTimer program.
How do i do this?
NOTE: The ADC and the LEDTimer programs use the same ports, so i should switch one of them right?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Some thoughts -
1) Keep in mind you can open multiple Designer sessions. So open one
with A/D project, make that your master project, then open another with timer
example/whatever, and view the two screens side by side, cutting and pasting
between the two projects. Best done on dual monitor, or one hi res monitor
using windows shortcut keys to open 2 windows side by side. Select one window
on taskbar, then hold down ctrl key and click other window and select how you
want the two windows to appear.
2) The PIR has option of digital or analog out per below. If you are using A/D for PIR
it might make more sense to use just digital out and timer, saves code and resources
for other uses.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
So, I can get rid of the ADC and just keep the PGA user module and the Timer User module?
1) IF that is true, then I can send the output from the sensor as a digital signal, run it through Port 0_5.
2) If detect motion, execute LED timer program and TUrn on LED and loop counter
as simple as that?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Is there anyway I can get a walk through? or chat via online to make this quicker? Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If you look at the diagram for the digital PIR output case you would -
1) Delay on power up of PIR the "Circuit Stability Time"
2) Feed the sensor output to PGA then to a comparator, so you develop a logic
level signal to drive the enable of the timer. Route
3) Timer clock, since you are trying to detect relatively slow motion, use say 10 - 50 mS.
4) Width of timer has to reflect some minimal length in time of motion. Here I am guessing,
but lets use 50 mS clock, and detect up to 1 minute of motion, So Timer is 60 secs / .05 secs =
1200 ticks, or a 16 bit timer.
5) When comparator out goes high timer starts, and you use ISR on this edge. You can
use a pin to generate ISR off comparator out, or use internal buffer, place it, and enable
it as an ISR. Or use comparatopr ISR. Set a flag, exit. In main test flag, if true, tunr on led
or whatever you want for detection of motion. Could also test timer value that a minimum
amount of motion has been detected.
6) If timer rolls over, 60 secs (or whatever you decide) set its Tc out to interrupt and you have
a false motion ? A motion that lasts too long, not sure how you want to handle.
6) Using another placed buffer (or use comparator ISR) ISR when motion is lost (comparator
out falls) and use that ISR to set a flag, which in turn resets timer count (timer is now stopped
because enable is false, low from comparator).
Sort of an overview. I do not knbow what criteria you want to detect motion, and when motion
is considere illegitimate, you have to modify code to take care of that and above settings.
Regards, Dana.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In 3 above route Comparator out to timer enable.
Regards, Dana.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
awesome. I got the project to work using the application notes you gave me.
How do I set a time limit for how long the LED turns on? say, 5 seconds.
1) PIR detects motion waving hand. LED turns on.
2) If motion detected again, reset timer to 5 seconds.
3) Else let timer run out to 5 seconds, turn OFF led.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
When detecting a move, stop a 5 second timer, load the period register anew and start the timer again, set LED on. This will ensure a contineous signal as long as there is a movement seen.
When timer expires (interrupt-routine) stop timer and clear LED
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
As an aside, looking at digital out of PIR, looks like open drain PMOS to Vdd
rail, so you want a light pulldown to ground. Compute that off fact at Vdd - .5
it can source 100 uA max. Since it pulls to Vdd - .5, if you are running it at same
Vdd as PSOC, just interface that to enable of Timer. In other words eliminate PGA
and comparator, no need for them.
Also not knowing if that output is well conditioned, when motion results in noise
dominated output, you might want to debounce it like a mechanical contact. In
this case you might want to gate the enable to the timer with the debounce detect
routine you write.
Attached some debounce ref material.
Regards, Dana.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In fact if you look at notes below and use of one shot that indicates
PIR not well conditioned for noise, so I would advise using a debounce
routine.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
One error in my posting, I forgot PSOC 1 Timers do not have HW enable.
So just use pin polling or isr to enable Timer via API write.
To effect it as a gated timer use your debounce code to qualify gate API
write.
Regards, Dana.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hey,,tanmanie
As per your last depicted post I think 5 sec of delay would be ok for detecting a particular move and I guess there would be a contineous signal as long as there is a movement seen and it would work like a motion sensor security lighting.