- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi all,
I am new to the PSoC platform and am having trouble implementing an ultrasonic and line sensor for a robot.
The arduino code for each is listed below, any help on how i could implement this code with PSoC would be greatly appreciated.
Ultrasonic
/* Tested with HY-SRF05, HC-SR04 The circuit: * VVC connection of the sensor attached to +5V * GND connection of the sensor attached to ground * TRIG connection of the sensor attached to digital pin 12 * ECHO connection of the sensor attached to digital pin 13 */ const int TRIG_PIN = 12;const int ECHO_PIN = 13; void setup() { // initialize serial communication: Serial.begin(9600); pinMode(TRIG_PIN,OUTPUT); pinMode(ECHO_PIN,INPUT);} void loop(){ long duration, distanceCm, distanceIn; // Give a short LOW pulse beforehand to ensure a clean HIGH pulse: digitalWrite(TRIG_PIN, LOW); delayMicroseconds(2); digitalWrite(TRIG_PIN, HIGH); delayMicroseconds(10); digitalWrite(TRIG_PIN, LOW); duration = pulseIn(ECHO_PIN,HIGH); // convert the time into a distance distanceCm = duration / 29.1 / 2 ; distanceIn = duration / 74 / 2; if (distanceCm <= 0){ Serial.println("Out of range"); } else { Serial.print(distanceIn); Serial.print("in, "); Serial.print(distanceCm); Serial.print("cm"); Serial.println(); } delay(1000);}
Line Sensor
- Labels:
-
PSoC 5LP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
have you created a psoc project?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
would be helpful if you post your hardware design as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Do you actually understand the arduino code?
if you do, then it will be pretty straightforward to translate it to psoc funtions. The Arduino code you posted is basically setting pins high and down and using delays to create the pulse and then reading the status of the input pin. But that is not the PSOC way.
The problem with the arduino aproach is that you leave the cpu busy and your system unreponsive for the whole 50ms or more that the measurement takes.
take a look here http://www.cypress.com/?app=forum&id=4749&rID=80281
I have just posted a project using the HC-SR04 that does everything in hardware.
- 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
"Thinking PSoC" takes some experience. We C-coders (I admit here: I am one) usually start by thinking in bits, flags and code. The best way to handle a PSoC project is to start building a schematic. That includes to "know" all (or many) usermodules and what they perform. That takes time.
Building up a schematic which is capable of handling most of the required job will not only use less code but will run faster and does not burden the CPU.
An example: You may time the input of an ultra-sonic distance-sensor by constantly monitoring a pin or you use a timer with a capture-input and get interrupted. Same as easy is to measure the High-time of a signal, just connect the capture- and the enable-input together and provide the timer with an appropiate clock to get the required granulary.
No bit nor byte fiddling, pure hardware.
Hapy wiring
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
And for your line-interface as well:
Why not only transmit the information of the line-state when that state did change? Can be detected with hardware and the program can be informed by an interrupt.
For the access to pins: Just give a name to your pin and access it in your program with pin_Read() or pin_Write(). Which of the physical connections to the outer world you will specify on a different page within the Creator-software so you are nearly completely free which pin to use without changing schematic nor code.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
And one ´(last) hint concerning the calculation of the distance: Sonic air-speed is mostly related to temperature (not atmospheric pressure!!!) which easily will make up an error of 10 per cent. Seems to be quite a few, but in terms of a dent in a car it could be noticeable.
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
We all have been there when we started, but soon after you will "get PSOC" and if you have to work on another mcu you will miss psoc features. lol
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
as for the line sensor, I would also use pwm to set up come cicle. I would recommend using an analog comparator and fire a ISR when there is change from low to high or high to low reflectance. Another aproach is using the ADC where you could ue filtering to get a more robust dsign. Maybe also first measure the analog output from the sensor with the LED turned off to set up a base ambient light/noise floor then set a short pulse to turn the LED and measure the sensor output with the LED on
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
Am presently working on CY8C-KIT-042-BLE PIONEER KIT and PRoC. Can anyone help me for the schematic and a hardware design to interface a ultrasonic sensor on to the development board. Kindly help on the same.
Thank you,
Sunil Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Welcome in the forum, Sunil!
This project is for a different kit, but you can get it to work on your BLE pioneer kit.
Happy coding
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Any ideas on the Pioneer Kit?? i just need the schematic, so that i can build the applications on the schematic window..
Thank you!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You will just need using different pin numbers for your project. The schematics and the programming are included in the project archive.
Bob