HI I did the test , as I suspected, I get 0.7v all the time. So I caould put a few in a row to get a higher voltage difference and use that as a reference voltage.
Printable View
HI I did the test , as I suspected, I get 0.7v all the time. So I caould put a few in a row to get a higher voltage difference and use that as a reference voltage.
You could, but those diodes will vary in voltage with time, temperature, current flow, moon phases, etc, not by much, but they will change over time and temperature at least, and in series, they'd do nothing but get worse. Therefore, you're battery voltage reading will change accordingly, and probably screw you up in the long run. And you have to have X amount of current to even get the diodes to conduct. You might end up using more power than you would really want to just to get a reading.
Have you been able to get the A/D working yet?
Like I said, spare pin to a resistor (probably 1K or so), other side of resistor to non-banded side of diode, banded side of diode to ground. Tap the non-banded side to your A/D port and take some readings with the battery hooked up as normal and A/D converter set up with Vref+ at Vdd and Vref- at Vss. If you're using the 10bit A/D, you should get a reading arorund 150-ish. Then as the battery wears down, the reading will go up. A reading of roughly 200 will mean a dead battery.
And, you can save the power to read the battery by change that 'spare pin' mentioned above to an input and shutting off the A/D module.
ok , I have a problem now:
i wrote this program below, I configured so it read porta.0, but I get 0 output when I ground it and oscillation between 890 and to 900 when i put it to Vdd.
if I leave the program as is, and just put the input wire to portA.1 theni get 0 output when i groud the wire, and 1023 when I put it to Vdd.
Why am I getting a better result to a non configured port 6, at least i am ot calling this pin ??
my ADCON0 = %10000001 i believe this is for An0 to input
I am also trying to get two input for A/d , is that possible ?
'RECEIVE PIC
INCLUDE "modedefs.bas"
DEFINE OSC 20 'use external 20mhz crystal
DEFINE LCD_DREG PORTB ' Set LCD Data port
DEFINE LCD_DBIT 4 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 0 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD
DEFINE LCD_COMMANDUS 2500
'DEFINE LCD_DATAUS 250
'DEFINE CHAR_PACING 2000
pause 1000
' Define ADCIN parameters
Define ADC_BITS 10 ' Set number of bits in result
Define ADC_CLOCK 3 ' Set clock source (3=rc)
Define ADC_SAMPLEUS 50 ' Set sampling time in uS
input1 var word : input2 var word
TRISA = %11111111 ' Set PORTA to all input
CMCON = 7
ANSEL = %00001100
ADCON1 = %10000010
ADCON0 = %10000001
Pause 500
loop: ADCIN porta.0, input1
Lcdout $fe, 1 ' Clear LCD
Lcdout "Value1: ", DEC input1 ' Display the decimal value
lcdout $FE,$C0, "Value2: ", dec input2
Pause 200
Goto loop
End
Also, what do you mean by : Spare pin to resistor ?
trying to get multiple input,but getting wrong values
loop:
ADCON0 = %10000001 ' Configure and turn on A/D Module
ADCIN porta.0, input1
pause 50
ADCON0 = %10001001 ' Configure and turn on A/D Module
ADCIN porta.1, input2
pause 50
Lcdout $fe, 1 ' Clear LCD
Lcdout "Value1: ", DEC input1 ' Display the decimal value
lcdout $FE,$C0, "Value2: ", dec input2
Pause 400
Goto loop
Oscillation - I get that too on most everything I do on the A/D inputs (I don't know if it's a function of crappy circuit boards or bad design, doesn't matter to me anyways). You're probably going to want to do some sort of software averaging and/or put a capacitor across the input line to smooth it out a bit.
Spare pin on resistor - instead of putting the diode direct to battery power, thru a resistor to ground, you can intermittently power that diode thru a spare PIC output pin and save that power. Every little bit helps ya know.
ok, but what about this loop here, can i do that, having multiple a/d conversion on one chip ?
loop:
ADCON0 = %10000001 ' Configure and turn on A/D Module
ADCIN porta.0, input1
pause 50
ADCON0 = %10001001 ' Configure and turn on A/D Module
ADCIN porta.1, input2
pause 50
From the definition of ADCON0, I can only choose one pin for A/D conversion. Maybe thats why it get mixed up .
You can do A/D on more than one pin, just not at the same time. I'm not sure why it didn't work for you in the one post. Maybe not waiting long enough between conversions and/or long enough between switching A/D channel assignment. I think you have to wait awhile, not only after the last conversion, but after you switch the channel, which ADCIN does for you. So, again, not sure. I'll think on it. Until then, double check your configuration, TRIS assignments, ADCON setup, etc.etc.
And you shouldn't have to use more than one channel for your project, unless I missed something there too...
HI,
I dont have to use more then one for this project, But I had this problem before and did not persue into it, so I asked the question just on the way. I read on a site, just like you said, adding a capacitor to the output of the sensor or battery will help. The thing I dont know why it works, I tried these two program they both works, just dont know why the program with just one ADCON0 works
Two Adcon
ADCON0 = %10000001 ' Configure and turn on A/D Module
ADCIN porta.0, input1
pause 50
ADCON0 = %10001001 ' Configure and turn on A/D Module
ADCIN porta.1, input2
pause 50
One ADCON0
ADCON0 = %10000001 ' Configure and turn on A/D Module
ADCIN porta.0, input1
ADCIN porta.1, input2
pause 50
See they both work, but I did not configure port A.1.. why ?
You're using the ADCIN command. Ya think maybe PBP sets it up for ya?
I know the PBP manual doesn't explicitly say it that it sets it up for you, but it does say that ADCIN reads the 'channel' and also says all you have to do is set the required pins to inputs, it doesn't really say to select the channel you want to sample... I suppose the manual could be a little more informative in this respect.
I just looked at the ADC section of the 'F88. It's a bit different than some of the other PICs. Not only do you have to TRIS the pins you want to inputs, but you also have to enable the A/D in the ANSEL register. I don't know if PBP does this for you or not.
You can easily check for that in your .lst file after compiling the program. Just put a comment around the line you're wanting to check and search for that comment in the .lst file. Should make it a bit easier for ya...
hi,
Ok I got the A/D working now.
I bought another RF module kit from this web site:
http://www.robotshop.ca/home/product...ity-tx-rx.html
( actuallyI just had to drive there).
I use the exact program and configuraiton and I am getting contact output on the lcd :
TempC : 0
TempF: 32
here is what I see on the scope:
http://www3.sympatico.ca/lerameur/
I bought three pair of them , They all act the same...
it looks ok from the scope doesn't it ??
A/D is working as expected? Values are what you need and all that?
Yes :)
I did that they are almost the same on the scope.
Almost apparently isn't close enough.
Fatten up the traces a bit if you can and repost the pics including the original RF module sets.
Also, you might want to try speeding up the TX rate, maybe a couple more sync bytes ($55), maybe less, who knows.
That's the problem with getting something to work with one thing, and then using another, you gotta redo practically everything.
Ok I posted a picture of the working module, I bit different.
same link
2nd picture, bottom trace is old 'working' receiver output?
If so, do you see that big gap after every transmission? That's the data slicer slowly losing it's mind. After a couple of ms, it starts going nuts, which is why you have to train the rx.
If I had to guess, I would say try using n2400 (or t2400, I don't remember which) instead of what you're using now, on both TX and RX. Then try t2400 on the TX and n2400 on the RX. It (the new TX/RX pair) looks like it's inverted or something.
And again, try bumping up the speed. On the new RX 'scope picture, see how that gap isn't there? That thing loses it's mind fast.
Ok i tried faster speed, and same thing, I changed to t2400 here si the result, it looks good, but the output gives me
tempc: -6396C
tempf: -60 F
3rd pic:
http://www3.sympatico.ca/lerameur/
It also take like 15 seconds before anything appears on the lcd.
whereas before a few seconds
Then try t2400 on the TX and n2400 on the RX.
output is now:
tempc: +148C
tempf: +99.75 F
and it does not seem to be moving from that
i did all the test with all three set of TX and RX modules, same results with each
these modules has to be working, the only difference is the white space is a bit smaller.. unless it means the chip is useless. Should i order other fron Rentron ?
SLAP me with a dead fish in the face....
I have crystals in drawers, Ithoight they where 20Mhz, they where 2.0 Mhz...
it works now...
I am attempting to use the encoder I received a while ago to compare with my software encoding technique. see new thread
k
I am going to start my other project which needs two HPWM port, so I choose the pic16F876 for now, I cannot make it oscillate, you have idea, is there a software (programming thing ) that is needed ? I read the spec sheet i didnot see anything about it
I saw that. Some (most?) of them won't do data. They'll do a single switch position on the TX end, to a single relay/light/whatever on the RX end.
That's why I pushed the manchester encoding so hard a couple of weeks ago. You know what you're doing now (I think anyways, you got the temperature to transmit without it didn't you?) and don't need those encoders.
hehehe, yes well that 2.0 Mhz crystals cost some hours too Grrrrr
Manchester encoding is working good. I also saw on previous post that other where trying to remove errors in the transmition so the wireless could be almost full proof. I saw the shiftin function was used in one case.
When I ordered these encoders, , I did not know there was different types of encoding (serial , parallel). Maybe one day I will find use for them.
k
xtal config bits ?
isn't it this line I had in my code:
DEFINE OSC 20 'use external 20mhz crystal
Do I need to add this line too ?
@ DEVICE PIC16F877,HS_OSC ' Use PIC16F877 and HS Oscilator
Why didn,t i need to add this when using the pic16F88??
Nope, that DEFINE just tells PBP what sort of timing to use when it compiles. For example, if you defined 4mhz, a pause 1000 would have x number of delay statements (or loops or whatever). If you define 20mhz, PBP will automatically change that X number to 5 times the number of delay statements (or loops or whatever). The real explanation is towards the end of the PBP manual.
For checking your xtal config bits, you'll either want to check you programmer's config bit settings (which you'd probably do right before you hit the program button), or start adding config lines in your code.
For example, here's a bit (ok, actually it's all of them plus explanations below it of what each register does and how to use it) of config's for one of my projects using a PIC18F4620:
@ __CONFIG _CONFIG1H, _OSC_HSPLL_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
@ __CONFIG _CONFIG2L, _BOREN_OFF_2L & _PWRT_ON_2L
@ __CONFIG _CONFIG2H, _WDT_OFF_2H & _WDTPS_32768_2H
@ __CONFIG _CONFIG3H, _LPT1OSC_OFF_3H & _MCLRE_ON_3H & _PBADEN_OFF_3H & _CCP2MX_PORTC_3H
@ __CONFIG _CONFIG4L, _XINST_OFF_4L & _STVREN_OFF_4L & _LVP_OFF_4L & _DEBUG_OFF_4L
@ __CONFIG _CONFIG5L, _CP0_OFF_5L & _CP1_OFF_5L & _CP2_OFF_5L & _CP3_OFF_5L
@ __CONFIG _CONFIG5H, _CPB_OFF_5H & _CPD_OFF_5H
@ __CONFIG _CONFIG6L, _WRT0_OFF_6L & _WRT1_OFF_6L & _WRT2_OFF_6L & _WRT3_OFF_6L
@ __CONFIG _CONFIG6H, _WRTC_OFF_6H & _WRTB_OFF_6H & _WRTD_OFF_6H
@ __CONFIG _CONFIG7L, _EBTR0_OFF_7L & _EBTR1_OFF_7L & _EBTR2_OFF_7L & _EBTR3_OFF_7L
@ __CONFIG _CONFIG7H, _EBTRB_OFF_7H
;----- CONFIG1H Options --------------------------------------------------
;_OSC_LP_1H,_OSC_XT_1H,_OSC_HS_1H,_OSC_RC_1H,_OSC_ EC_1H,_OSC_ECIO6_1H,_OSC_HSPLL_1H,_OSC_RCIO6_1H,_O SC_INTIO67_1H,_OSC_INTIO7_1H,_FCMEN_OFF_1H,_FCMEN_ ON_1H,_IESO_OFF_1H,_IESO_ON_1H
;----- CONFIG2L Options --------------------------------------------------
;_PWRT_ON_2L, _PWRT_OFF_2L, _BOREN_OFF_2L, _BOREN_ON_2L, _BOREN_NOSLP_2L, _BOREN_SBORDIS_2L, _BORV_0_2L, _BORV_1_2L, _BORV_2_2L, _BORV_3_2L
;----- CONFIG2H Options --------------------------------------------------
;_WDT_OFF_2H, _WDT_ON_2H, _WDTPS_ 1 / 2 / 4 / 8 / 16 / 32 / 64 / 128 / 256 / 512 / 1024 / 2048 / 4096 / 8192 / 16384 / 32768 _2H
;----- CONFIG3H Options --------------------------------------------------
;_MCLRE_OFF_3H, _MCLRE_ON_3H, _LPT1OSC_OFF_3H, _LPT1OSC_ON_3H, _PBADEN_OFF_3H, _PBADEN_ON_3H, _CCP2MX_PORTBE_3H, _CCP2MX_PORTC_3H
;----- CONFIG4L Options --------------------------------------------------
;_STVREN_OFF_4L, _STVREN_ON_4L, _LVP_OFF_4L, _LVP_ON_4L, _XINST_OFF_4L, _XINST_ON_4L, _DEBUG_ON_4L, _DEBUG_OFF_4L
;------CONFIG5/6/7 Options not used for code/eeprom protection
where can I get a tutorial on this,
I checked PBP manual the datasheet of my PIC and I have not seen that. I just want to be able to read what you posted,
1H, 2L 2H etc.. no idea, (and the rest too)
hennnn I feel pretty stupid now
I saw that this is in the file included in the PBP compiler, like INCLUDE "P16F877A.INC"
Here is a good starting place: Presetting Configuration Fuses (PIC Defines) into your Program
Ok thanks for the link
to go back to the A/D conversion.
I read another way to use analog to digital with direct ADC control, and not with adcin , What does that mean ?
Accessing the registers directly, select channel, set pin assignments, set acquisition time, set sampling time, turn module on, start a/d conversion, wait for completion and read the registers.
Again, if ADCIN is working, stay with it. You won't do a lot better with direct access.
Yup it's just another way to do the same thing... it's just a little less code hungry
Ok still working on the same pic.
I finally got the oscillation going.
I wrote this program: (I have two questions)
1) why does the DEFINE OSC 20 not work in this case
2) In the program i wrote, NOTHING appears on the LCD
Can I put all the ldout pin on the B port ?
Pin 11 LCD on to PIN 25
Pin 12 --> Pin 26
Pin 13 --> Pin 27
Pin 14 --> Pin 28
anything software for the lcd that i dont have to do with the Pic 16f88 ?
@ DEVICE PIC16F876A , HS_OSC , WDT_OFF , PWRT_ON , BOD_ON , LVP_OFF , PROTECT_OFF
'HS 20mhz, watchdog off, powerup timer on, mclr external, brown out detect on, low volt program off , code protect off
DEFINE LCD_DREG PORTB ' Set LCD Data port
DEFINE LCD_DBIT 4 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 0 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD
DEFINE LCD_COMMANDUS 2500
DEFINE LCD_DATAUS 250
DEFINE CHAR_PACING 2000
Pause 1000 ' Wait 1 second
loop:
lcdout $FE,1, "Number: ", dec 55
pause 100
goto loop
end
Have you got PGM (RB4? RB5?) pulled up or down, whichever it is?
I use them for my LCDout....
1) What do you mean by OSC 20 doesn't work? Compile error? Timing wrong?
2) yes, you can put the LCD data lines anywhere you CAN define them.
Did you try an led blink yet?
PIC16F876A and 16F88 should operate the same as far as PBP is concerned.
Why not use port D like usual?
What do you mean by OSC 20 doesn't work? Compile error? Timing wrong?
No oscillation on the scope... thast why
2) yes, you can put the LCD data lines anywhere you CAN define them.
Did you try an led blink yet?
I will try it
PIC16F876A and 16F88 should operate the same as far as PBP is concerned.
Why not use port D like usual?
NO port D on that chip, I tried portC 4 to 7 , no difference
yes it does oscillate
when I put thisline:
@ DEVICE PIC16F876A , HS_OSC , WDT_OFF , PWRT_ON , BOD_ON , LVP_OFF , PROTECT_OFF
and not:
DEFINE OSC 20