Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

AD problem... update.

Status
Not open for further replies.

RobertD

New Member
Hi folks, I'm still trying to get the AD to give a linear response to input. I changed the pot to RA1 from a 10k to a 5k and got similar responses. That is the ADRESH gives a somewhat logarithmic response, that is top heavy.

0.5v=104
1.0v=189
2.5v=240
3.0v=247
4.4v=254
5.0v=255

You see that it goes from 0.5/104 to 2.5/240, which is the very top of the 255 max for 5v. I'm supposed to get 125 for 2.5v when the response is linear.

I tried with different chips, and I tried with different code, I'm thinking impedance might be a factor, I'm using Firefly/Junebug combo for the programming. I changed the pot from a 10k to a 5k, and seem to get lower values for the ADRESH. I might want to try with a 2k pot for RA3 and see if there is any improvement. But before doing that, I'd like to get some feedback. Maybe try with a different programmer perhaps.

Any suggestions?

(PS: I tried to contact Bill, but he must be on vacation...)
 
Last edited:
hi Robert,

Bring me upto speed on the PIC type.

Repost your full asm file.

Can you post the 'hex' file produced by your assembler.
You may have to change the '.hex' to '.txt' to get the forum upload to accept it.

I'll give it a try.:)
 
Maybe try with a different programmer perhaps.

The programmer can't make any difference, either it programmes correctly or it doesn't, and as you presumably verify it?, then you know it's programmed correctly.

Try posting the entire code (as Eric suggested), also post a photo of how you've built it - you're doing something wrong somewhere, the PIC A2D is simple to use and works without any problems.

If you've not checked my tutorial, you might give that a read.
 
OK Progress report. I changed the pot again, to a 2k, and I get lower results in the ADRESH still from the 5k which were lower than the original 10k pot that came with the programmer.

1.0v=112
1.5v=167
2.0v=198
2.5v=220
3.1v=233
4.0v=248

Not bad, but definitely points to a problem, maybe a load on the pin or something.
I'm using a 18F88, and I'm thinking of switching to a 18F1320. But this problem doesn't
seem to be a chip problem, I changed the 88's I have a few new ones laying around.

OK Code I'm using is Mike Webbs, original, unchanged, and it worked for him...

Code:
;###############################################################################
;	Title:			ADC, Servo Demo
;    	Author:			Mike Webb
;	Date:			21 Nov 2006
;################################################################################

		include	"p16f88.inc"

		errorlevel	-302	; stop the annoying " Register in operand not in bank 0." error.

	__config  _CONFIG1, _CP_OFF & _CCP1_RB0 & _DEBUG_ON & _WRT_PROTECT_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _MCLR_ON & _PWRTE_ON & _WDT_OFF & _INTRC_IO
	__config  _CONFIG2, _IESO_OFF & _FCMEN_OFF

; Setup Variables
		cblock	0x20
Count
OnTime
		endc

		org     0h
		nop	;		required for ICD2
;---------------------------------------------------------------------------------------------------------------------------------------		bcf	STATUS,RP1;	bank 0 or 2
		bsf	STATUS,RP0;	select bank 1
		movlw	(0<<NOT_RBPU|0<<INTEDG|0<<T0CS|0<<T0SE|0<<PSA|B'000'<<PS0)
		movwf	OPTION_REG;	setup option reg
		bcf	TRISB,3	;	make b3 output
		movlw	B'111'<<IRCF0;	=b'01110000'
		movwf	OSCCON;		select 8MHz clock
		movlw	b'00000010';	Select bit 3	
		movwf	ANSEL;		ADC on RA3
		movlw	TRISA
		bcf	STATUS,RP0;	back to bank 0
Loop		Call	ReadADC;	read A3
		movwf	OnTime;		Store it for later
		movlw	d'250';		250*8 = 2000 cycles = 1mS
		bsf	PORTB,3;	Turn output on
		call	DelayW;		delay the 1mS
		movfw	OnTime;		Get value from ADC
		btfss	STATUS,Z;	if it's zero don't do any delay
		call	DelayW;		delay W*8 = 0 to 255 = 0 to 1.03 mS  -- near enough
		bcf	PORTB,3;	Turn output off - pulse is complete
		comf	OnTime,W;	Complement ADC value
		addlw	1;		com and inc = negate.
		btfsc	STATUS,Z;	Don't do a delay of zero
		call	DelayW;		delay (256-ADC value)*8 = time required to get to 2mS 
		movlw	d'18';		We need to delay another 18mS
		movwf	Count;		so setup a counter
TimeLoop	movlw	d'250';		250*8 = 2000 clock cycles = 1mS
		call	DelayW;		do the delay
		decfsz	Count,F;	repeat it?
		goto	TimeLoop;	yes, go around again
		goto	Loop;		Go back and do it all again

DelayW
; will delay W*8 cycles including the call/return
		addlw	0xff;		add -1 to W			1
		btfsc	STATUS,Z;	=zero?				1/2
		goto	DoneDelay;	yes, better get out of here	2
		nop;			delay a bit			1
		goto	$+1;		delay a bit more		2
		goto	DelayW;		go around again			2
DoneDelay	return	;						2

ReadADC		movlw	b'01'<<ADCS0|b'001'<<CHS0|b'0'<<GO|b'1'<<ADON
		movwf	ADCON0;		select pin A1 and 16 TOSC
		bsf	STATUS,RP0;	bank 1
		movlw	b'0'<<ADFM|b'1'<<ADCS2|b'00'<<VCFG0
		movwf	ADCON1;		Left justify
		bcf	STATUS,RP0;	back to bank 0
		movlw	5;		wait 5*8 = 40 cycles
		call	DelayW;		for ADC capacitor to charge
		bsf	ADCON0,GO;	Start the conversion
WaitADC		btfsc	ADCON0,GO;	Conversion complete?
		goto	WaitADC;	No, so keep waiting
		movfw	ADRESH;		return with result in W
		return

		END
 
Last edited:
This is the hex file that was in the folder, I think it's the right one, not sure though, the pickit2 only returns 000's

:020000040000FA
:100000000000831600308100861170308F000230AE
:100010009B00853083122620A100FA3086151F2010
:100020002108031D1F2086112109013E03191F20ED
:100030001230A000FA301F20A00B1A280B28FF3E18
:1000400003192528000024281F28080049309F0094
:10005000831640309F00831205301F201F151F1983
:060060002F281E08080015
:02400E00303749
:02401000FC3F73
:00000001FF
 
Something that helped me with a/d was to put a 10k pot with 5k pots off of each leg. One from the outside leg of the 10k to the negitve rail, and one from the other outside leg of the 10k pot to the positive rail, and the center leg of the 10k pot to the pic. This allowed me to trim and shift the a/d result in some way.
 

Attachments

  • ADC.JPG
    ADC.JPG
    14.3 KB · Views: 144
If I was just building a one time thing, that would be OK, but I need this for production, so it has to run A-OK.
 
Robert,
Run the asm in Oshonsoft sim.
Results observing ADRESH, hex values
Vadc ADRESH
0.0 0
0.5 0x19
1.0 0x33
1.5 0x4c
2.0 0x66
2.5 0x7f
3.0 0x99
3.5 0xb3
4.0 0xcc
4.5 0xe6
5.0 0xff

Nothing wrong with the ADC section, adc is left justified.

Where are you measuring the output of the ADC.?

Dont wish to offend you, but the program is awful.!:)
 
Last edited:
hi,

Clip of the MPLAB hex.
 

Attachments

  • esp04 Aug. 09.gif
    esp04 Aug. 09.gif
    14.2 KB · Views: 153
Robert,
Run the asm in Oshonsoft sim.
Results observing ADRESH, hex values
Vadc ADRESH
0.0 0
0.5 0x19
1.0 0x33
1.5 0x4c
2.0 0x66
2.5 0x7f
3.0 0x99
3.5 0xb3
4.0 0xcc
4.5 0xe6
5.0 0xff

Nothing wrong with the ADC section, adc is left justified.

Where are you measuring the output of the ADC.?

Dont wish to offend you, but the program is awful.!:)

Thanks Eric, I'll mention this to Mike Webb, the designer it's not my program, but my AD does the same thing, so I use this one since it's just AD by itself.

I use a voltmeter at the pot, and at the pin, and I read the ADRESH from mplab ADRESH register.

Yes it runs OK on other people's programmers, that's why I think it's my programmer that's the problem. I'm looking to hook the chip direct to the serial port and program without the firefly. I'm looking into this right now. I think I need four wires, Vin, ground, TX, and Rx, and I plug Rx computer to Tx chip for in-circuit programming.

That's my next project, I would like to be able to program my chips without the aid of machines that can cause problems.
 
Last edited:
Not bad, but definitely points to a problem, maybe a load on the pin or something.
I'm using a 18F88, and I'm thinking of switching to a 18F1320. But this problem doesn't
seem to be a chip problem, I changed the 88's I have a few new ones laying around.

Robert,
Is this a typo 18F88 versus a 16F88.?

Whats your next step.?
 
I'm running the AD in debug mode. Maybe that's the problem. I don't know what Oshonsoft sim is or where it is, I'm not sure how to use the sim at all. I thought by staying in debug I'd get real-time values.


PS: 16F88 is correct.
PPS: I d/l Oshonsoft sim, and will install it.
 
Last edited:
I'm running the AD in debug mode. Maybe that's the problem. I don't know what Oshonsoft sim is or where it is, I'm not sure how to use the sim at all. I thought by staying in debug I'd get real-time values.

PS: 16F88 is correct.

hi,
The hex file you posted is about 50% the size of mine.! I think it must be the wrong one.?

What assembler are you using.?
 
Thaks Eric, just one thing, when I program in circuit, does MPLAB read it like it does on Junebug?

It's a nasty problem, I have to figure out why this is happening, but looks like the programmer.

Reading ADRESH in debug mode is not a problem then...?
 
Thaks Eric, just one thing, when I program in circuit, does MPLAB read it like it does on Junebug?

It's a nasty problem, I have to figure out why this is happening, but looks like the programmer.

Like I said before, it either programs or it doesn't, it can't be the programmer.

Reading ADRESH in debug mode is not a problem then...?

No idea, but why are you messing with debug mode? - have you tried actually running the program - there may be no problem all.
 
Like I said before, it either programs or it doesn't, it can't be the programmer.



No idea, but why are you messing with debug mode? - have you tried actually running the program - there may be no problem all.

When I'm in debug mode, I run the program, and that's how I get the values into ADRESH. I don't know how else to do it.
 
Last edited:
When I'm in debug mode, I run the program, and that's how I get the values into ADRESH.

Well don't - program the PIC, place it in a circuit, and run it do what you want. Don't mess about with debuggers or simulators, there's only one 100% perfect method of doing it, and that's REALITY :D
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top