|
|
View previous topic :: View next topic |
Author |
Message |
kupikupi
Joined: 03 Sep 2005 Posts: 31
|
can anyone help ? i dont know how to decode sony IR signal |
Posted: Sun Sep 04, 2005 2:07 am |
|
|
could anyone explain to me how would i use the ccp(capture/compare/PWM) function?? really need help here,... i'm new to C and PIC.. i've done some readings but i still don't get ti .. coz the examples are all the assembly which i only have 1& knowledge about .. while my C is that good..
I'm actually using an IR remote control to control 2 motors of a cart thru a PIC18F452.. i understood that the IR signal into the PIC will be pulses... so someone told me to use the capture function .. but i dont know how ..
1. how do i read it
2. how do i measure it
3. how do i represent the decoded signal ??
4. how would i use the deccoded signal to drive the motor ?
i've been searching all over for examples..all i got was examples in assembly which i could hardly understand... and i need to get this done urgently..
really appreciate anyone who could help me here,... thax alot ..
so there are 2 ccp channels in my PIC.. one to read falling edge and another to read rising edge .. and i need to asscociate timers with it .. but i dont know how..
Last edited by kupikupi on Fri Oct 14, 2005 4:14 am; edited 1 time in total |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Sun Sep 04, 2005 9:20 am |
|
|
This uses an external interrupt.
http://www.ccsinfo.com/forum/viewtopic.php?t=21290
You talk about controlling 2 motors. This might require the use of 2 PWM's so you wouldn't be able to use the CCP module for the IR if you need 2 separate PWM's. I'd suggest that you read the pic datasheet. Most of all, the sections explaining the different modules (CCP,timers,A/D,interrupts ,etc..). |
|
|
kupikupi
Joined: 03 Sep 2005 Posts: 31
|
|
Posted: Sun Sep 04, 2005 9:38 am |
|
|
Mark wrote: | This uses an external interrupt.
http://www.ccsinfo.com/forum/viewtopic.php?t=21290
You talk about controlling 2 motors. This might require the use of 2 PWM's so you wouldn't be able to use the CCP module for the IR if you need 2 separate PWM's. I'd suggest that you read the pic datasheet. Most of all, the sections explaining the different modules (CCP,timers,A/D,interrupts ,etc..). |
thanx alot for the reply ..Mark .. really appreciate that... actually i've tried reading the datasheet .. i kept reading it .. but i just could not understand.. 1st of all i really new to pic ..and my assembly is really˛ bad.... any suggestion on what i could do ??
and yes mark .. u mentioned about both ccp channels being used... what should i do . i have to use other modules for the IR ?? like ADC?? could u enlighten me on how should i carry on with my project.?? i'm really confused, desperate and running out of time .. thanx alot for the reply... |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Sun Sep 04, 2005 10:15 am |
|
|
The link I posted says that it uses one of the external interrupts to decode the signals. This means that both pwm channels would be free to drive separate motors.
Most of the pic asm in the datasheets is pretty easy to understand. Most is just setting register values which isn't that hard to understand, especially if you read what the instruction does. I don't know of any good learning examples other than searching the forum for other users that have asked the same questions about resources for learning. I started about 8 years ago when an engineer left our company. I took his position and learned mainly through reading datasheets. If you can program in C already, then it shouldn't be that hard to learn how to do it for a PIC.
Running out of time.... This must be a school project. Am I right? |
|
|
kupikupi
Joined: 03 Sep 2005 Posts: 31
|
|
Posted: Sun Sep 04, 2005 10:32 am |
|
|
Mark wrote: | The link I posted says that it uses one of the external interrupts to decode the signals. This means that both pwm channels would be free to drive separate motors.
Most of the pic asm in the datasheets is pretty easy to understand. Most is just setting register values which isn't that hard to understand, especially if you read what the instruction does. I don't know of any good learning examples other than searching the forum for other users that have asked the same questions about resources for learning. I started about 8 years ago when an engineer left our company. I took his position and learned mainly through reading datasheets. If you can program in C already, then it shouldn't be that hard to learn how to do it for a PIC.
Running out of time.... This must be a school project. Am I right? |
yes ..u are right .. a school project.. and the lecturer doesnt know anything about PIC... so we have to search high and low for help... well... i'm still learning how to program in C .. i keep reading the datasheets .. i keep wondering how it really works..
i wanna ask u Mark .. so it seems that different pin in the PIC has different functions.. say for ADC ..when i input some analog signal .. does it automatically converts everything and stores the results somewhere? all i need to do is read the results?? does the data sheet tell how it converts and how is the result represented?? do all differnt pins have its own instruction to execute?
i need some advice from u Mark.. what do u think i should do as now??as im still learning C and really new to PIC.does reading the datasheet help ??(i've been reading it for the past 3 weeks) i've got 3 weeks more to complete the whole project.. i think i could complete it in time if i have a guide to how i should continue.. coz right now i'm really stuck ... |
|
|
MikeValencia
Joined: 04 Aug 2004 Posts: 238 Location: Chicago
|
|
Posted: Sun Sep 04, 2005 11:32 am |
|
|
kupikupi wrote: |
i need some advice from u Mark.. what do u think i should do as now??as im still learning C and really new to PIC.does reading the datasheet help ??(i've been reading it for the past 3 weeks) i've got 3 weeks more to complete the whole project.. i think i could complete it in time if i have a guide to how i should continue.. coz right now i'm really stuck ... |
No offense, but I think you should drop that course...FAST!!!
If part of passing the course is to have working code, then you're screwed. If the project is due in 3 weeks, and all you've done for the past 3 weeks is to read, read, and read, without even attempting to write simple code to blink an LED, then I really think you should throw in the towel, at least for this semester.
With three weeks left, your only option now would be to "contract" this work out to someone. |
|
|
kupikupi
Joined: 03 Sep 2005 Posts: 31
|
|
Posted: Sun Sep 04, 2005 6:40 pm |
|
|
MikeValencia wrote: | kupikupi wrote: |
i need some advice from u Mark.. what do u think i should do as now??as im still learning C and really new to PIC.does reading the datasheet help ??(i've been reading it for the past 3 weeks) i've got 3 weeks more to complete the whole project.. i think i could complete it in time if i have a guide to how i should continue.. coz right now i'm really stuck ... |
No offense, but I think you should drop that course...FAST!!!
If part of passing the course is to have working code, then you're screwed. If the project is due in 3 weeks, and all you've done for the past 3 weeks is to read, read, and read, without even attempting to write simple code to blink an LED, then I really think you should throw in the towel, at least for this semester.
With three weeks left, your only option now would be to "contract" this work out to someone. |
i could write a LED blinking program ....i just need some guide on how to associate ccp with timers and i'm still learning on how the interrupts work .. which think i'm on the right track ... once i get some ideas.. i could strart writing programs.. hope u guys could guide me in learning this.. thanx alot.. |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Sun Sep 04, 2005 8:47 pm |
|
|
MikeValencia wrote: | kupikupi wrote: |
i need some advice from u Mark.. what do u think i should do as now??as im still learning C and really new to PIC.does reading the datasheet help ??(i've been reading it for the past 3 weeks) i've got 3 weeks more to complete the whole project.. i think i could complete it in time if i have a guide to how i should continue.. coz right now i'm really stuck ... |
No offense, but I think you should drop that course...FAST!!!
If part of passing the course is to have working code, then you're screwed. If the project is due in 3 weeks, and all you've done for the past 3 weeks is to read, read, and read, without even attempting to write simple code to blink an LED, then I really think you should throw in the towel, at least for this semester.
With three weeks left, your only option now would be to "contract" this work out to someone. |
Now that's not good advice. |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Sun Sep 04, 2005 8:54 pm |
|
|
Now I am curious to know what type of class this is and what is actually taught there. It seems that there are many students that post questions here and it is like they know nothing at all about programming pics.
Quote: | so it seems that different pin in the PIC has different functions | Yes, the datasheet will tell you what each pin does.
Quote: | i keep reading the datasheets | Good for you. Its the best way.
Quote: | when i input some analog signal .. does it automatically converts everything and stores the results somewhere? | Almost, you have to setup the ADC module and tell it to start. Then the result is stored in a register and the Go/Done flag is cleared. Just so you know, you could set this up to interrupt you when the conversion is complete.
Quote: | does the data sheet tell how it converts and how is the result represented?? | Absolutely.
Quote: | do all differnt pins have its own instruction to execute?
| Not sure what you mean by that.
Quote: | i need some advice from u Mark.. what do u think i should do as now?? | I think you should post your complete assignment and I as well as others will guide you. I am not going to do your assignment for you but will help you help yourself. |
|
|
kupikupi
Joined: 03 Sep 2005 Posts: 31
|
|
Posted: Mon Sep 05, 2005 5:38 am |
|
|
Quote: | do all differnt pins have its own instruction to execute? |
Quote: | Not sure what you mean by that. |
well.. the ADC converter does conversion automatically.. does other pin also does something else automatically?? because i think we have to do all conversion ourselves... i didnt know the PIC would also do something
Last edited by kupikupi on Mon Sep 05, 2005 5:47 am; edited 2 times in total |
|
|
kupikupi
Joined: 03 Sep 2005 Posts: 31
|
|
Posted: Mon Sep 05, 2005 5:39 am |
|
|
oh great ... thanx for the offer Mark .. really needed that...
well ... about my subject.... 70 % of it is the design project and 30% is the final exams.. well... teaching should be about microcontrollers.. but so far.. after 8 weeks of classes .. i dont seem to learn anything ... all learning about PIC has to be done myself.. the lecturer is of no help at all.. he doesnt seem to know anything about PIC... i think i know more than him .. can u imagine . everytime we ask him something about PIC.. he asks us back.. so u can figure how we struggle here. .. well at least his counterpart in the main campus guides his student thru the whole project..
back to my project.. im actually building a mini wheelchair controlled by PIC18F452 using a remote control.
so we started out with the LED blinking program ... but that was just to test the PIC..
i'll start with the IR part.. i need to use a remote control to control the direction of the wheelchair. my IR is made up of the transmitter ( i'm planning to use the SONY remote control as lots of peole have recommended) and a receiver ( an IR detector called TSOP1738) so i understood that the IR detector receives the signal from the remote control and converts the signal to digital and then the PIC decodes the digital signal which is used to drive the motor. some suggested that i use the ccp function to decode the signal.. but since i only have 2 PWM channels.. which i think i'll need to drive the motor .. im still figuring which to use the decode the signal ..
as for the motor, u suggested ealier that i need the PWM channels to control the motors, but the motor is not actually driven by the PIC. it is driven by a H-bridge L298 . so i just need the output from the IR signal to be in binary form the drive the motor. ( please correct me i'm wrong)
at the last part will be the wall sensor( the wheelchair will move away when it detects a wall or obstacle) . which i think i'll leave it out unless i have the time to do it. it will be an IR sensor .. but i havent figure the rest yet..
now my problem will be the IR part which im really confused ... i think if i could do the IR part.. i coud manage the motor part without much trouble...
so grateful to have ur help here Mark .. great to meet really really nice people here... i wont expect u to do the whole thing for me .. coz i really want to learn somehting .. not just complete my project.. thanx alot..and to all the who will help me.. a big thank u for wanting to help me.. |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Mon Sep 05, 2005 8:16 am |
|
|
Quote: | as for the motor, u suggested ealier that i need the PWM channels to control the motors, but the motor is not actually driven by the PIC. it is driven by a H-bridge L298 . so i just need the output from the IR signal to be in binary form the drive the motor. ( please correct me i'm wrong)
| Depends on how you look at it. The PIC is controlling the H-bridge which does control the motor so that means that the PIC is controlling the motor. You will need a pwm signal if you want variable speed. You definitely want to control the speed when turning but you could do this by manually generating the signal by toggling the pins. The first thing I'd do is get the IR working with the code posted in the link. Since you don't have an LCD (probably) you can use the printf commands to display the data on a PC. |
|
|
kupikupi
Joined: 03 Sep 2005 Posts: 31
|
|
Posted: Mon Sep 05, 2005 8:27 am |
|
|
Mark wrote: | Quote: | as for the motor, u suggested ealier that i need the PWM channels to control the motors, but the motor is not actually driven by the PIC. it is driven by a H-bridge L298 . so i just need the output from the IR signal to be in binary form the drive the motor. ( please correct me i'm wrong)
| Depends on how you look at it. The PIC is controlling the H-bridge which does control the motor so that means that the PIC is controlling the motor. You will need a pwm signal if you want variable speed. You definitely want to control the speed when turning but you could do this by manually generating the signal by toggling the pins. The first thing I'd do is get the IR working with the code posted in the link. Since you don't have an LCD (probably) you can use the printf commands to display the data on a PC. |
Thanx Mark.... so i could use the codes directly( just use printf ) .. and i connect the PIC to the pc thru serial port?? dont i need a bootloader ?? let me go step by step..
1.i change the codes with printf ...
2.upload the codes into the PIC
3. connect thru serial port to pc..
but what software do i use?? |
|
|
MikeValencia
Joined: 04 Aug 2004 Posts: 238 Location: Chicago
|
|
Posted: Mon Sep 05, 2005 10:37 am |
|
|
Quote: |
Thanx Mark.... so i could use the codes directly( just use printf ) .. and i connect the PIC to the pc thru serial port?? dont i need a bootloader ?? let me go step by step..
1.i change the codes with printf ...
2.upload the codes into the PIC
3. connect thru serial port to pc..
but what software do i use?? |
Look at page 22 of this .pdf document:
http://ww1.microchip.com/downloads/en/DeviceDoc/51275b.pdf
You will see a MAX232 chip, along with a a few .1uF capacitors. It is very easy to get the MAX232 from a local Fry's, maybe Radio Shack, and for sure, Digikey. Hopefully, your EE lab has it.
Breadboard the circuit together.
Now cut and paste this code:
Code: |
#include <18F452.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000) /* one instruction=1us? */
void main(void)
{
printf ("Hello world.\r\n");
while (1);
}
|
Compile this code and program it into your PIC. What programmer are you using? ICD-2? Promate? I hope your lab provides a programmer!
You ask what software to use on the PC to communicate with the PIC? Use Hyperterminal, with the following settings:
9600 bits per second
8 data bits
Parity NONE
Stop bits 1
Flow control HARDWARE
Hyperterminal is supplied with every Windows-based PC. If you compiled correctly and have the proper settings in Hyperterminal, then you should see your "Hello world." line printed the moment you reset the PIC.
That is how to do printf. Once your Hello World is working, then you can go on to display data as Mark says:
Code: |
mydata = 24;
...
printf (mydata = %d\r\n", mydata);
...
|
The difference between a printf on a PC (Linux or Windows) vs. an "embedded" printf i've noticed is the "\r". In PC apps, i usually just write a "\n". On a PIC's printf though, you need the \r\n combination to get a proper carriage return and line feed. The \n will only give you a line feed.
You ask about a Bootloader. A bootloader is not essential for your project, so don't worry about it now. Just focus on being able to flash the PIC with an ICD. |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Mon Sep 05, 2005 12:49 pm |
|
|
MikeValencia wrote: | Quote: |
Thanx Mark.... so i could use the codes directly( just use printf ) .. and i connect the PIC to the pc thru serial port?? dont i need a bootloader ?? let me go step by step..
1.i change the codes with printf ...
2.upload the codes into the PIC
3. connect thru serial port to pc..
but what software do i use?? |
Look at page 22 of this .pdf document:
http://ww1.microchip.com/downloads/en/DeviceDoc/51275b.pdf
You will see a MAX232 chip, along with a a few .1uF capacitors. It is very easy to get the MAX232 from a local Fry's, maybe Radio Shack, and for sure, Digikey. Hopefully, your EE lab has it.
Breadboard the circuit together.
Now cut and paste this code:
Code: |
#include <18F452.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000) /* one instruction=1us? */
void main(void)
{
printf ("Hello world.\r\n");
while (1);
}
|
Compile this code and program it into your PIC. What programmer are you using? ICD-2? Promate? I hope your lab provides a programmer!
You ask what software to use on the PC to communicate with the PIC? Use Hyperterminal, with the following settings:
9600 bits per second
8 data bits
Parity NONE
Stop bits 1
Flow control HARDWARE
Hyperterminal is supplied with every Windows-based PC. If you compiled correctly and have the proper settings in Hyperterminal, then you should see your "Hello world." line printed the moment you reset the PIC.
That is how to do printf. Once your Hello World is working, then you can go on to display data as Mark says:
Code: |
mydata = 24;
...
printf (mydata = %d\r\n", mydata);
...
|
The difference between a printf on a PC (Linux or Windows) vs. an "embedded" printf i've noticed is the "\r". In PC apps, i usually just write a "\n". On a PIC's printf though, you need the \r\n combination to get a proper carriage return and line feed. The \n will only give you a line feed.
You ask about a Bootloader. A bootloader is not essential for your project, so don't worry about it now. Just focus on being able to flash the PIC with an ICD. |
You forgot to include this line
Code: | #use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
|
Flow control should be set to NONE and not HARDWARE. Hardware is for use when using hardware handshanking signals.
Quote: | dont i need a bootloader |
Do you understand what a bootloader is? It is a way of programming a PIC using the serial port. You said that you already have "blinked" leds so I am assuming that you can already program the pic. I think it best to follow Mike's suggestion and get the Hello World working first and then try the IR stuff. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|