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.

Erratic output - help with A/D

Status
Not open for further replies.
bsodmike said:
Bleh, can't do any testing untill the 12F675 arrives....that teaches me to use OTP...

Don't you have any other PIC's at all?, a 16F84, 16F628, 16F877 - any of the popular EEPROM ones?. You could write yourself a delay routine which works while you are waiting for the 12F675 to arrive - if you want to use tmr0 for it, try reading my previous posts and checking MicroChip application notes.
 
Okay. I tested the basic PWM code on a 16f84A and here are the results:

Code:
Required               What I get           Voltage                Duty %
105hz                     105.17               2.638v                  50.14
141hz                     141.27               2.644v                  50.19
177hz                     176.41               2.613v                  50.24
210hz                     209.70               2.612v                  50.28 - 50.29

Why oh why is the Voltage 2.6v and not close to 5v? I set one pin to *plain* on and I get 5.255v :shock:

Help?!?

Edit: I was thinking about this. Considering this signal is doing 5v and then 0v (in 1 period) I'm wondering if my DMM is recording the AVG voltage -2.6v, which is 5.2v seems right...damn I need an osc-scope!
 
bsodmike said:
Edit: I was thinking about this. Considering this signal is doing 5v and then 0v (in 1 period) I'm wondering if my DMM is recording the AVG voltage -2.6v, which is 5.2v seems right...damn I need an osc-scope!

Exactly - the meter can only average the reading, as you say, an oscilloscope would be nice. It took me years to get one though, although I have three now :lol:
 
Well after busting moolah on this new fluke and metcal I'm pretty much not going to be buying anything more for the lab yet, since if I ever get an osc scope I want it to be a good one - digital, with a LCD display and 10-20Mhz.... (cost a bomb....heh)

Now I know my PWM code works -whoopie. however I sent an OTP version of the updated code and a buddy tried it out. Seems he's having some problems. Can't wait for the 12F675 to get me...I'm itching..to test this!! bwahahah. :lol:
 
:cry:

I am not so sure about the osc claibration on a 12f675 Nigel, the little "darlings" (Mchip!) have changed the "established" way of loading the osccal.....

You need to.....

CALL H'03FF' ;GET OSC CALLIBRATION

BSF STATUS,RP0 ;SWITCH TO BANK1

MOVWF OSCCAL ;SETUP OSC CAILIBRATION

BCF STATUS,RP0 ;SWITCH TO BANK0

It's not very clearly documented in the data sheet, is it just me or are MCHIP getting bored with making data sheets???

This new "feature" drove me mad on my 9600 serial routine, unitl I relised that the osccal is now in bank1!!! :wink:

The adc I routine for this chip is (8 bit 0-255).......


SETUP......

BSF STATUS,RP0 ;SWITCH TO BANK1

MOVLW B'00010001' ;FOSC/64, GP0 ANALOG INPUT
MOVWF ANSEL ;STORE IN ANALOG SELECT


MOVLW B'10000001' ;MOVE ADCONO MASK TO W
;RIGHT JUSTIFIED, VDD REF, CHAN 0
;ADON ON
MOVWF ADCON0 ;STORE IN ADCON 0

BCF STATUS,RP0 ;SWITCH TO BANK0



SUBROUTINE........



GET_ADC
BSF ADCON0,GO_DONE ;START ADC COVERSION

WAIT_ADC1
BTFSC ADCON0,GO_DONE ;ADC DONE?
GOTO WAIT_ADC1 ;NO, LOOP

BSF STATUS,RP0 ;SWITCH TO PAGE1
MOVF ADRESL,W ;MOVE ADC RESULT LOW TO W
BCF STATUS,RP0 ;SWITCH TO PAGE1

MOVWF RES_LOW ;STORE IN RESULT LOW

RETURN ;RETURN


Hope this helps!
 
Thanks for your input Matt. I infact have mine like that. The datasheet is very very vague but they do talk about calling that address to load info into w.

Code:
	movlw	b'01010001'	;ANS0 set as input, Fosc/16 = TAD of 4µs 
	movwf 	_ansel		;

That is how I got my Ansel setup and the readings are done this way:

Code:
measure	movlw	d'3'		; This defines the number of samples taken
	movwf	cnt		; excluding the 'first sample'

	movfw	_adresh		; read the very first sample and store it
	movwf	sum		; in the variable 'sum'

loop	movfw	_adresh		; read the second sample into accu	
	addwf	sum,f		; add both together, put answer back in sum
	btfsc	_status,0	; check carry bit for overflow
	incf 	overflow,f	; if carry bit is set, inc overflow by 1

	decfsz	cnt,f		; perform cnt - 1, skip next if result is 0
	goto	loop		; cnt != 0 so loop back for another sample

	rrf 	overflow,f	; shift the overflow
	rrf	sum,f		; rrf carry (div by 2)
	rrf 	overflow,f	; shift the overflow
	rrf 	sum,w		; rrf carry (div by 2), copy avg to accu

	return			; return without altering accu value

how it flows is simple. I call measure, then compare it to the A/D resolution and take action. for example:

Code:
	call	measure		; oversample a/d
	sublw	.26		; L - W, W altered
	btfss	_status,0	; Is W > L?	
	goto 	begin		; W is <L ; if W is > L - cont.

	movlw	.110
	call	freq

That that does it check if the A/D res is .26 if the value is not equal then increse the frequency to '255-110' tmr0 counts.

When the carry is +ve is skips the goto and increases the frequency!
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top