PR23, PIC Program

LED Blinking, Walking with Cytron Servo, Displaying RFID, Multi-function Mobile Robot......

PR23, PIC Program

Postby himura_ryuu » Wed May 20, 2009 6:17 pm

Hye all, i'm a newbie here~

I'm currently trying to understand the command line in PR23.

I'm wondering, what does this line means,

"
....
#define CHANNEL0 0b10000001 //AN0 (Ultrasonic)
#define CHANNEL1 0b10002001 //AN1 (Analog Sensor)
.....
"

My question is what does this BOLDED number means???
Anyone can help me???
"Q.E.D
Shoumei Shouryou"
himura_ryuu
Apprentice
 
Posts: 34
Joined: Wed May 20, 2009 6:08 pm

Re: PR23, PIC Program

Postby AMD » Wed May 20, 2009 7:26 pm

hmm.. me too not so sure what the bold mean...
i already left the programming for 10 years (machine lang)...
...
neway, AFAIR I think the bold item that u asked is
the address location in the PIC memory...
when u do a programming, u have to determine
a memmory location for every I/O device that u use,
so u can retrieve any I/O status from the device...

p.s. - correct me if I'm wrong...
MOVE FOR FREEDOM
User avatar
AMD
Freshie
 
Posts: 7
Joined: Wed May 20, 2009 3:44 am

Re: PR23, PIC Program

Postby sich » Thu May 21, 2009 11:49 am

I think the program u pasted here got problem.
....
#define CHANNEL0 0b10000001 //AN0 (Ultrasonic)
#define CHANNEL1 0b10002001 //AN1 (Analog Sensor)
.....


There shouldn't have '2' inside a binary number. 'OB' means the digits behind it is binary numbers. So it should be 1 or 0 only. So lets assume the '2' is '1' here and the code becomes like this:
#define CHANNEL0 0b10000001 //AN0 (Ultrasonic)
#define CHANNEL1 0b10001001 //AN1 (Analog Sensor)


Since it mentioned AN0 and AN1 inside the comments, so it can be a configuration for ADC. Maybe it means when you put 0b10000001 into a function, it configs the ADC to read from AN0, and this'll actually give u the value of ultrasonic. So search for where it uses the 'CHANNEL0' and 'CHANNEL1' in the source code to find the clue.
~> How to ask QUESTIONS the SMART way in FORUM? <~
User avatar
sich
Moderator
 
Posts: 603
Joined: Tue Apr 21, 2009 2:15 pm

Re: PR23, PIC Program

Postby himura_ryuu » Thu May 21, 2009 6:28 pm

sich WROTE:I think the program u pasted here got problem.
....
#define CHANNEL0 0b10000001 //AN0 (Ultrasonic)
#define CHANNEL1 0b10002001 //AN1 (Analog Sensor)
.....


There shouldn't have '2' inside a binary number. 'OB' means the digits behind it is binary numbers. So it should be 1 or 0 only. So lets assume the '2' is '1' here and the code becomes like this:
#define CHANNEL0 0b10000001 //AN0 (Ultrasonic)
#define CHANNEL1 0b10001001 //AN1 (Analog Sensor)


Since it mentioned AN0 and AN1 inside the comments, so it can be a configuration for ADC. Maybe it means when you put 0b10000001 into a function, it configs the ADC to read from AN0, and this'll actually give u the value of ultrasonic. So search for where it uses the 'CHANNEL0' and 'CHANNEL1' in the source code to find the clue.


Thank you sich~
However, i still don't understand the number~ How can we determine the memory??
From the datasheet of the microC???
ok, let say i'm trying to attach new new analog sensor into a new channel, say channel 2, is it right if i wrote it this way,

"
....
#define CHANNEL0 0b10000001 //AN0 (Ultrasonic)
#define CHANNEL1 0b10001001 //AN1 (Analog Sensor)
#define CHANNEL2 0b10001001 //AN2 (another Analog Sensor)

....
"

Sorry for the question~ I'm a noob~
"Q.E.D
Shoumei Shouryou"
himura_ryuu
Apprentice
 
Posts: 34
Joined: Wed May 20, 2009 6:08 pm

Re: PR23, PIC Program

Postby sich » Fri May 22, 2009 12:21 am

You need to read the datasheet of the PIC used for that project. Look into the Analog to Digital Conversion section. I believe the code configured the analog channel for conversion, and the binary data is the configuration needed to select the channel.
#define CHANNEL1 0b10001001 //AN1 (Analog Sensor)
If this configures the AN1, i don't think your code:
#define CHANNEL2 0b10001001 //AN2 (another Analog Sensor)
will configure AN2. It should be another set of binary data.

What u need to do is CTRL+F the source code for that two words (CHANNEL1 & CHANNEL2) to see where they've been used. Then figure out where the binary values (CHANNEL1 & CHANNEL2 represent two sets of binary values after the '#define' declaration) are placed. From there, it'll lead u to the right register that u need to find inside the PIC datasheet. I strongly believe by studying the register configuration, u'll get the answer.
**Always remember to read the datasheet for more info**
~> How to ask QUESTIONS the SMART way in FORUM? <~
User avatar
sich
Moderator
 
Posts: 603
Joined: Tue Apr 21, 2009 2:15 pm

Re: PR23, PIC Program

Postby himura_ryuu » Fri May 22, 2009 8:00 am

sich WROTE:You need to read the datasheet of the PIC used for that project. Look into the Analog to Digital Conversion section. I believe the code configured the analog channel for conversion, and the binary data is the configuration needed to select the channel.
#define CHANNEL1 0b10001001 //AN1 (Analog Sensor)
If this configures the AN1, i don't think your code:
#define CHANNEL2 0b10001001 //AN2 (another Analog Sensor)
will configure AN2. It should be another set of binary data.

What u need to do is CTRL+F the source code for that two words (CHANNEL1 & CHANNEL2) to see where they've been used. Then figure out where the binary values (CHANNEL1 & CHANNEL2 represent two sets of binary values after the '#define' declaration) are placed. From there, it'll lead u to the right register that u need to find inside the PIC datasheet. I strongly believe by studying the register configuration, u'll get the answer.
**Always remember to read the datasheet for more info**


Ok, got it sich~ Huhuhuhu~
Thank you so much~ :)
"Q.E.D
Shoumei Shouryou"
himura_ryuu
Apprentice
 
Posts: 34
Joined: Wed May 20, 2009 6:08 pm

Re: PR23, PIC Program

Postby himura_ryuu » Fri May 22, 2009 8:16 am

New Question

It the PR23 Source Code, the sensor is read/used via mode

So, how can we modified the mode of sensor so that, say the analog sensor and ultrasonic to be used on the same time???

The ultrasonic is used as center sensor and another two sets of analog sensor is used on the left and right side.

"
...
void ultrasonic(void)
{
int distance;
n=1;
.....
if (distance>40)
....

void analog_sen(void)
{
int distance;
....
if (distance>200)
...
"


In the ultrasonic mode, the if function written (distance>40)
This 40 is measured in what unit???

In the analog_sensor mode, the if function written (distance>200)
This 200 is measured in what unit???

Huhuhu~ Again, number makes me confused~

In LCD program,
"
lcd_goto(20) //send string to second line
"


I believe it says clearly that this LCD command is used to display on the second line of the LCD Display. However, do this number 20 is fixed??? I mean, can i change the number to another number but having the same function of sending data to second line display???

Sorry for questioning so much~ :oops:
"Q.E.D
Shoumei Shouryou"
himura_ryuu
Apprentice
 
Posts: 34
Joined: Wed May 20, 2009 6:08 pm

Re: PR23, PIC Program

Postby doraemon » Mon May 25, 2009 10:42 pm

hi, as i know the value for analog sensor and ultrasonic sensor use function to read the value and the sensors are connected to different pins of the PIC, so it shouldn't be a problem to read the value in the same time, you may just assign the return value of the function for reading analog sensor and ultrasonic sensor to different variable.

as for the meaning of distance>40 or distance > 100, for the analog sensor, if i no mistaken, the 40 and 100 actually is the value after ADC, the output voltage changed over distance from the sensor is 2.45v-0.45v, by using the formula in the source code and after do some calculation, you will get the meaning of the number, if based on the datasheet, the distance should be 10cm -80cm. as for ultrasonic sensor, it can be read by 3 method, which is PWM, ADC and UART, so maybe you can refer to the datasheet to have better understanding..
doraemon
Freshie
 
Posts: 5
Joined: Mon May 25, 2009 10:25 pm

Re: PR23, PIC Program

Postby himura_ryuu » Tue May 26, 2009 1:39 am

doraemon WROTE:hi, as i know the value for analog sensor and ultrasonic sensor use function to read the value and the sensors are connected to different pins of the PIC, so it shouldn't be a problem to read the value in the same time, you may just assign the return value of the function for reading analog sensor and ultrasonic sensor to different variable.

as for the meaning of distance>40 or distance > 100, for the analog sensor, if i no mistaken, the 40 and 100 actually is the value after ADC, the output voltage changed over distance from the sensor is 2.45v-0.45v, by using the formula in the source code and after do some calculation, you will get the meaning of the number, if based on the datasheet, the distance should be 10cm -80cm. as for ultrasonic sensor, it can be read by 3 method, which is PWM, ADC and UART, so maybe you can refer to the datasheet to have better understanding..


Thanks for the tips, doraemon~ :D
Basically, again i need to read the datasheet~ huhuhu~
And what do you mean by "you may just assign the return value of the function for reading analog sensor and ultrasonic sensor to different variable"
Can you show me some example?
Does this mean that i can use;
#define CHANNEL1 0b10001001
#define CHANNEL2 0b10001001
??? Or should i change the binaries??
"Q.E.D
Shoumei Shouryou"
himura_ryuu
Apprentice
 
Posts: 34
Joined: Wed May 20, 2009 6:08 pm

Re: PR23, PIC Program

Postby doraemon » Tue May 26, 2009 7:05 pm

oh...the
#define CHANNEL1 0b10001001
#define CHANNEL2 0b10001001
is just to define the analog channel for ultarsonic sensor and analog, u no need to change that,
what i mean by "you may just assign the return value of the function for reading analog sensor and ultrasonic sensor to different variable" is, if you read through the source code, you will found that there is a function, us_value(unsigned char mode) for you to read value from ultrasonic sensor, you may assign a variable, for example:
unsigned int ultrasonicValue; //define variable
ultrasonicValue = us_value(1); //assign ultrasonic value to the variable
to read adc value for ultrasonic sensor.
while for analog, u may just get the value like this:
unsigned int analogSensorValue; //define variable
analogSensorValue=read_adc(CHANNEL1); //assign analog value to the variable

hope this help..
doraemon
Freshie
 
Posts: 5
Joined: Mon May 25, 2009 10:25 pm

Next

Return to DIY Project Set

Who is online

Users browsing this forum: No registered users and 15 guests

cron