1 = Input
0 = Output
1 = Input
0 = Output
Dave
Always wear safety glasses while programming.
Hmm good catch! I forgot AN5 which was purposedly the one I'm trying to read...!
Here is ANSEL now:
'Set analog input AN0, AN1, AN2, AN3, AN4 and AN5
ANSEL = %00111111
However that hasn't changed anything, for AN5 or the other sensors (AN4 to AN0).
Going through the 16F884 datasheet again to check these registers.
I remember doing this lately on a 16F877A whithout much troubles!
Compiler version?
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
Take the advise from Bruce in post 5.
Here is an example for a different chip, but you will get the idea. Works much nicer.
http://rentron.com/PICX2.htm
And it may not be causing you trouble now but it could ...Maybe you got my hint...
1 = Input'Set entire PortB as digital input
PORTB = %00000000
TRISB = %00000000
'Set entire PortC as digital input
PORTC = %00000000
TRISC = %00000000
'Set entire PortD as digital input
PORTD = %00000000
TRISD = %00000000
0 = Output
Dave
Always wear safety glasses while programming.
I will try to read the ADC manually then,
And I missed your hint, because the code is working for those I/O's (however the comments are wrong!).
Looks better now'Set entire PortB as digital output
PORTB = %00000000
TRISB = %00000000
'Set entire PortC as digital output
PORTC = %00000000
TRISC = %00000000
'Set entire PortD as digital output
PORTD = %00000000
TRISD = %00000000![]()
Ok, I just tried to recompile my code for a 16F877A and if does work much better. Values are still fluctuating a bit so I will have to find a way to stabilize this (using software and or hardware).
here is the new init code
'************************************************* ******
'Init for PIC16F877A
'************************************************* ******
'Set ADC pins to digital operation
ADCON1 = %10001001 'AN0 to AN5 are analog input
CMCON = %00000111 'disabling the comparator module
'Define pin function
TRISA = %00101111 'Set PortA as input or output
TRISB = %00000000 'Set entire PortB as digital output
TRISC = %00000000 'Set entire PortC as digital output
TRISD = %00000000 'Set entire PortD as digital output
TRISE = %00000001 'Set PortE0 as input and rest as output
' 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
I thought I would use a 16F88x since the 877A is being phased out. Also I have a couple 884 on hand... but with all the extra trouble I think I will stick to the 877A to write the code and then transfer it to the 884 afterward.
Will update the status of the project here
PS: as far as my noise problem comming from the HV generation circuit, I now switch off the PWM module that drive the switching mosfet slightly before doing my analog readings and they are now rock solid![]()
Last edited by aberco; - 12th February 2009 at 16:11.
Bookmarks