Thought I'd figured this stuff out years ago. Anyway, here's a little program to read the voltage on a bank of capacitors and fire a pair of FETs for a period of time depending on the 1's an 0's on 4 pins.
It should not allow the FETS to fire untill the adc reading is 466 or higher. However it fires regardless of adc reading.
What gotcha did I miss?
18F1320, running on 8mhz internal osc.
Code:
OSCCON = $70 'set internal resonator to 8mhz
Define ADC_BITS 10 ' Set number of bits in result
Define ADC_CLOCK 3 ' Set clock source (3=rc)
Define ADC_SAMPLEUS 50 ' Set sampling time in uS
DEFINE OSC 8
BNK1 VAR WORD
BNK2 VAR WORD
DUR VAR WORD
ADCON0 = %00000001
ADCON1 = %01111100
ADCON2 = %10111111
TRISA = %11111111
TRISB = %11110000
PORTB.0 = 1
PORTB.1 = 1
PORTB.2 = 1
PORTB.3 = 0
BNK1 = 0
BNK2 = 0
DUR = 0
MAIN:
DUR = 0
PORTB.3 = 0
BNK1 = 0
BNK2 = 0
ADCIN 0, BNK1
ADCIN 1, BNK2
IF PORTB.4 = 1 THEN DUR = 8
IF PORTB.5 = 1 THEN DUR = 4
IF PORTB.6 = 1 THEN DUR = 2
IF PORTB.7 = 1 THEN DUR = 1
IF BNK1 OR BNK2 => 466 THEN FLASH
IF BNK1 OR BNK2 =< 465 THEN MAIN
FLASH:
IF PORTA.4 = 1 OR PORTA.5 = 0 THEN PORTB.3 = 1
IF PORTA.4 = 1 OR PORTA.5 = 0 THEN PORTB.0 = 0 : PORTB.1 = 0
PORTB.3 = 0
IF DUR = 1 THEN PAUSE 1
IF DUR = 2 THEN PAUSE 2
IF DUR = 4 THEN PAUSE 4
IF DUR = 8 THEN PAUSE 8
PORTB.0 = 1 : PORTB.1 = 1
PAUSE 100
GOTO MAIN
Bookmarks