Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Tools
Old 29th May 2009, 07:41 PM   #1
Default Sony IR decode using hi-tech C for PIC16F877A

Dear all~~~
I have a Sony IR decode Project.
I am using Hi-tech C program language.
My hardware is PIC16F877A whit 4M crystal.
I want to use CCP module.
I have find sample code in Google.
But it can not work correctly.
The CCPR1 is always not Sony IR code.
Does anyone have Hi-tech C sample code for me???
THX
stockton is offline  
Old 29th May 2009, 07:43 PM   #2
Default

You said so yourself, you already have sample code. Figure out what's wrong with what you have.
__________________
"Because I be what I be. I would tell you what you want to know if I
could, mum, but I be a cat, and no cat anywhere ever gave anyone a
straight answer, har har."
Sceadwian is online now  
Old 29th May 2009, 08:24 PM   #3
Default

There's code in assembler in my tutorials, but perhaps more helpful for you there's a description of how SIRC's works.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Old 29th May 2009, 09:34 PM   #4
Default

Hey Nigel 1 question. When sending SIRC i know one must send out pulses to make the data aka start, one, zero but when receiving the data it comes back as solid blocks? Like i just have to read the start and see how long it is right? it doesnt receive actual pulses right like i wont have to read the PULSES right?
AtomSoft is offline  
Old 29th May 2009, 09:52 PM   #5
Default

The TSOP1138 (or equivalent) removes the carrier.
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com/
blueroomelectronics is offline  
Old 29th May 2009, 10:01 PM   #6
Default

yay! i think i finally understand it then. Thanks Bill and Nigel.
AtomSoft is offline  
Old 29th May 2009, 11:08 PM   #7
Default

Quote:
Originally Posted by stockton View Post
Dear all~~~
I have a Sony IR decode Project.
I am using Hi-tech C program language.
My hardware is PIC16F877A whit 4M crystal.
I want to use CCP module.
I have find sample code in Google.
But it can not work correctly.
The CCPR1 is always not Sony IR code.
Does anyone have Hi-tech C sample code for me???
THX
different compiler, does not use ccp module but is C

Experimenting with IR Remotes using a PIC running BoostC Project - Open Circuits
Russ Hensel is offline  
Old 29th May 2009, 11:49 PM   #8
Default

Gosh Russ, it would take me less time to research and implement my own algorithms and method from scratch rather than try to analyze the stuff you have spread out across all those files (grin)...
Mike, K8LH is offline  
Old 30th May 2009, 12:39 AM   #9
Default

OMG i did it.:
Code:
/* **************************************************************************
;																			*
;	Filename: SIRC															*
;	Date: May 29, 2009														*
;	File Version: 001														*
;																			*
;	Author:   Jason Lopez													*
;	Company:  AtomSoft														*
;																			*
;****************************************************************************
; Notes:
; I am delaying in this code a nice even number every 200uS. Mainly because if
; i count each pulse it would be accurate but too many counts for a char type
; and i dont want to use a int. So i can get a 600 count by skipping every 300uS
; and the count will be a nice low number...3
; 
; For a 1.2mS aka HIGH i should get a count of 6 and for the start 2.4mS i should
; get a count of 12. Since this isnt too accurate i range it about 1-2 numbers 
; above or below the standard.
; 
;****************************************************************************
*/
#include <p18f2525.h>
#include <delays.h>
#include <string.h>

#pragma config WDT = OFF, LVP = OFF, OSC = INTIO67, XINST = OFF

unsigned char lTime;
unsigned char ir_add;
unsigned char ir_cmd;

#define irTris TRISCbits.TRISC4
#define irPin PORTCbits.RC4

void main(void);
void GetSIRC(void);

void main(void){
	OSCCON = 0x72;      			//8MHz clock
	while(!OSCCONbits.IOFS);		//wait for osc stable

	irTris = 1;

	GetSIRC();
	while(1);
}

void GetSIRC(unsigned char *address, unsigned char *command){
	char x;
StartLook:
		ir_add = ir_cmd = 0;
		while(irPin);			//wait for it to be low
		lTime = 0;				//reset the counter
		while(irPin == 0){		//while the pin is low which is our pulse count
			lTime++;			//increment every 200uS until pin is high
			Delay100TCYx(4);	//200uS delay
		}

		if(lTime <= 10)			//Start too short
			goto StartLook;		//Restart
		if(lTime >= 14)			//Start too long
			goto StartLook;		//Restart
			
		lTime = 0;
		for(x=0;x<7;x++){			//repeat 7 times for command
			ir_cmd >>= 1;			//if it was skipped or is done ORing then shift over the 1
			while(irPin);			//wait for it to be low
			lTime = 0;				//reset the counter
			while(irPin == 0){		//while the pin is low which is our pulse count
				lTime++;			//increment every 200uS until pin is high
				Delay100TCYx(4);	//200uS delay
			}
				if(lTime >= 6)		//If its high then OR a 1 in else skip
					ir_cmd |= 0x40;	//if its less than 6 its a 0 so dont OR it		
								
		}
		for(x=0;x<5;x++){			//repeat 5 times for address/device
			ir_add >>= 1;			//if it was skipped or is done ORing then shift over the 1
			while(irPin);			//wait for it to be low
			lTime = 0;				//reset the counter
			while(irPin == 0){		//while the pin is low which is our pulse count
				lTime++;			//increment every 200uS until pin is high
				Delay100TCYx(4);	//200uS delay
			}
				if(lTime >= 6)		//If its high then OR a 1 in else skip
					ir_add |= 0x10;	//if its less than 6 its a 0 so dont OR it			
		}
}
EDIT:
I fixed it up and commented like crazy... even a top part for how it works.

Last edited by AtomSoft; 30th May 2009 at 02:45 AM.
AtomSoft is offline  
Old 30th May 2009, 01:20 AM   #10
Default

Wanna use a POINTER instead then here ya go:
Code:
/* **************************************************************************
;																			*
;	Filename: SIRC															*
;	Date: May 29, 2009														*
;	File Version: 001														*
;																			*
;	Author:   Jason Lopez													*
;	Company:  AtomSoft														*
;																			*
;****************************************************************************
; Notes:
; I am delaying in this code a nice even number every 200uS. Mainly because if
; i count each pulse it would be accurate but too many counts for a char type
; and i dont want to use a int. So i can get a 600 count by skipping every 300uS
; and the count will be a nice low number...3
; 
; For a 1.2mS aka HIGH i should get a count of 6 and for the start 2.4mS i should
; get a count of 12. Since this isnt too accurate i range it about 1-2 numbers 
; above or below the standard.
; 
;****************************************************************************
*/
#include <p18f2525.h>
#include <delays.h>
#include <string.h>

#pragma config WDT = OFF, LVP = OFF, OSC = INTIO67, XINST = OFF

unsigned char lTime;

unsigned char MyAdd;
unsigned char MyCmd;

#define irTris TRISCbits.TRISC4
#define irPin PORTCbits.RC4

void main(void);
void GetSIRC(unsigned char *address, unsigned char *command);

void main(void){
	OSCCON = 0x72;      			//8MHz clock
	while(!OSCCONbits.IOFS);		//wait for osc stable

	irTris = 1;

	GetSIRC(&MyAdd,&MyCmd);
	while(1);
}

void GetSIRC(unsigned char *address, unsigned char *command){
unsigned char ir_add;
unsigned char ir_cmd;
char x;
StartLook:

	ir_add = ir_cmd = 0;

	while(irPin);				//wait for it to be low
	lTime = 0;					//reset the counter

	while(irPin == 0){			//while the pin is low which is our pulse count
		lTime++;				//increment every 200uS until pin is high
		Delay100TCYx(4);		//200uS delay
	}

	if(lTime <= 10)				//Start too short
		goto StartLook;			//Restart
	if(lTime >= 14)				//Start too long
		goto StartLook;			//Restart
			
	lTime = 0;
	for(x=0;x<7;x++){			//repeat 7 times for command
		ir_cmd >>= 1;			//if it was skipped or is done ORing then shift over the 1

		while(irPin);			//wait for it to be low
		lTime = 0;				//reset the counter

		while(irPin == 0){		//while the pin is low which is our pulse count
			lTime++;			//increment every 200uS until pin is high
			Delay100TCYx(4);	//200uS delay
		}

		if(lTime >= 6)			//If its high then OR a 1 in else skip
			ir_cmd |= 0x40;		//if its less than 6 its a 0 so dont OR it		
								
	}
	for(x=0;x<5;x++){			//repeat 5 times for address/device
		ir_add >>= 1;			//if it was skipped or is done ORing then shift over the 1

		while(irPin);			//wait for it to be low
		lTime = 0;				//reset the counter

		while(irPin == 0){		//while the pin is low which is our pulse count
			lTime++;			//increment every 200uS until pin is high
			Delay100TCYx(4);	//200uS delay
		}

		if(lTime >= 6)			//If its high then OR a 1 in else skip
			ir_add |= 0x10;		//if its less than 6 its a 0 so dont OR it			
	}

	*address = ir_add;
	*command = ir_cmd;
}

Last edited by AtomSoft; 30th May 2009 at 02:56 AM.
AtomSoft is offline  
Old 30th May 2009, 02:01 AM   #11
Default

Very nice Jason (AtomSoft), and all in a single file too (grin)...

So it seems Sony SIRC is something like this with base timing in intervals of 550 to 600 usecs?

Attached Thumbnails
Sony IR decode using hi-tech C for PIC16F877A-sony-sirc.png  

Last edited by Mike, K8LH; 30th May 2009 at 02:04 AM.
Mike, K8LH is offline  
Old 30th May 2009, 02:46 AM   #12
Default

Yeah exactly! Thanks! I also fixed the code on both my post here. The code is at 100% (i hope)
AtomSoft is offline  
Old 30th May 2009, 12:19 PM   #13
Default

A couple more questions about SIRC, please?

(1) Is the signal from the TSOP1138 type decoders "active low" when it's receiving the IR signal (signals reversed from my drawing above)?

(2) Do those signal times vary considerably?
Mike, K8LH is offline  
Old 30th May 2009, 12:26 PM   #14
Default

Quote:
Originally Posted by Mike, K8LH View Post
A couple more questions about SIRC, please?

(1) Is the signal from the TSOP1138 type decoders "active low" when it's receiving the IR signal (signals reversed from my drawing above)?
Yes, it's active low.

Quote:

(2) Do those signal times vary considerably?
Yes they do, which is why you can't reliably just send RS232 serial data over the link.

So my tutorial doesn't check for specific pulse widths, but if it's within a certain range or not, here's the actual code, the values are simply scaled to fit within a single byte, and have no precise meaning.

Code:
; test if Zero, One, or Start (or error)
		
Chk_Pulse	clrf	Flags

TryError	movf 	LoX,	w		; check if pulse too small
  		addlw 	d'255' - d'20'		; if LoX <= 20
  		btfsc   STATUS    , C
  		goto 	TryZero
		bsf	Flags,	ErrFlag		; Error found, set flag
		retlw	0x00

TryZero		movf 	LoX,	w		; check if zero
  		addlw 	d'255' - d'60'		; if LoX <= 60
  		btfsc   STATUS    , C
  		goto 	TryOne
		bsf	Flags,	Zero		; Zero found, set flag
		retlw	0x00

TryOne 		movf 	LoX,	w		; check if one
  		addlw 	d'255' - d'112'		; if LoX <= 112
  		btfsc   STATUS    , C
  		goto 	TryStart
		bsf	Flags,	One		; One found, set flag
		retlw	0x00

TryStart 	movf 	LoX,	w		; check if start
  		addlw 	d'255' - d'180'		; if LoX <= 180
  		btfsc   STATUS    , C
  		goto 	NoMatch
		bsf	Flags,	StartFlag	; Start pulse found
		retlw	0x00
NoMatch						; pulse too long
		bsf	Flags,	ErrFlag		; Error found, set flag		
		retlw	0x00

;end of pulse measuring routines
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Old 30th May 2009, 12:26 PM   #15
Default

Im not 100% sure on my Receiver Part But I checked it with the PICKIT 2 Logic software and it seems to be active low. And inactive high. It maybe just my part now sure. I dont even have info on it. Ill try other receiver peice i have here and see if i get same results ok.

EDIT:
HEH i guess Nigel cleared that up

Last edited by AtomSoft; 30th May 2009 at 12:27 PM.
AtomSoft is offline  
Reply

Tags
decode, hitech, pica, sony

Thread Tools
Display Modes


Similar
Title Starter Forum Replies Latest
Which IR protocal is easier to decode, Sony SIRC or Philips RC5 blueroomelectronics Micro Controllers 5 14th January 2008 01:17 AM
How to decode.... arustu Electronic Projects Design/Ideas/Reviews 5 1st August 2006 10:44 AM
bs2pe read decode egg0900 Micro Controllers 3 20th June 2005 11:06 PM
IR (Encode and Decode signals) Bella Micro Controllers 0 27th October 2003 06:46 AM



All times are GMT. The time now is 05:04 AM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker