Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Project understanding

Status
Not open for further replies.

amitaiwe

Member level 3
Joined
Feb 19, 2014
Messages
57
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
547
HI all,

I'm trying to understand (and remember) whats going on in this project
which I intend using:

http://www.micro-examples.com/articles/index.php/PicoDetector#comment=1:99

I will be grateful to anybody how can help me with a few issues:

1. In the explanation appears:
"Coil L1 replaces crystal in PIC oscillator circuit"
what exactly does that mean?
As far as I understand the method for detecting a metal is by a AC current passing
through a inductor and/or capacitor. What oscillates the current in this circuit? an
initial oscillator of the pic? if yes so isn't it supposed to be a square
signal? if the answer is again yes - does the circuit work, does the
inductor respond to a square wave?


2. I don't manage to understand which type of inductor to use
for this type of project. I sow a few different types which made
me confused:
- **broken link removed**
- surface Inductor ?

3. About the code:
Recently I did a project which contains a pic16f877 and
for that purpose I wrote in assembly language and used Mplab environment and ICD2
For burning the code to the pic.
can I use the same method here by copying the text of the code and use in the same
method? (by changing the configuration of Mplab to C code)

Thanks, Amitai
 

Hi amitaiwe,
3. About the code:
Recently I did a project which contains a pic16f877 and
for that purpose I wrote in assembly language and used Mplab environment and ICD2
For burning the code to the pic.
can I use the same method here by copying the text of the code and use in the same
method? (by changing the configuration of Mplab to C code)

Yes, you can. But to do that, you need to download and install C compiler on your computer(try xc8 compiler from microchip). Then, while creating a new project on MPLAB, you have to select the installed C compiler as the toolchain. Now, create a new file, copy the code to this file, save the file with .c extension(not .asm) and build the project. Burning the code to the pic is the same as you did with assembly code.

Raj Gunaseelan
 

Hi,
I build this project up and for some reason it doesn't work.
I used a PIC16f877 and translated the co
I'm suspecting its a problem in the code. ( I checked the circuit and everything seems OK).
can anyone help me with this one?

Thanks, Amitai




LIST P=PIC16F877

include <P16f877.inc>
org 0x00

reset:
nop
goto start
org 0x20

start:
; configuration
;-----------------------------------

bcf STATUS,RP0 ;bank 0
bcf STATUS,RP1

ctr EQU H'0025' ; number of loops between two watchdog resets
previous EQU H'0026' ; previous value of ctr
calibr EQU H'0027' ; calibration value when oscillator runs free
restarts EQU H'0028' ; number of watchdog restarts
en EQU H'0029' ; enable flag, allows detection

bsf STATUS,RP0 ;bank 1
clrf TRISB ; making PORTB output
bcf STATUS,RP0 ;bank 0
clrf PORTB ; reset output

; end configuration
;-----------------------------------

;*************** MAIN PROGRAM *****************
main_loop:
bcf STATUS,RP0 ;bank 0
btfss STATUS, 4 ; POWER UP? WDT TIME OUT OCCURRED?
goto init_loops ; yes
goto check_reset_counter ; no

init_loops:
clrf restarts
movlw 0x01
movwf calibr

check_reset_counter:
movlw 0xFF
subwf restarts, w ; restarts - 255
btfss STATUS, C ; restarts =< 255 ?
incf restarts, f ; yes - increment restarts

movf previous, w
xorwf ctr
subwf calibr, w ; calibr - ( previous xor ctr)
btfss STATUS, C ; is previous XOR ctr > calibr ?
call metal_detcted ; yes

movf ctr, w
movwf previous

movlw 0x0F
subwf restarts, w ; restarts - 15
btfsc STATUS, C ; calibration over?
goto calib_over ; yes
goto calib_still_active ; no

calib_over:
bcf PORTB, 1 ; calib led OFF
movlw 0xFF
movwf en ; enable detect led
goto WDT_set

calib_still_active:
bsf PORTB, 1 ; calib led ON
clrf en ; disable detect led
goto WDT_set

WDT_set:
bsf STATUS,RP0 ;bank 1
movlw 0xF9
movwf OPTION_REG ; Prescaler Rate, PORTB pull-ups are disable? (needed)?

bcf STATUS,RP0 ;bank 0
clrf ctr

waiting_loop: ; start counter, to be interrupted by watchdog
btfss STATUS, 4
goto main_loop
incf ctr, f
goto waiting_loop

;------

metal_detcted:
bsf PORTB, 2 ; turn led detect ON

btfss STATUS, 4 ; time out occurred ?
goto led_off ; yes
goto calib_check ; no

led_off:
bcf PORTB, 2 ; turn led detect OFF
return

calib_check:
movlw 0x0F
subwf restarts, w ; restarts - 15
btfsc STATUS, C ; in calibration mode?
return ; no
rlf calibr
call DELAY_1m
call DELAY_1m
call DELAY_1m
call DELAY_1m
call DELAY_1m
return

;*************** END MAIN PROGRAM *************

DELAY_1m:
movlw 0x2f ; N1 = 47
movwf 0x35
cont2: movlw 0x10 ; N2 = 16
movwf 0x36
cont1: decfsz 0x36,1
goto cont1
decfsz 0x35,1
goto cont2
return

end
 

Hi,

Your code seems to have gone wrong at the beginning, you have directed the program code into the User register (ram) area.

Have modified the code as I would use it so it builds ok, though have not looked at its actual operation.

Also included the Configuration values which, if different you need to change to suit your needs


Code:
	LIST P=PIC16F877
	include <P16f877.inc>

	__CONFIG _LVP_OFF &_WDT_ON &_PWRTE_ON &_CP_OFF & _XT_OSC
	; basic config values  Watchdog ON, Lvp OFF, XT OSC crystal 4mhz and below

	
	cblock 0x20	; define user registers/variables

	ctr  		; number of loops between two watchdog resets
	previous	; previous value of ctr
	calibr  	; calibration value when oscillator runs free
	restarts 	; number of watchdog restarts
	en 			; enable flag, allows detection
	endc


	org 0x00
	nop
	goto start

start:
	; configuration
	;-----------------------------------
ction
	
	banksel  TRISB
	clrf	 TRISB 	  ; making PORTB output
	banksel	 0		 ;bank 0
	clrf 	PORTB  	; reset output
	
	; end configuration
	;-----------------------------------
	
	;*************** MAIN PROGRAM *****************
main_loop:
	bcf STATUS,RP0 ;bank 0
	btfss STATUS, 4 ; POWER UP? WDT TIME OUT OCCURRED?
	goto init_loops ; yes
	goto check_reset_counter ; no
	
init_loops:
	clrf restarts
	movlw 0x01
	movwf calibr
	
check_reset_counter:
	movlw 0xFF
	subwf restarts, w ; restarts - 255
	btfss STATUS, C ; restarts =< 255 ?
	incf restarts, f ; yes - increment restarts
	
	movf previous, w
	xorwf ctr
	subwf calibr, w ; calibr - ( previous xor ctr)
	btfss STATUS, C ; is previous XOR ctr > calibr ?
	call metal_detcted ; yes
	
	movf ctr, w
	movwf previous
	
	movlw 0x0F
	subwf restarts, w ; restarts - 15
	btfsc STATUS, C ; calibration over?
	goto calib_over ; yes
	goto calib_still_active ; no
	
calib_over:
	bcf PORTB, 1 ; calib led OFF
	movlw 0xFF
	movwf en ; enable detect led
	goto WDT_set
	
calib_still_active:
	bsf PORTB, 1 ; calib led ON
	clrf en ; disable detect led
	goto WDT_set
	
WDT_set:
	bsf STATUS,RP0 ;bank 1
	movlw 0xF9
	movwf OPTION_REG ; Prescaler Rate, PORTB pull-ups are disable? (needed)?
	
	bcf STATUS,RP0 ;bank 0
	clrf ctr
	
waiting_loop: ; start counter, to be interrupted by watchdog
	btfss STATUS, 4
	goto main_loop
	incf ctr, f
	goto waiting_loop
	
	;------
	
metal_detcted:
	bsf PORTB, 2 ; turn led detect ON
	
	btfss STATUS, 4 ; time out occurred ?
	goto led_off ; yes
	goto calib_check ; no
	
led_off:
	bcf PORTB, 2 ; turn led detect OFF
	return
	
calib_check:
	movlw 0x0F
	subwf restarts, w ; restarts - 15
	btfsc STATUS, C ; in calibration mode?
	return ; no
	rlf calibr
	call DELAY_1m
	call DELAY_1m
	call DELAY_1m
	call DELAY_1m
	call DELAY_1m
	return
	
	;*************** END MAIN PROGRAM *************
	
DELAY_1m:
	movlw 0x2f ; N1 = 47
	movwf 0x35
cont2: movlw 0x10 ; N2 = 16
	movwf 0x36
cont1: decfsz 0x36,1
	goto cont1
	decfsz 0x35,1
	goto cont2
	return
	
	end
 
Thanks!
I'm checking it know, in the meantime with no success.
( it might be a problem of wiring, components, etc.)
Maybe there's something in the code to change which is related
to the WTD or PWR?
I'm attaching a capture of the schematic

Capture.PNG

Amitai
 

Hi,

The Config parameters, you want the WTDog turned on, PWR up is normally on but only concerned with the chip actually powering up, not running your code.

You do need to change the XT_OSC to HS_OSC as used in the original code.

The Watchdogs main parameter is in the Option-Register, those two chips use the same layout so that should be ok.

Your hardware diagram , pins 11 ans 32 go to +5, pins 12 and 31 to 0v with the 100nf caps across 11 and 12 , 31 and 32.

For the chip to run pin1 Mclre must be tied to +5v , preferably by a resistor, around 10k.
 
Using a DMM I can see that the frequency on the inductor changes while having metal near,
but the led doesn't respond at all. the output of both the legs is
'0' continuously.
 

Using a DMM I can see that the frequency on the inductor changes while having metal near,
but the led doesn't respond at all. the output of both the legs is
'0' continuously.

Hi,

The original code does not show any config bits.

If you look at the datasheet for the two chips they both have a similar WDT time base of around 17/18ms and both use the same Post Scaler values as set by the Option Reg.

However the 12F also has a Pre Scaler, its value is set in the Config bits, but none shown in the original code.
If you check on those bits you will see that its default power on value is 1:512
 
OK, Thanks,
But what can I do with this information?

Amitai

As you can see in the original code, all the timings are revolving around the watchdog time period, which as the 877 does not have the prescaler of the 12F, means in the 877 certain events are happening 512 times faster.

Two simple choices, rewrite your code to compensate, or better still write you own code from scratch ,givne you can see the logic of the original code or buy that 12F as the guy has provided the .hex code.

If you search more you will probably find such a device using a 877a chip, as it such a popular one for diy projects

If you want to learn coding here are some good tutorials.

**broken link removed**
http://www.electro-tech-online.com/articles/nigel-goodwins-tutorials-in-c.467/
http://www.winpicprog.co.uk/pic_tutorial.htm
http://www.amqrp.org/elmer160/lessons/
http://www.epemag.wimborne.co.uk/resources.htm
http://www.mikroe.com/chapters/view/5/chapter-4-timers/
 

Hi,

For the chip to run pin1 Mclre must be tied to +5v , preferably by a resistor, around 10k.

As far as I understand that's only for the programming mode, no?
(after burning the PIC the chip needs only VSS and VDD )


- - - Updated - - -

Two simple choices, rewrite your code to compensate, or better still write you own code from scratch ,givne you can see the logic of the original code or buy that 12F as the guy has provided the .hex code.

First of all thanks again,
I prefer staying with the 877 PIC in the mean time since I don't have much time and it has some functions which I
need.
what option for compensating is their besides changing the option register values for
the prescaler rate? changing the oscillator to LP or XT mode?

besides I had an idea - maybe instead of using the WDT I can use an external oscillator and use the compare
function ?

Amitai
 

Hi,

Pin 1 of the 877 Must be tied to Vdd or it will not work properly, though it may appear to run if its not tied up.

Changing the Osc mode does not divide the signal.

There is no one simple fix to your problem, you have to sit down and go thought all the original code line by line and understand the code fully, then it becomes clear how you can make the changes needed to make it run on the 877.
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top