Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Nigels SIRC Coding Some Doubts

Status
Not open for further replies.

Suraj143

Active Member
Hi all I’m learning nigels IR coding. I have some small doubts regarding that.

In SIRC if there is signal (one) the duration is 1.2mS & if there is no signal (Zero) the duration is 0.6mS.

Can Nigel or anybody tell me why its detecting 60 for zero in the LoX register?
It should be 50 isnt’t it?

Calculation 12 (nop) X 50 = 600uS exactly 0.6uS.

Tell me why its detecting 112 for one in the LoX register ?
It should be 100 isnt’t it?

Calculation 12 (nop) X 100 = 1200uS exactly 1.2mS.

Help me


Code:
Next		nop
		nop
		nop
		nop
		nop				;waste time to scale pulse
		nop				;width to 8 bits
		nop
		nop
		nop
		nop
		nop
		nop
		incf	LoX,	f
        	btfss   IR_PORT, IR_In
        	goto    Next			;loop until input high again

; 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' - [COLOR="Red"]d'60'	[/COLOR]	; 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' - [COLOR="Red"]d'112[/COLOR]'		; if LoX <= 112
  		btfsc   STATUS    , C
  		goto 	TryStart
		bsf	Flags,	One		; One found, set flag
		retlw	0x00
 
You have to count all the instructions in the loop. If you do this you will see that LoX * 16 is the actual time and so Nigel is comparing with 16*60=960uS which is roughly half way between 0.6 and 1.2mS.

Mike.
 
Hi Mike thanks for your input.

I see Next routine will generate 16uS delay. So I have to multiply by Lox register value that is right.

Let say I want to detect a zero pulse (0.6mS) so it must set the Zero flag in the Flag register.

If it is zero pulse then the time will be 16*60 = 960uS.
The actual time must be 600uS but its exceeded 360.already passed to the next pulse too

This is the place I get confused.

Why I cannot multiply by 16*38 = 608uS.
 
The length of pulses varies between different remotes and with battery and light conditions and so you have to factor this in.

To read a IR signal you do the following,
Look for a pulse that is 2.4mS long, so you wait for any pulse over 2mS but less than 3mS. The pulses you receive after that must be 1 (1.2mS) or 0 (0.6mS). So, if it's greater than 0.3 and less than 0.9 it's a zero. Greater than 0.9 and less than 1.5 then it's a one. This is why Nigel compares with the values above.

Mike.
 
Pommie said:
The length of pulses varies between different remotes and with battery and light conditions and so you have to factor this in.

To read a IR signal you do the following,
Look for a pulse that is 2.4mS long, so you wait for any pulse over 2mS but less than 3mS. The pulses you receive after that must be 1 (1.2mS) or 0 (0.6mS). So, if it's greater than 0.3 and less than 0.9 it's a zero. Greater than 0.9 and less than 1.5 then it's a one. This is why Nigel compares with the values above.

Mike.

Totally understood. That’s what I needed so a range is better than a fix threshold value.

Thanks Mike

Nigel tells
"output from IR receiver is normally high, and goes low when signal received"
I understood that.

But in his Next routine he is telling “loop until input high again” does this means
Waiting for next one pulse or waiting for the next zero pulse?

Sorry for that

Code:
Next		nop
		nop
		nop
		nop
		nop				;waste time to scale pulse
		nop				;width to 8 bits
		nop
		nop
		nop
		nop
		nop
		nop
		incf	LoX,	f
        	btfss   IR_PORT, IR_In
        	goto    Next			;loop until input high again
 
Oops now I got it btfss IR_PORT, IR_In will clear when its receiving logic one & it will set when it recieving logic zero. :)
 
btfss IR_PORT, IR_In means

Bit Test F Skip if Set

So if IR_In is = 1 then skip the loop and its a 0 continue loop

So i think its waiting for a the pin to start receiving again if nothings coming in then wait until something does.. This i believe can be a 1 or 0 since both are high so to speak only difference in 1 and 0 is length. Just a guess but i assume if nothing comes in after 0.9ms then its the end of transmission right?

EDIT: Had some typos :D
 
Last edited:
Button Press & Hold Time Issue

Hi all I tested Nigels IR coding and it worked.

After detecting the correct device ID & Command code I assigned an LED to turn on or OFF. So its working.

Now I want to increment a register while the button press & hold time instead of the LED.

To do this I’m thinking to check the Flags2,New bit has been set or not,if is set the user has been released the button.& if not its still pressing.

Any idea from you all.

Code:
Read_Pulse      clrf	LoX
		btfss   IR_PORT, 	IR_In	;wait until high
            	goto    $-1
		clrf	tmp1
		movlw	0xC0			;delay to decide new keypress
		movwf	tmp2			;for keys that need to toggle

Still_High	btfss   IR_PORT, 	IR_In	;and wait until goes low
            	goto    Next
		incfsz	tmp1,f
		goto	Still_High
		incfsz	tmp2,f
		goto	Still_High
		bsf	Flags2,	New		;set New flag if no button pressed
		goto	Still_High
 
Last edited:
Hi I just wrote a code.This must call after the device & command byte recieved.This will increment the value of that Level register while the button is been held down.

I want to confirm whether its ok or not.

Code:
Wait_High	btfss   IR_PORT, IR_In	;wait until high
            	goto    $-1
		clrf	tmp1
		movlw	0xC0		;delay to decide new keypress
		movwf	tmp2		;for keys that need to toggle

Still_High	btfss   IR_PORT, IR_In	;and wait until goes low
            	goto    Increment
		incfsz	tmp1,f
		goto	Still_High
		incfsz	tmp2,f
		goto	Still_High
		bsf	Flags2,	New	;set New flag if no button pressed
		goto	Main		;goto original code to accept a new key

Increment	incf	Level,F
		movf	Level,W
		xorlw	.255
		btfss	STATUS,Z
		goto	Still_High
		movlw	.1
		movwf	Level
		goto	Still_High
 
Why not just make a variable and have that be set and cleared. and if set already skip the set part of the code. kind of like

user press ---> MyFlag = 1 ---> do code ---> check if pin signal still comming in while MyFlag = 1 ---> if so loop untill no signal comes ---> Clear MyFlag
 
Why not just do,

If code received = "1" then increment counter.
If code received = "2" then decrement counter.

The handset takes care of any repeating.

Mike.
 
Hi for both of you thanks for the info.

Nigels newflag will set when the incoming signals space detected (0.6ms gaps)

If I release the button it will set the newflag because it has plenty space time (0.6ms gaps).

When I press & hold the button, cant it be expire as soon as possible? Because in the incoming pulse stream it has plenty spaces (0.6ms gaps).
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top