BasicMicro - Forums

www.basicmicro.com
It is currently Mon May 21, 2012 12:36 am

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: RCTIME, I don't think I understand
PostPosted: Tue Oct 19, 2010 5:45 pm 
Offline
Guru

Joined: Sun Jan 03, 2010 8:01 am
Posts: 55
Location: Eau Claire, WI
Greetings All,

I am in the process of attempting to understand the RCTIME command. I have looked through the forum and looking at the syntax manual I still can't get "it to work the way I think it should". I've been working on this mini-projects for the last two nights and I am tired of "playing"; I need help!

I have connected a .1uf Capacitor in parallel with a 4.7K resistor; this should give me a time constant of:

T=RC
T=4,700ohms X .0000001f
T=4,700us

When I run my program (listed below) I get a result of 589us which is WAY OFF. I'm not sure if I am missing something of if there is some type of scaling factor that I need to do...any assistance would be great (I'm sure I'm doing something dumb or I really don't understand the RCTIME command).

Info.....

The capacitor/resistor is connected to PIN3 of my Nano-18 in this manner

P3 ------------
\ |
/ ----
\ ----
/ |
GND -----------

My code is:

dtime var word
st
high 4
pause 100 ; wait for capacitor to charge
rctime 4,0,dtime
DEBUG ["The result is",DEC dtime 13]
pause 100
goto st


Top
 Profile  
 
 Post subject: Re: RCTIME, I don't think I understand
PostPosted: Wed Oct 20, 2010 12:49 am 
Offline
Master

Joined: Sun Aug 17, 2008 5:26 pm
Posts: 798
Location: CA bay Area
Hello, Brian.
ASCII-symbol wiring diagrams don't survive the standard formatting here. Try using "QUOTE" from the formatting menu next time.
I created a PDF of the RCTIME command from an earlier manual. This covers all parts for syntax use, but the example code is only for the Pro. It does, however, end in an explanation of how to exercise the resistor/capacitor pairs to arrive at a scaling factor to use to arrive at the proper value.
Hope this helps.
Attachment:
RCTIME.pdf [117.96 KiB]
Downloaded 101 times

_________________
kenjj
http://blog.basicmicro.com/
http://kjennejohn.wordpress.com/


Top
 Profile  
 
 Post subject: Re: RCTIME, I don't think I understand
PostPosted: Wed Oct 20, 2010 5:14 am 
Offline
Guru

Joined: Sun Jan 03, 2010 8:01 am
Posts: 55
Location: Eau Claire, WI
As always Kenjj thanks for the help you always give out to people :D !

Quote:
It takes about 1.83T (where T is the time constant) for the circuit to discharge enough to trigger the
RCTime command. This means that the time constant =ResultVariable / 1.83.


After measuring the actual resistor/capacitor values with my Fluke I still had a large margin of error. I finally figured out that the results of the RCTIME command needed to be divided by the 1.83 value (which is identified in your PDF file but not so much in the original manual).

But I still have a problem....the result of RCTIME was still way off (again I measured the resistor and capacitor values) and found that in order to "make" this command work that I had to use a constant of T of 2.4 (vs. the 1.83). Is it normal for the Nano (or others processors) to have this much "play" in the "T" (Time Constant) as I need this RCTIME command to work in 6 different NANO processors (I know that I will have to calibrate the T due to capacitor/resistor tolerances but I don't want to have to change my code for each NANO).

Again thanks!


Top
 Profile  
 
 Post subject: Re: RCTIME, I don't think I understand
PostPosted: Wed Oct 20, 2010 10:21 am 
Offline
Citizen

Joined: Wed Aug 20, 2008 9:57 am
Posts: 27
Hi Brian
The problem with the RC time function is that it uses the digital threshold of the PIC pin. This threshold voltage is not guaranteed by the manufacturer since it is a digital input and nobody cares exactly where it decides between a one and a zero. Not only is the value undefined, it also varies with temperature.
If you are measuring a variable resistor, using it in a voltage divider and reading the center with an A/D is far more accurate. If you are trying to measure a variable capacitance, then, other than measuring the frequency of an oscillator (555 timer), the RC time is all you have to work with.
Keep us posted on your progress.
Wizard


Top
 Profile  
 
 Post subject: Re: RCTIME, I don't think I understand
PostPosted: Wed Oct 20, 2010 12:15 pm 
Offline
Guru

Joined: Sun Jan 03, 2010 8:01 am
Posts: 55
Location: Eau Claire, WI
Greetings Wizard,

I am laying the groundwork for including the humidity sensor that is offered at _ arralax (the HS1101) which uses capacitance to represent the humidity level. I was looking at the datasheet for the HS1101 which includes a schematic for using frequency with a 555 to represent the humidity level which I may explore. My overall goal is to develope a remote wireless thermostat for the different zones in my radiant floor heating system. I plan on using the 4D System OLED display on the thermostats and the 4D Systems 3.2 touch LCD on the base unit. I will be using Zigbee for the Wireless communication between the thermostats and the base unit which will control the zone valves.

Wizard, thanks for verifying my thoughts about the time constant concept...this thought did cross my mind about the voltage needed to represent a "1" in the digital world. But...if there is that much of a difference between processors then is the RCTIME command really that useful? I have three Nano-18 to experiment with...I'll keep this forum posted.

Again thanks for the help Kenjj and Wizard!


Top
 Profile  
 
 Post subject: Re: RCTIME, I don't think I understand
PostPosted: Wed Oct 20, 2010 5:31 pm 
Offline
Master

Joined: Sun Aug 17, 2008 5:26 pm
Posts: 798
Location: CA bay Area
RCTime is what you use if you have a PIC with no ADC pins or run out of them.
RCTime exists because BMicro produced a compiler/IDE years ago that contained all the Stamp Basic commands so as to make it instantly appealing to former Stamp users. The main selling point was the addition of commands that took advantage of the builtin hardware in the later PICs, namely ADC pins, USART, HPWM, etc.
You also have access to comparators in the new Atoms that have access to selectable voltage references in the PIC. These are VERY accurate. Get the data sheet for the PIC16F88 (used in the Nano18) and look up the specs and use guides. All the register names and their associated bits (register.0 to register.7, as well as the proper bit name in the sheet) are predefined in the Nano definitions. If the spec sheet says you turn on a comparator by setting the 4th bit of registerX, you just write
Code:
RegisterX.3 = 1

and you're done. Then you have to usually monitor a bit in a register there or elswhere to see if the comparator changed state.
Let's say the bit of interest goes to a "0" when the comparator detects the capacitor has charged past a particular voltage. Your IF looks like
Code:
IF RegisterX.7 = 0 then Set_Valve  ; Set_Valve is a routine that controls the floor heater

Fairly simple.
'Luck with your project. :D

_________________
kenjj
http://blog.basicmicro.com/
http://kjennejohn.wordpress.com/


Top
 Profile  
 
 Post subject: Re: RCTIME, I don't think I understand
PostPosted: Thu Oct 21, 2010 4:46 am 
Offline
Guru

Joined: Sun Jan 03, 2010 8:01 am
Posts: 55
Location: Eau Claire, WI
Kenjj, thanks for the syntax required to access the internal registers of the Atom product line; it may be easier than I thought (which also opens up a whole new type of programming for me, kind of like my old days back at school programming 6809/8085 in assembly/machine language and working with ADC/DAC and PIAs...cool)!

I was busy at work teaching a night class so I wasn't able to "play" but I hope to find time tonight. Accessing the registers may be a bit advanced for me right now (honestly I'm still figuring out just the basic formatting commands...I/we need MORE examples of this in the manual or a tutorial) but I'll load up the PDFs you referenced and I'll try to see what kind of trouble I can get into with my newly acquired knowledge. Thanks!


Top
 Profile  
 
 Post subject: Re: RCTIME, I don't think I understand
PostPosted: Thu Oct 21, 2010 11:49 am 
Offline
Master

Joined: Sun Aug 17, 2008 5:26 pm
Posts: 798
Location: CA bay Area
I just did a quick Google search, using
Quote:
using PIC comparator

and found this link to comparator tips and tricks at Microchip:
http://ww1.microchip.com/downloads/en/DeviceDoc/41215c.pdf

Then I did a search using
Quote:
using PIC voltage reference with comparator

and found this online PIC book that covers a lot of territory on using PIC internals, PIC type unknown, I just glossed over this one section.
This link jumps to a spot in the book that discusses using the reference module:
http://books.google.com/books?id=IXXQhoWdROAC&pg=PA445&lpg=PA445&dq=using+PIC+voltage+reference+with+comparator&source=bl&ots=jMxVN2FEnP&sig=F4iGpluyqdO2vT0PpVTS5DRuU14&hl=en&ei=c4jATI2rAoTQsAOiuo3ZCw&sa=X&oi=book_result&ct=result&resnum=4&ved=0CCIQ6AEwAw#v=onepage&q=using%20PIC%20voltage%20reference%20with%20comparator&f=false
You can find more just by using those two search terms again or try other combos.
Take care.

_________________
kenjj
http://blog.basicmicro.com/
http://kjennejohn.wordpress.com/


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

phpBB SEO