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.

PIC circuit help

Status
Not open for further replies.

trojan89

New Member
I need to activate a realy using a PIC16f628a microcontroller. I have tested my program using the Oshon simulator for the same microcontroller. But when i wire up the circuit i am not getting an output.
This is the program
; Begin
R0L EQU 0x20
R0H EQU 0x21
R1L EQU 0x22
R1H EQU 0x23
R2L EQU 0x24
R2H EQU 0x25
R3L EQU 0x26
R3H EQU 0x27
R4L EQU 0x28
R4H EQU 0x29
R5L EQU 0x2A
R5H EQU 0x2B
ORG 0x0000
BCF PCLATH,3
BCF PCLATH,4
GOTO L0002
ORG 0x0003
RETFIE
L0002:
; 1: Symbol comp_change = PIR1.CMIF 'comparator interrupt flag
; The address of 'comp_change' is 0xC,6
; 2:
; 3: CMCON = 0x06 'set comparator mode to two common reference comparators with outputs
MOVLW 0x06
MOVWF 0x1F
; 4: TRISA = 0x07 'set RA0, RA1 and RA2 as inputs, other PORTA pins as outputs
BSF STATUS,RP0
MOVLW 0x07
MOVWF 0x05
BCF STATUS,RP0
; 5: VRCON = 0xec 'turn on, configure voltage reference module for 2.5V and connect it to RA2
BSF STATUS,RP0
MOVLW 0xEC
MOVWF 0x1F
BCF STATUS,RP0
; 6: TRISB = 0x00 'set PORTB pins as outputs
BSF STATUS,RP0
CLRF 0x06
BCF STATUS,RP0
; 7:
; 8: loop1:
L0001:
; 9: While Not comp_change 'wait for comparator output change
L0003:
BTFSC 0x0C,6
GOTO L0004
; 10: Wend
GOTO L0003
L0004: MOVLW 0x1F
ANDWF STATUS,F
; 11: PORTB = CMCON 'display CMCON register on PORTB pins, RB6 and RB7 are comparator outputs
XORWF 0X1F,0X01
MOVF 0x1F,W
MOVWF 0x06
; 12: comp_change = 0 'reset comparator interrupt flag
BCF 0x0C,6
; 13: Goto loop1 'repeat forever
GOTO L0001
; End of program
L0005: GOTO L0005
; End of listing
END


Please guide me as to what connections i need to be making to make it work. Because i have been trying for nearly a week am at my wit's end

.**broken link removed**

**broken link removed**

The two images show pin12 going from low to high when input goes over 2.5v.
Please tell me as to how to wire up the circuit because i am an amateur.

Incase the pics arent showing
the links are
1."http://picasaweb.google.com/narasimha.89/PICmicrocontroller#5452009253650278610"
2."http://picasaweb.google.com/narasimha.89/PICmicrocontroller#5452009246352389138"

Right now im wirng up Vdd Vss pin18(ra1) and pin12(rb6). Are there any more connections i need to wire up?
Thanks in advance.
 
Last edited:
Did you measure at the PIC output? Or are you just not seeing the relay switch on?

Dont forget to pull MCLR high with a 10k pullup resistor.

I dont see your configuration / fuse settings, are you implementing the watchdog timer? If so it will be resetting your processor as you haven't switched it off, and you are not clearing it periodically.

Some simulators ignore these features and carry on working without them needed to be implemented.

Do you have a schematic of how your system is wired up?

Wilksey
 
Did you measure at the PIC output? Or are you just not seeing the relay switch on?

Dont forget to pull MCLR high with a 10k pullup resistor.

I dont see your configuration / fuse settings, are you implementing the watchdog timer? If so it will be resetting your processor as you haven't switched it off, and you are not clearing it periodically.

Some simulators ignore these features and carry on working without them needed to be implemented.

Do you have a schematic of how your system is wired up?

Wilksey

I measured the output of pic and the relay. Am not getting

an output at either.I have pulled the MCLR pin high with a 10k resistor a push button and 5V supply.

As for the watchdog timer, I am an amateur could you please help me understand as to how to program the watchdog timer? And how it could affect the program?
 
What did you use to make that assembler? It looks like it's been disassembled from something as it has generic labels.

In MPASM for a 16F chip for ex you would write:
Code:
__CONFIG CONFIG1, _WDT_OFF &&  _INTIO && _MCLRE_OFF && _LVP_OFF

This turns off watchdog, low voltage programming, and disables MCLR, it also sets the internal oscillator with OSC pins as IO.

The watchdog timer is a "failsafe" module built into most PIC chips, what it does is listen for a command called clearwdt, which is clear watch dog timer, if it does not get this command within the watchdog timeout period it will reset the processor, so in effect, if you never clear the WDT and dont switch it off your chip will be in a permanent reset cycle.
Much like if you didn't pull MCLR high.

Wilksey
 
What did you use to make that assembler? It looks like it's been disassembled from something as it has generic labels.

In MPASM for a 16F chip for ex you would write:
Code:
__CONFIG CONFIG1, _WDT_OFF &&  _INTIO && _MCLRE_OFF && _LVP_OFF

This turns off watchdog, low voltage programming, and disables MCLR, it also sets the internal oscillator with OSC pins as IO.

The watchdog timer is a "failsafe" module built into most PIC chips, what it does is listen for a command called clearwdt, which is clear watch dog timer, if it does not get this command within the watchdog timeout period it will reset the processor, so in effect, if you never clear the WDT and dont switch it off your chip will be in a permanent reset cycle.
Much like if you didn't pull MCLR high.

Wilksey

So if i pulled MCLR high I wouldn't need to write that line?Thing is I got the PIC to work...now it goes to 4.5v above the specified voltage and remains at 0.4 when below. So do i need to add any code to make it better? I only ask because it seems to work and this being my first project with a PIC don't want to fix something which isn't broken.
 
It's considered a no-no to disable MCLR and use the Internal Oscillator at the same time. The reason is because you can find it very hard to reprogram your PIC again as the PIC starts up and runs the program before the programmer can stop it.


Edit: so yeh I would leave it as it is (with the 10K pull and MCLR enabled) if it's working.
 
Last edited:
Nope, I always opt for pulling the line high.

You got the PIC to work, do you mean setting the correct pin high / low?

What did you do to make it work?

Wilksey
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top