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.

picbasic pro rctime instruction

Status
Not open for further replies.

abofar

New Member
Hello.All

I have a question please excuse me if it is silly. In picbasic pro RCTIME is somehow ambiguous. Look at this code :
Main:
HIGH RA.0 ' charge the capacitor
PAUSEUS 250 ' for 250 us
RCTIME RA.0, 1,Result ' measure discharge time
PAUSE 100
GOTO Main
1. RCTIME suppose to return the discharge time of the capacitor . High RA.0 set pin RA.0 to +5v. 250uS delay inserted to give time for C to charge. RCTIME starts timing the discharge . When 1.4v reached the timer stops and discharge time is stored in Result. I cannot see the start time here , if it is stars at RCTIME instruction, there is 250uS has not been taken into account and therefor the timing is not accurate. Am I correct here?.

2. Is the voltage level to switch from high to low 1.4v or 1.3v as some say ?.

3. Is the time returned by RCTIME instruction actually RC time ( T=RC where the voltage suppose to be at 36.2% of the supply voltage, for this formula to be true)? . Is the voltage 1.4v correspond to 36.2% of 5v so we can take it as RC time?. Actually 36.2% of 5 is 1.81 not 1.4 or 1.3.

I roved the internet but could not find an answer.
Please any help.

Obaid
 
Last edited:
The way I read it is... Set the port high... wait 250us to make sure the cap is fully charged... When you execute RCTIME.. this is a function. the "result" is worked out within that function from the time RCTIME is executed untill the cap reaches the discharges state. This simple A to D is not hard to understand... If you can read assembler, take a look at Nigel's tutorials... Joystick input... This is explained in the theory.
 
Thank you Ian for your quick response. I understand the function of pic adc. My problem is that I cannot see where RCTIME start timing . As I understand from pibasic pro manual it starts at the time the instruction executed. Discharging could start before that may be 100uS before or any time before the instruction is executed. How can this time measured by RCTIME can be taken as RC time ,it is just time represent part of the discharge time, isn't it?

Obaid
 
OK let us assume it is accurate. What time does it measure in relation to RC=T. 1.4v is not 36.2% of 5v. we know that it changes state at 1.4v. An by the way is it 1.4v or 1.3v?

Obaid
 
Here Ian is what RCtime looks like in asm I'll post both asm and the basic
ASM
Code:
	GOTO L1
L12:	MOVWF 0x34
	BSF FSR,7
	IORWF INDF,F
	BCF FSR,7
	CLRF 0x22
	BTFSS 0x20,0
	MOVWF 0x22
	CALL L2
	GOTO L3
L2:	MOVF 0x34,W
	XORWF 0x22,F
	MOVLW 0x01
	MOVWF 0x20
	CLRF 0x21
L4:	MOVF INDF,W
	ANDWF 0x34,W
	XORWF 0x22,W
	BTFSS STATUS,Z
	RETURN
	INCF 0x20,F
	BTFSC STATUS,Z
	INCFSZ 0x21,F
	GOTO L4
	RETURN
L11:	CLRF 0x23
	MOVWF 0x22
L6:	MOVLW 0xFF
	ADDWF 0x22,F
	BTFSS STATUS,C
	ADDWF 0x23,F
	BTFSS STATUS,C
	GOTO L3
	MOVLW 0x03
	MOVWF 0x21
	MOVLW 0xDF
	CALL L5
	GOTO L6
	CLRF 0x21
L5:	ADDLW 0xE8
	MOVWF 0x20
	COMF 0x21,F
	MOVLW 0xFC
	BTFSS STATUS,C
	GOTO L7
L8:	ADDWF 0x20,F
	BTFSC STATUS,C
	GOTO L8
L7:	ADDWF 0x20,F
	CLRWDT
	INCFSZ 0x21,F
	GOTO L8
	BTFSC 0x20,0
	GOTO L9
L9:	BTFSS 0x20,1
	GOTO L10
	NOP
	GOTO L10
L10:	RETURN
L3:	BCF STATUS,IRP
	BCF STATUS,RP1
	BCF STATUS,RP0
	CLRWDT
	RETURN
L1:	BCF 0x06,3
	BSF STATUS,RP0
	BCF 0x06,3
	MOVLW 0x0A
	BCF STATUS,RP0
	CALL L11
	CLRF 0x20
	MOVLW 0x06
	MOVWF FSR
	MOVLW 0x08
	CALL L12
	MOVF 0x20,W
	MOVWF 0x38
	MOVF 0x21,W
	MOVWF 0x39

And the basic
Code:
w0 VAR word
LOW PORTB.3 ' Discharge cap to start
PAUSE 10 ' Discharge for 10ms
RCTIME PORTB.3,0,W0 ' Read potentiometer on Pin3
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top