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![]()
Bookmarks