using part of the dc PORT

Status
Not open for further replies.

MrDEB

Well-Known Member
I want to add a battery monitor to the bike project but how to configure only one ADC pin instead of all the ADC pins?
using a 18F25K20 in final project but using a 18f2420 for testing
For the battery monitor just two 50k resistors in series then connect the porta.0 to the resistor junction w/ ground and battery connections as requited.
Am using portA.1 and PortA.2 as digital inputs.
Code:
// start of main
SetAllDigital
 
Shift.SetOutput(DataPin)
Shift.SetClock(ClockPin)
 
High(ResetPin_R)        // make output and set high
High(ResetPin_G)        // make output and set high
Low(LE)                 // make output and set low
High(D_code)            // reset the Decoder to enable   
 
PORTB = 0
TRISB = %00000000       // make PORTB outputs
 
// make S1 and S2 switch inputs (assumes there are external pullups on the pins)
Input(s1)
Input(s2)
     
 
While true                   // durring RIDE the code jumps to here if switch = 1
Reading the data sheet I assume all I need to do is set TRISA=%00000001
but the data sheet mentions a ANSX bit?
am assuming I leave the setalldigital as is?
 
You set the ADC as shown


Code:
TRISA = %00000001  // sets AN0 as input 
ADCON1 =$E  //sets only AN0 as analog 
CMCON = $7 // lets you use all  the rest of the pins AS I/O
 
Last edited:
if I want to use a different port pin, all I do is change the TRISA value and the HEX value? $E for RA0 I need to locate a hex decimal chart for RA2
Perhaps going over with this simple project.
The transmitter circuit draws less than 10ma (estimated) and powered by two coin cell batteries (transmitter needs 2.4v to operate but one battery is only 3v(not much head room.
Perhaps I should post a schematic. Was going with just a diode.
 
Overkill?

using the P mosfet to prevent reverse polarity and two coin cell batteries as the transmitter operates on 2.4v min.
Schematic shows a battery monitor which I might not include.
can't upload schematic why??
Keep getting file error on server.
 
MrDeb if you make AN2 analog that means AN0 to AN2 will also be Analog too you'll end up with 3 pins as analog AN0
AN1 AN3

The chip your using has what I call dependent ADC means you set them in order.

Now some chips can set them in any order Like this one 18F25K20 but the 18F2420 has to be in order if you want one you start with AN0 two you get AN0 and AN1

Can't have AN2 without AN0 and AN1 LOL
 
Last edited:
I am using two different chips, a 18F25K20 for the receiver end but the transmitter I am wanting to use an 18F13K22 which has the ICSP connected to RA0 & RA1.
I could go with two of the 18F25K20's to make life easier but am looking at moving thins around and use RB4 or RB5 (there is no RB0, RB1 or RB3?).
Going to rethink this.
THANKS Again
Call me with your new PH#
 
schematic upload error

here is what the error says
"Fatal error:

File system directory "[path]/customfiles/6/3/0/6/2" is not writable or cannot be found. Please create this directory; ensure the directory is writable or change the directory setting.

Unable to proceed with save while $errors array is not empty in class vB_DataManager_AttachmentFiledata in [path]/includes/class_dm.php on line 849"
I tried using the quote but it says message is to short.

 
I like to stay away from the ICSP pins if at all possible. When I first got started with micro controllers it was suggested not to use as it COULD cause issues.
Anyway I got to thinking that if I use the same chip in both the Transmitter and receiver I would offset the cost by buying in larger quantities than buying two different chips.
Now I need to decide if I need to go to the trouble of using two coin cell batteries = 6v or one = 3v. Using the one cell I eliminate having to use a voltage regulator. BUT the transmitter operates from 2.4 to 12v. At present the transmitter circuit draws 15ma at 3v upon transmission BUT I have two LEDs for testing so in actuality it probably draws less than 10ma at transmission. So a 2032 coin cell has 225mah. Wonder if there is a way to compute how long the battery will stay above 2.4v.
Doing research at present.
 
I have the minimum components as per data sheets etc.
I inserted the P mosfet just so a reverse polarity won't occur in the event the battery is inserted backwards. I feel I probally should go with two batteries but really don't want to. The transmitter circuit, in standby mode draws 6ma.

The encoder chip data sheet recommends the diodes (I only have two instead of 4)
The tilt switches are needed. I could go a higher pullup resistor for less current draw.
Can't see anything I can delete but open for suggestions.
 
Well that battery has a 240mAH rating that means you could draw 240mA for one hour if your transmitter used 10mA
240 / 10 means 24 hours till the battery is dead.
 
DUH your correct. Will remove the temp LED. The 10ma is transmitting which is two seconds at most but need to measure standby without the LED.
 
STOP the presses!!
that's if it draws 10ma continuously.
I clipped the leds and standby = 4.8ma
transmitting with a delayms of 2000(need to change, used for indication) = 14.9ma
BUT how long will the battery stay above 2.5 for transmitter enable voltage?
Has anyone seen such a calculator for battery degrade life?
still would like more life but then I would have to add a voltage reg unless I can find a battery holder that puts two coin cells in parallel. YEA good luck with that.
 
The battery is dead at 80% your going to 70% The only way to get this to last is

One put the pic to sleep if a button pressed wake it up and take action you could even let the led come on when you press the button.

Two put a slow crystal on it .

And put it back to sleep LOL

Those remotes that use small battery's don't use any power till you press a button.
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…