by any chance is there a multiplexed comparator on this pin?!?
Are you sure the Vref is set to internal?
by any chance is there a multiplexed comparator on this pin?!?
Are you sure the Vref is set to internal?
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
There is (PIN 6 12LF1822) , but I've turned the compartators off...
ADC +Vref is set to be VCC.Code:@ __CONFIG _CONFIG1, _FCMEN_OFF & _FOSC_INTOSC & _WDTE_OFF & _MCLRE_OFF & _CP_ON & _IESO_OFF & _BOREN_OFF & _PWRTE_OFF @ __CONFIG _CONFIG2, _LVP_OFF DEFINE OSC 8 ' INCLUDE "DT_INTS-14.bas" ' INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1 DEFINE HSER_CLROERR 1 ' Clear overflow automatically DEFINE HSER_SPBRG 16 ' 115200 Baud @ 8MHz, 2.12% SPBRGH = 0 BAUDCON.3 = 1 ' Enable 16 bit baudrate generator APFCON.2 = 1 ' PUT HSEROUT ON PIN 3 (ra4) APFCON.0 = 0 ' PUT CCP1 onto RA2 Pin5 Osccon = %01110010 'sets the internal oscillator to 8Mhz DEFINE ADC_BITS 8 ' ADCIN resolution (Bits) DEFINE ADC_CLOCK 1 ' ADC clock source (Fosc/8) DEFINE ADC_SAMPLEUS 50 ' Set sampling time in microseconds CM1CON0 = 0 ' COMPARATORS OFF CM1CON1 = 0 ' COMPARATORS OFF ADCON0 = %00000010 'AN0 Enabled (Pin 5) + ADC On ADCON1 = %00000000 'set ADC +ve ref to internal VREF (00 is VCC) 'FVRCON = %11000001 ' turn fixed internal voltage reference on & set it to 4.096V (last two bits set the voltage ...01 =1.024V,10=2.048 OPTION_REG = 0 'WEAK PULLUPS ENABLED WPUA.3 = 1 ' RA3 pin 4 enabled (SW1) IOCAN.3 = 1 'interrupt on -ve going edge (SW1 cpscon0 = 0 'turn off capacititve touch 'HPWM SETTINGS (MANUAL SETTING OF THE REGISTERS VS THE PICBASIC HPWM COMMAND) CCP1CON = %00001100 ' Turn HPWM on on CCP1 TRISA.2 =1 ' Disable the CCP2 pin output driver by setting the bit CCPR1L.6 = 0 'I'm only using 8 bit PWM so clear the top two bits CCPR1L.7 = 0 'I'm only using 8 bit PWM so clear the top two bits PR2= 63 'THIS SETS THE PWM PERIOD (FREQUENCY) to 15.625KHZ @4MHZ (I hope - not scoped it!) T2CON = %00000100 'TIMER2 ON 1:1 PRESCALER 1:1 POSTSCALER TRISA.2 = 0 'Enable the CCP2 pin output driver by setting the bit OPAMP VAR PortA.5 SW1 VAR PortA.3 latest_sample var byte TEST1: adcin 1, latest_sample hserout [dec latest_sample,13,10] PAUSE 200 GOTO TEST1
(Not sure what's going with the formatting - when I copied/pasted there were heaps of line breaks in my code - to make it easier on the eye!)
Last edited by HankMcSpank; - 19th May 2011 at 17:40.
Weird, I would try something
ANSEL is not set, set it so the unused Analog pin will be digital
Increase your ADC Sampling Time, set Fosc to Frc.
This should do the trick.
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
My apologies, I stripped out some linesfrom my program (ie a list of what I have attached to all the pins), to condense the code & make it eaasier to read , it seems I got carried away with the delete key when posting
....that above bit missing from my original code.Code:TRISA = %11001010 'RA2 hpwm out therefore output needed ANSELA =%00000010 'SIG in (RA1) NEED TO BE ANALOGUE.
I'll try increasing the sampling time (but not sure why it would be 'signal level' sensitive....ie above a few millivolts right up to VCC, the ADC reads fine)
Walter....oh dear, not what I wanted to hear (re your problems). I did read the errata sheet, but that seems to relate more to ADC not completing (hanging?) under certain circumstances.... whereas this appears to be working as it should my readings are totally fine above 008 upto 255 ....just can't get under 008...even short to the PIC's ground pin.
I've only recently progressed from using ADCIN ...I'm just using it here cos it's quick!
Edit: just tried setting the Fosc to Frc ....hmmm, I won one bit back ...my ADC now reads between 007 & 255!
Last edited by HankMcSpank; - 19th May 2011 at 18:20.
well, I got to the bottom of it...something whacky going on here!
It's something to do with the way I'm setting the weak pullup register....
Firstly, I noticed that when I disabled weak pullups (I just took a flier!)
My ADC started reading down to zero as it should!Code:OPTION_REG.7 = 1 ' disable weak pullups
Sure enough when I enabled weak pullups again, the problem returned.
But this is where I’m obviously doing something wrong, this way actually works…
(I want weak pullups of RA3)
…ie even with weak pullups enabled my ADC reads down to zero.Code:WPUA = %00001000 IOCAN = %00001000
But if I do this….
My ADC won’t read down below 008 again!Code:WPUA.3 = 1 IOCAN.3 = 1
So to get ADC reading down to zero *with* weak pullups enabled on a 12LF1822, it must be set like this....
Not sure if it makes any difference but my weak pullup is on the MCLR pin.Code:OPTION_REG.7 = 0 WPUA = %00001000 IOCAN = %00001000
Anyway, I'm happy - it's sorted!
Last edited by HankMcSpank; - 19th May 2011 at 20:00.
That's interesting. I also thought the WeakPullups could do something but never had this problem before. Nice finding.
So I guess doing the ADC while sleeping would also have do the trick.
Since it's working... don't fix it![]()
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
Nothing whacky there.
The WPUA register defaults to %00111111 on power-up.
If you do WPUA.3 = 1
nothing changes, because that bit is already a 1.
You have to disable pull-ups on the pins you don't want pulled-up.
The numbers over each bit show the POR/BOR defaults.
![]()
DT
Bookmarks