Valley Robotics
September 09, 2010, 09:23:21 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Robotics Presentations:
1) October 16 - ALFA Conference at Monterrey, Mexico.
2) TBD - Los Fresnos Elementary
 
   Home   Chat Help Search Calendar Blog Login Register  
Pages: [1]
  Print  
Author Topic: pic programming  (Read 2427 times)
oelias
Newbie
*
Posts: 8


View Profile Email
« on: December 21, 2009, 12:45:12 PM »

Need some help in programming a pic16886 on a fr28 I/O board(aka rs232 relay control board). This board is to be used to monitor the environment for bacteria growth.

In the end, I must be able to collect data using sensors (temperature(thermocouple), ph (ph sensor), light (photo electric sensor)) and be able retrieve the data collected.

Any assistance is appreciated. Note: I have some basic knowledge in programming in C++, never done something like this.

I cannot attach any files because of the size, but do have info on the board and pic.

THX

Logged
Heriberto
Administrator
Jr. Member
*****
Posts: 51


heribertor88
View Profile WWW Email
« Reply #1 on: December 21, 2009, 06:44:09 PM »

Great!  If you have basic knowledge of C++ then that will do.  You will program it in C.  I recommend MPLAB because it's free and it provides more debugging tools than any other compiler.  An alternative and more powerful platform is Matlab, but do you know how to use this?

For others searching the PIC's specs. it's below:
http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en026562

If you have windows then use hyperterminal to communicate in whatever baud rate you prefer.  (make sure the hyperterminal in windows knows your desired baud rate)

This PIC uses 11 channels at 10-bit resolution.  For you to interpret this data you need to convert analog(0-5v) to digital(binary).  Since it's binary at 10-bit, that equals 1024 steps or levels of resolution.  You can split the 5 volts into 1024 steps and output this to the windows hyperterminal once your ADC (Analog to Digital Converter) has converted the signal.

comments = //

//Your programming should reflect the output hence here are a few lines to get you started:

////////////////////////////////////////////////////////////////////////////////////////start of oscar_data_acquisition.c

#include <16F886.H>       //browse and download it online

//Declare your global variables:

#define photo_sensor PIN??     //assign which pin the sensor is outputting data to
#define temp_sensor  PIN??
#define ph_sensor      PIN??
int photo =0;
int temp  =0;
int ph      =0;

//standard initiation
#define RS232_XMIT     PIN_A1  //Transmission line
#define RS232_RCV      PIN_A0  //Receiving line

#use delay(clock=?)      //input number of instructions per sec
#use rs232(baud=9600, xmit=RS232_XMIT, rcv=RS232_RCV)  //9600 is sort of a standard and is a descent speed.  
                                                                                                  //Not too high not too low, just right.

main(void)  //start of program
{
while(1)
  {
   do{
        //a2d read photo sensor
        delay_ms(500);               // Use delays for stabilization in the system(normally after you read from an analog sensor)

        rprintf("photo sensor:%d\r\n",photo);  //displays your sensor data


        //a2d read temp sensor
        delay_ms(500);               // Use delays for stabilization in the system(normally after you read from an analog sensor)

        rprintf("temp sensor:%d\r\n",temp);  //displays your sensor data


        //a2d read ph sensor
        delay_ms(500);               // Use delays for stabilization in the system(normally after you read from an analog sensor)

        rprintf("ph sensor:%d\r\n",ph);  //displays your sensor data
        }
  }
} //end of main

////////////////////////////////////////////////////////////////////////////////////////end


This is something to get you going in the right path.  The code is generic to PIC's and the a2d conversion is far more complex than just "//a2d read temp sensor", but do read more into it.  Come back to the forum for more questions.  

Let us know if you know how to use Matlab.
I could not find specs for your board.  Can you please email me the specs at heribertor88 (at) yahoo (dot) com
Thanks and update us of your progress.  I wish you luck!

Thanks
Heriberto
« Last Edit: December 21, 2009, 06:46:26 PM by Heriberto » Logged
oelias
Newbie
*
Posts: 8


View Profile Email
« Reply #2 on: December 22, 2009, 01:38:38 PM »

I am familiar with matlab, but i have only used it to write mathematical codes (DE solvers, intergrals)
Logged
oelias
Newbie
*
Posts: 8


View Profile Email
« Reply #3 on: December 22, 2009, 04:16:37 PM »

Update on pic programming project

I have downloaded and installed mplab v8.43.

Having trouble with the hyperterminal.
This website helped in setting the hyperterminal.(rule-4)
http://www.best-microcontroller-projects.com/rs232-work.html

I can set it up, but now what? Huh

Baud rate is the bits per second?

more time will be spent researching. back to youtube.

thx
Logged
Heriberto
Administrator
Jr. Member
*****
Posts: 51


heribertor88
View Profile WWW Email
« Reply #4 on: December 22, 2009, 11:43:45 PM »

now you have to program your PIC to

1. make sure both hyperterminal and your processor are speaking
    in the same baud rate(BPS: bits per second)
            note: it may not always be BPS, but it is in our case since we are using
            2 devices that speak in digital format
2. read analog sensor data/convert to digital(10-bit)
3. stabilize system after every use of analog input
4. output through serial (command: rprintf)
5. log in hyperterminal
6. go to matlab or excel and chart your data

I provided some very elementary startup code for your PIC.

An alternative is to buy a data acquisition device specific for Matlab and log in real time.  The benefit of this is that you have a graphical user interface and it automatically logs data for you.  Much more powerful!

Heriberto
Logged
oelias
Newbie
*
Posts: 8


View Profile Email
« Reply #5 on: January 11, 2010, 12:41:32 PM »

Sensor application Pic programming status:

It has seemed that I have shorted or burned out the pic. it gets hot when the power supply is plugged in. bad sign i guess

I have purchased a microcontroller kit from radio shack to practice while I still wait for the pic replacement. this has been very helpful on how microcontrollers work. it uses a program called basic stamp. is this the famous program called basic? well this has many examples of what a microcontroller can do. from controlling servo moters to lighting leds. it even has explanations on how to sense light and get some readings with a cds cell (one sensor down two to go). 

Some more research has been done on the other two sensors. (ph and temp) for temp a rtd could be used. this is resistance varying resistor that changes because of temp. the same principle from the cds cell could be used to sense temperature.

the ph sensor is a duzy. the sensor used in the lab have a bnc connector at the end. i dont know how to plug it to the board.
Logged
Heriberto
Administrator
Jr. Member
*****
Posts: 51


heribertor88
View Profile WWW Email
« Reply #6 on: January 11, 2010, 05:58:06 PM »

Good pace, keep it up!  Yeah replace pic and do a continuity test without power hooked up to it. This is to validate that all of your components are still working.  Sometimes capacitors give in when you over volt them so the cont test can help you debug if this happenend or not.

As for the bnc connector just buy a male or female connector to the other end(only if you want to keep the input bnc) so that you strip the cable to it's core.  Remember the inside is always positive while the outside is ground or negative.  If you do not care to keep the input bnc connector then cut in with some wire cutters and use the core for positive and outside as ground.  It's a resistance sensor so just hook it up to your ADC(analog to digital converter).

The Stamp microcontroller you bought can do everything you are doing except provide high amps to exterior components. "Use relays"

Basic Stamp is the name of the processor while the language is called "PBasic" which is modeled around the Basic language.

For your sensors use the Analog to Digital Converters embedded in the microcontrollers. also knows as ADC.  Normally they are 10-bit so your resolution will be 1024 steps.  Very accurate considering the sensors are not expensive and have their own percentage of error.
Logged
oelias
Newbie
*
Posts: 8


View Profile Email
« Reply #7 on: January 13, 2010, 11:12:43 AM »

I have replaced the board and pic. this board has a bootloader and firmware already programmed in to the pic and a program called FR88Ctrl was developed for this board.

I noticed that the ADC on the board can only take up to 5 V. when i burned out the previous pic, i had an input of 12V. Ouch! i have taken note of that and am now inputting 3V and it does not sense it! This project is taking more time than I had expected. I cant get this board to work!
Logged
oelias
Newbie
*
Posts: 8


View Profile Email
« Reply #8 on: January 13, 2010, 11:34:19 AM »

what is an I2C and SPI port?
Logged
AirbornG
Newbie
*
Posts: 1


View Profile
« Reply #9 on: March 24, 2010, 08:13:19 PM »

Hi,

I was searching for the same as you and found this thread. Have you got any furder? Did you complete the implementation?

I intend to do the same for controling an aquarium's pH and for that I am collecting information.
For those interested this links might help:

http://www.emesys.com/OL2ph.htm
http://damien.douxchamps.net/elec/ph_meter/
http://www.edn.com/contents/images/101702di.pdf
http://www.electro-tech-online.com/attachments/electronic-projects/21692d1218729019-ph-amplifier-micro-ph_amplifier.pdf
http://www.66pacific.com/ph/simplest_ph.aspx
Logged
Heriberto
Administrator
Jr. Member
*****
Posts: 51


heribertor88
View Profile WWW Email
« Reply #10 on: March 24, 2010, 09:50:19 PM »

what is an I2C and SPI port?


Oscar, I2C uses less pins than SPI, but normally SPI uses less power.  Both are communication protocols that enable you to efficiently talk from microcontroller to sensors, other microcontrollers or even mini pc's.  For example, I bought a propeller microcontroller and I'm limited on the pins I can use so I need to use SPI or I2C to avoid using lots of pins on the microcontroller.  I ordered a 4 channel at 12-bit Analog to Digital Converter with SPI output.  I can now easily and efficiently have the processor communicate with the ADC as opposed to using many pins on my microcontroller.  Now only 4 pins are used. Another great advantage is the ability to daisy chain components that communicate through i2c or SPI.  This site explains SPI further.

http://www.best-microcontroller-projects.com/spi-interface.html

Heriberto
Logged
oelias
Newbie
*
Posts: 8


View Profile Email
« Reply #11 on: March 27, 2010, 03:06:31 PM »

Quote
Have you got any furder? Did you complete the implementation?
Yes and No.
Instead of building my own micro controller to store control the sensor reading, I have decided to buy a data-logger from Campbell Scientific. This piece of equipment will allow me to do everything I was trying to do with the pic. So instead of reinventing the wheel, I have decided to go with the data-logger and just implement the sensors that are already in the lab. They are quite expensive but will save me a lot of time and headaches.

Thanks for the link Heriberto. It was very informing.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!