View previous topic :: View next topic |
Author |
Message |
kupikupi
Joined: 03 Sep 2005 Posts: 31
|
|
Posted: Wed Sep 07, 2005 2:29 am |
|
|
Mark .. i want to try the codes by newguy on my PIC.. but it's a ccs codes... how do i port it to C18 ?? wat do i have to change?
thanx ... |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Wed Sep 07, 2005 7:27 am |
|
|
Here is a start for you. Remember, I am not going to do your whole project for you. I added some comments where you need to do some stuff.
Code: | #include <p18F452.h>
#include <stdio.h>
#include <usart.h>
// Uncomment the following line if using the ICD debugger
//#define USE_ICD
// Configuration Bits
#pragma config OSC = HS
#pragma config PWRT = ON
#pragma config BOR = ON, BORV = 42
#pragma config CCP2MUX = ON
#pragma config STVR = ON
#pragma config LVP = OFF
#pragma config CP0 = OFF
#pragma config CP1 = OFF
#pragma config CP2 = OFF
#pragma config CP3 = OFF
#pragma config CPB = OFF
#pragma config CPD = OFF
#pragma config WRT0 = OFF
#pragma config WRT1 = OFF
#pragma config WRT2 = OFF
#pragma config WRT3 = OFF
#pragma config WRTB = OFF
#pragma config WRTC = OFF
#pragma config WRTD = OFF
#pragma config EBTR0 = OFF
#pragma config EBTR1 = OFF
#pragma config EBTR2 = OFF
#pragma config EBTR3 = OFF
#pragma config EBTRB = OFF
#pragma config DEBUG = OFF
#ifdef USE_ICD
#pragma config WDT = OFF, WDTPS = 128
#else
#pragma config WDT = ON, WDTPS = 128
#endif /* USE_ICD */
#define enable_global_int() INTCONbits.GIE = 1;\
INTCONbits.PEIE = 1
#define disable_global_int() INTCONbits.GIE = 0;\
INTCONbits.PEIE = 0
#define enable_int0_int() INTCONbits.INT0IE = 1
#define disable_int0_int() INTCONbits.INT0IE = 0
#define enable_timer1_int() PIE1bits.TMR1IE = 1
#define disable_timer1_int() PIE1bits.TMR1IE = 0
#define L_TO_H 1
#define H_TO_L 0
#define ext_int0_edge(x) INTCON2bits.INTEDG0 = x
#define restart_wdt() {_asm clrwdt _endasm}
#define TRUE 1
#define FALSE 0
#define LEAD_IN_LOW 40000 // 8 ms
#define LEAD_IN_TOTAL 60000 // 12 ms
#define MIN_TIME 3000 // 0.6 ms
#define THRESHOLD 8000 // 1.6 ms
#define MAX_TIME 11500 // 2.3 ms
unsigned char overflow_count = 0, rx_state = 0xff;
unsigned long timer_at_start;
unsigned long timer_at_end;
unsigned long low_time;
unsigned long timer_at_mid;
unsigned long period;
unsigned long first_data = 0;
unsigned long second_data = 0;
unsigned long temp1;
unsigned long temp2;
unsigned long timer_at_mid_start;
unsigned char full_cycle = FALSE;
unsigned char got_first = FALSE;
unsigned char data_avail = FALSE;
unsigned char caught_rise = TRUE;
/****************************************************************************
* DESCRIPTION: Low priority interrupt routine
* RETURN: none
* ALGORITHM: none
* NOTES: you may have to save data sections here if you call functions
* or use the math libraries
*****************************************************************************/
#pragma interruptlow InterruptHandlerLow // note that you may
void InterruptHandlerLow(void)
{
//check for external int
if (INTCONbits.INT0IE)
{
if (INTCONbits.INT0IF)
{
INTCONbits.INT0IF = 0;
// To do: Add your int0 code here
}
}
//check for timer1 interrupt
if (PIE1bits.TMR1IE)
{
if (PIR1bits.TMR1IF)
{
PIR1bits.TMR1IF = 0;
// To do: Add your timer1 code here
}
}
/****************************************************************************
* DESCRIPTION: High priority interrupt vector
* PARAMETERS: none
* RETURN: none
* ALGORITHM: none
* NOTES: we are not really using high priority ints.
*****************************************************************************/
#pragma code InterruptVectorHigh = 0x08
void InterruptVectorHigh(void)
{
_asm
goto InterruptHandlerLow //jump to interrupt routine
_endasm
}
#pragma code
/****************************************************************************
* DESCRIPTION: Low priority interrupt vector
* PARAMETERS: none
* RETURN: none
* ALGORITHM: none
* NOTES: none
*****************************************************************************/
#pragma code InterruptVectorLow = 0x18
void InterruptVectorLow(void)
{
_asm
goto InterruptHandlerLow //jump to interrupt routine
_endasm
}
#pragma code
void decode_info(void)
{
// each tick = 200 ns
unsigned char i;
// To do: Add decode_info code here
}
void main(void)
{
OpenTimer1(T1_16BIT_RW & \
T1_PS_1_1 & \
T1_OSC1EN_OFF & \
T1_SOURCE_INT);
ext_int0_edge(H_TO_L);
// To do: Setup the UART
// To do: Setup TRIS registers
enable_int0_int();
enable_timer1_int();
enable_global_int();
while ( TRUE )
{
restart_wdt();
if (full_cycle)
{
full_cycle = FALSE;
decode_info();
}
if (data_avail)
{
data_avail = FALSE;
printf("\fCMD1 = %lx\nCMD2 = %lx", first_data, second_data);
}
}
}
|
Note that you are going to have to do some reading. For instance, you will need to read about Timer1 functions in both CCS and C18 documentation to see the differences. For example:
in CCS is
in C18. You will also want to pay attention to the default data types in CCS. |
|
|
kupikupi
Joined: 03 Sep 2005 Posts: 31
|
|
Posted: Wed Sep 07, 2005 9:25 am |
|
|
ok ... thanx alot for the help Mark .... U've been such a great help ... thank God there are some really really nice people like u here...
i'll have to do some readings before i post some more questions .... but at least i got an idea how i would do it...
thanx |
|
|
kupikupi
Joined: 03 Sep 2005 Posts: 31
|
|
Posted: Thu Oct 13, 2005 1:13 am |
|
|
hi ...
i need a little help here .. .i searched everywhere for how to decode the IR signal from the sony remote control... but i can't seem to find anything .. i asked around .. some said that i have to read the rising edge and falling edge of the signal .. some said binary data bits of 1s and 0s will be input to the PIC from the receiver called TSOP1738 .. so i just need to read the bits and control the motor .. could anyone give me an example on how to decode the IR signal from the sony remote control?? |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Thu Oct 13, 2005 2:32 am |
|
|
kupikupi wrote: | hi ...
i need a little help here .. .i searched everywhere for how to decode the IR signal from the sony remote control... but i can't seem to find anything | I suggest you search a bit harder. I used Google and my problem was I found too many hits.
There are many IR remote controls but only about 4 different protocols. The protocol used by Sony is called SIRCS while Philips uses the well documented RC-5 protocol.
The IR data is modulated onto a carrier with a frequency between 30 to 60kHz, depending on the protocol used. Demodulation is easiest performed by a TSOP17xx where the xx represents the modulation frequency. Often the TSOP1738 is choosen because it has a frequency in between the most used protocols and hence can be used for multiple protocol demodulation.
Try Google search: pic ir receiver sircs |
|
|
kupikupi2 Guest
|
|
Posted: Fri Oct 14, 2005 2:23 am |
|
|
i actually know how the IR works... i'm just not so sure how to decode the signal .. measure the rising edge ?? or read the signal as bits of 1s and 0s .. i need an example how to decode .. could anyone help me ... |
|
|
kupikupi2 Guest
|
|
Posted: Fri Oct 14, 2005 2:31 am |
|
|
my programming is really bad ...so i need a lilttle help on how to decode the signal .... just an example.... thanx very much ... |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
|
kupikupi
Joined: 03 Sep 2005 Posts: 31
|
|
Posted: Fri Oct 14, 2005 10:00 am |
|
|
is it possible to program it without using timers and interrupts??
from the links u gave Mark .. i really find it hard to understand what they are doing.... all i have done now is a simple program the move the car forward, backward, left and right .. but i dont know how to read the IR signal .. the IR receiver TSOP1738 is connected to the pin int0 in the PIC .. but i dont know how to read the signal ... i just need a somple example on how to read it like:
example:
if (int0 == 110110) // is this how i read the signal ?
portB = 0x02; // this thing drives the motor
i need some help on this.. thanx a lot |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1909
|
|
Posted: Fri Oct 14, 2005 10:51 am |
|
|
Look, it's not that hard to understand.
I'm the one that posted the "IR remote code grabber s/w" in the code library.
I used the external interrupt (B0) for that. You tell the PIC what to look for, in terms of a signal present at B0, in order to trigger an interrupt. The external interrupt can be set up to fire when there is a rising edge or when there is a falling edge.
When "something" happens on B0, the external interrupt fires. If a falling edge arrived, then the code sets up the interrupt to fire next if a rising edge is sensed. If a rising edge arrived, the code sets up the interrupt to fire next if a falling edge is sensed. In this manner, you can sense/detect the rising and falling edges from the serial data stream you expect to be at pin B0.
Now, once something happens, for instance a falling edge, note the time. If YOU were doing this, you would look at your watch. The PIC doesn't have a watch, but it does have timers. So when "something" happens at pin B0, note the value of the timer (which I think was timer 1). Save that value. The next time something happens at B0, again note the time. Based on when the "old" event happened and the time of this "new" event, you can determine things. Things such as:
- the high time of the signal
- the low time of the signal
- the period of the signal
Once these things have been sorted out, then you can examine these times to determine more things, such as:
- the signal start (preamble)
- the individual bits being transmitted (1's and 0's)
- the signal end
- whether the signal repeats
- etc.
You determine these things based on what you know about the signal you're trying to demodulate. How is a "1" represented? How is a "0" represented? If the signal is high for x microseconds and low for y microseconds, does that equal a logical "1"? How is the start of a transmission represented? Etc.
NO ONE is going to solve this problem for you. Most posts have been gently (some not so gently, for example this one) pushing you in a certain direction so that you may figure it out for yourself, based on good examples already found here. Read, experiment, and learn. |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Fri Oct 14, 2005 11:43 am |
|
|
kupikupi wrote: | is it possible to program it without using timers and interrupts?? | Yes but it would suck! You would continually have to monitor the input. When a change occured, increment a value until the input changed again (measuring time). Since nothing else can happen while you are measuring, nothing will. Things would stop or if using PWM to control the motors, they would stay at the current level until the routine had finished processing. Use interrupts and timers if you want to do it right. |
|
|
Douglas Kennedy
Joined: 07 Sep 2003 Posts: 755 Location: Florida
|
|
Posted: Fri Oct 14, 2005 12:47 pm |
|
|
Mark and others , I hope you get credit for this school assignment. My Mom always said help those that help themselves..... looks like this teacher is AWOL and these guys are left to help themselves to everybody's code.
This forum could easily get popular with students as they sit back and watch others spoon feed them higher grades. |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1909
|
|
Posted: Fri Oct 14, 2005 1:01 pm |
|
|
Douglas Kennedy wrote: | This forum could easily get popular with students as they sit back and watch others spoon feed them higher grades. |
Too late. Too late. |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Fri Oct 14, 2005 1:36 pm |
|
|
I'm not going to write his code for him. Just point him in the right direction. |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Fri Oct 14, 2005 3:15 pm |
|
|
Code: |
Mark and others , I hope you get credit for this school assignment.
|
I�m totally agree with Douglas. Lately, almost 80% of the inquires in this forum
start from somebody asking how to do something..., in the second answer they
receive, we know that what really they are looking for is a teacher on-line,
somebody who will help them in his/her school assignment and due to the lack of
knowledgements the discusion becomes easily off topic, trying to explain the Ohms Law,
a Zener diode or something else.
It is good to help other people, but doing that in such way we all loose to enrich
mutually with:
C language (CCS Compiler) + PIC microcontrollers.
Just to understand what I mean, take a look at the discussion level of this forum 3 years ago, it was excelent.
Humberto |
|
|
|