Continue to Site

# Help to solve ADC problem of 16F676

Status
Not open for further replies.

#### swapan

##### Full Member level 4
Friends,

Swapan

_CONFIG _CP_OFF & _CPD_OFF & _BODEN_OFF & _MCLRE_OFF & _WDT_OFF & _PWRTE_OFF & _HS_OSC

cblock 0x20
endc

Code:
start
CLRF	 PORTA
CLRF	 PORTC
BSF	 STATUS, RP0
MOVLW	 b'00111000'
MOVWF	 TRISA
MOVLW	 b'00111100'
MOVWF	 TRISC
MOVLW	 0XC0
MOVWF	 ANSEL
MOVLW	 b'00100000'
BCF	 STATUS, RP0
MOVLW	 0X07
MOVWF	 CMCON

MAIN_ON:

MOVLW	 b'00011001'

INIT:

GOTO	 INIT
MOVLW	 D'240'
BTFSS	 STATUS,C
GOTO	 RL_1
MOVLW	 B'00000000'
MOVWF	 PORTA

RL_1:

MOVLW	 D'220'
BTFSC	 STATUS,C
GOTO	 MAIN_ON
MOVLW	 b'00000001'
MOVWF	 PORTA
MOVLW	 D'200'
BTFSC	 STATUS,C
GOTO	 MAIN_ON
MOVLW	 b'00000011'
MOVWF	 PORTA

GOTO	 MAIN_ON

END

A very late ans:

From instruction set summary

SUBWF Subtract W from f
Syntax: [ label ] SUBWF f,d
Operands: 0 ≤ f ≤ 127
d ∈ [0,1]
Operation: (f) - (W) → (destination)
Status
Affected:
C, DC, Z
Description: Subtract (2’s complement method)
W register from register 'f'. If 'd' is 0,
the result is stored in the W
register. If 'd' is 1, the result is
stored back in register 'f'.

Put ,0 like this
result is stored in w register not back in AD_VALUE1
Code:
  INCLUDE "P16F676.INC"
__CONFIG _INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_ON & _MCLRE_OFF & _CP_OFF &

_CPD_OFF

cblock 0x20
endc

start
CLRF    PORTA
CLRF    PORTC
BSF    STATUS, RP0
MOVLW    b'00111000'
MOVWF    TRISA
MOVLW    b'00111100'
MOVWF    TRISC
MOVLW    0XC0
MOVWF    ANSEL
MOVLW    b'00100000'
BCF    STATUS, RP0
MOVLW    0X07
MOVWF    CMCON
MOVLW    b'00011001'

MAIN_ON:

INIT:

GOTO    INIT
MOVLW    D'240'
BTFSS    STATUS,C
GOTO    RL_1
MOVLW    B'00000000'
MOVWF    PORTA

RL_1:

MOVLW    D'220'
BTFSC    STATUS,C
GOTO    MAIN_ON
MOVLW    b'00000001'
MOVWF    PORTA
MOVLW    D'200'
BTFSC    STATUS,C
GOTO    MAIN_ON
MOVLW    b'00000011'
MOVWF    PORTA
GOTO    MAIN_ON

END
[/quote]\]
I tested it . at 5V , both relays are off. When voltage is lowered ,Below 4.3V , RA0 turns on. at 3.9 V RA1 turns on. When voltage is raised RA1 is o, showing hysterisis of 1 bit. While RA0 is turned off at 4.7V.
Actually this code is very basic , contais many flaws. As sampling input is rectified
ac containing ripple voltage so average of many samples at specific intervals will be needed after zero crossing detection. hysterisis should also be incorporated so
relay don't chatter at some voltages. Delay on timer of 3 to 5 minutes should be included. over / under voltage protection ,overload protection control through
software can also be included.
I KNOW WHEN YOU VISIT THIS PAGE SOME DAY YOU MAY SAY ,I'D ALREADY FOUND MY MISTAKE.

not properly work ...

Status
Not open for further replies.