PDA

View Full Version : RCTIME question



Scottie
- 22nd November 2010, 02:55
so this works in pbp
LOW portb.6
LOW portb.5
PAUSE 10
RCTIME portb.5,0,dtime

but this doesn't
LOW portb.5
LOW portb.6
PAUSE 10
RCTIME portb.5,0,dtime

any thoughts?

mackrackit
- 22nd November 2010, 05:09
What does not work about it? Wrong reading?

Scottie
- 22nd November 2010, 16:02
The cap never charges and results count of 1. With the first snippet it works and I get the count of 350 with the rc connected per the book. I can just use the first method but wondered if anyone else had the happen and what made the code do that.

When I was first saw this I was trying to see if I could use a single cap and different pins to connect multiple resistors and measure them that way. I was getting a count of 1 no matter the resistor. Then I reorder the code and it seemed to work. I got different values then a direct connection to VDD though. I am guessing the pins output must not go quite to vdd or something else in the pic does something to the rc circuit. (I was using opposite logic HIGHportb.6) not low but either way it didnt' seem to make any diffence. still got count of 1

I still want to try and do this, maybe use outputs setting reed relays to connect the resistors between the rctime pin and vdd, or just do some math to adjust the results for the offsets if they stay consistant.

Acetronics2
- 22nd November 2010, 16:53
Hi, Scootie

First thought ...

WHICH Pic are you using :confused:

Second thought ...

Your FULL program ( " copied and pasted " - not re-written - ) would be useful here ;)

Third Thought ...

a nice FULL SCHEME would be interesting to verify everything ;)

Alain

malc-c
- 22nd November 2010, 19:26
It's alright Alain, just gaze into your crystal ball and I'm sure you'll find all the answers :) :)

malc-c
- 22nd November 2010, 19:34
Hi, Scootie

First thought ...

WHICH Pic are you using :confused:

Second thought ...

Your FULL program ( " copied and pasted " - not re-written - ) would be useful here ;)

Third Thought ...

a nice FULL SCHEME would be interesting to verify everything ;)

Alain

... and what crystal you are using???

From the manual




RCTIME may be used to read a potentiometer (or some other resistive
device). Resistance can be measured by discharging and timing the
charge (or vice versa) of a capacitor through the resistor (typically 5K to
50K).

The resolution of RCTIME is dependent upon the oscillator frequency. If
a 4MHz oscillator is used, the time in state is returned in 10us
increments. If a 20MHz oscillator is used, the time in state will have a
2us resolution. Defining an OSC value has no effect on RCTIME. The
resolution always changes with the actual oscillator speed.

Scottie
- 23rd November 2010, 00:24
Hopefully these code tags show up properly and this is the place to paste the code, I am new at this


' Name : dtime.pbp
' Compiler : PICBASIC PRO Compiler 2.60
' Assembler : PM or MPASM
' Target PIC : 40-pin 16F887
' Hardware : Lab-X1
' Oscillator : 20MHz external crystal

'set device type
'fl pic16f887

' Define LCD registers and bits
DEFINE LCD_DREG PORTD
Define LCD_DBIT 4
Define LCD_RSREG PORTE
Define LCD_RSBIT 0
Define LCD_EREG PORTE
Define LCD_EBIT 1

ANSEL = %00000001 ' Set AN0-AN7 to digital with the exeption of AN0
ANSELH = %00000000 ' Set AN8 and higher channels to digital operation
'************************************************* *********

dtime VAR WORD
res1 VAR WORD
res2 VAR WORD
res3 VAR WORD

'Set up cap = 2uf pin b.5 to VDD
'nom resistance b.5-b.6 350ohm
'nom resistance b.5-b.4 5ohm

'TRISA = %11111111 ' Set PORTA to all input
Low PORTE.2 ' LCD R/W line low (W)
PAUSE 500 ' Wait .5 second

mainloop:
'measure strain gage resistance

TRISB.6 = 0
TRISB.4 = 1
HIGH portb.6
LOW portb.5
PAUSE 10
RCTIME portb.5,0,dtime
res1 = ((dtime*175)/10)

'measure wiring resistance loop
TRISB.6 = 1
TRISB.4 = 0
HIGH portb.4
LOW portb.5
PAUSE 10
RCTIME portb.5,0,dtime
res2 = ((dtime*175)/10)
res3 = res1-res2

LCDOUT $fe, 1 ' Clear LCD
LCDOUT "Raw ", DEC res1 ' Display value R1
LCDOUT $fe, $88
LCDOUT "Wirie ", DEC res2 ' Display value R2
LCDOUT $fe, $c0
LCDOUT "Gage ", DEC res3 ' Display value R3 PAUSE 1000 ' Wait 1 second

GOTO mainloop
End

Scottie
- 23rd November 2010, 15:39
I figured out that when I put in another pause my origional problem went away and it didn't matter what order the outputs were set in. Still don't know why though

Also changed the port bits because the others caused a porblem with the programmer left plugged into the x1 board

I need a larger (but stable) capacitor than the 2uf I am using now. The count is so low that I don't get the tolerance I need, each step is about 17.5 ohms and I would like to have about 1.0 ohm resolution if possible. My parts drawers don't have any good choices though.


TRISB.0 = 0
TRISB.2 = 1
HIGH portb.0
PAUSE 10
LOW portb.1
PAUSE 10
RCTIME portb.1,0,dtime