Analog issue


Closed Thread
Results 1 to 19 of 19

Thread: Analog issue

Hybrid View

  1. #1
    Join Date
    Feb 2004
    Location
    Michigan, USA
    Posts
    305

    Default Analog issue

    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

  2. #2
    Join Date
    Mar 2009
    Location
    Florida USA
    Posts
    22


    Did you find this post helpful? Yes | No

    Question

    where are your ENDIF's

  3. #3
    Join Date
    Feb 2004
    Location
    Michigan, USA
    Posts
    305


    Did you find this post helpful? Yes | No

    Default

    I had end if's in there and it threw errors. Deleted and compiled fine.

  4. #4
    Join Date
    Mar 2009
    Location
    Florida USA
    Posts
    22


    Did you find this post helpful? Yes | No

    Default

    harr... That was the first what poked into my eye. When I copied your code into my editor (Microcode Studio), it did not compile (picbasic pro) and several error messages popped up.
    What software are you using to edit, compile etc.?

  5. #5
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by jmgelba View Post
    It should not allow the FETS to fire untill the adc reading is 466 or higher. However it fires regardless of adc reading.
    Perhaps changing ...
    Code:
    IF BNK1 OR BNK2 => 466 THEN FLASH
    IF BNK1 OR BNK2 =< 465 THEN MAIN
    ... to ...
    Code:
    IF (BNK1 => 466) OR (BNK2 => 466) THEN FLASH
    GOTO MAIN
    DT

  6. #6
    Join Date
    Feb 2004
    Location
    Michigan, USA
    Posts
    305


    Did you find this post helpful? Yes | No

    Default

    DT - Thanks, that fixed the issue.
    Now, an unexpected one has appeared. First I'll explain the product.
    We are looking for a 1 to 2ms pulse appearing on either porta.0 or porta.1. Upon receipt of the pulse I have to send out a 1, 2, 4 or 8ms pulse to turn on 2 FETs located at portb.0 and portb.1 The time of the pulse depends upon dipswitch settings.
    So if set to 4ms, the program should scan the capacitors for the correct voltage, wait for a pulse input, fire FET's for 4ms when received, go back and wait for the next pulse in.

    The problem is the FETS fire anywhere from 1 time to 6 times per one 1 ms pulse input.
    I need an ultra fast reaction time so after a pulse is recieved I cant go and do other stuff before turning on the FET's.

    I thought about adding a 10ms delay at the end of the flash subroutine and I've thought about adding a count. If count = 1 and there is a pulse received, I could tell it to ignore the input. The count would have to get to reset to zero in the loop somewhere.

    Heres the code as it stands right now.

    Code:
    OSCCON = $70 'set internal resonator to 8mhz
    Define  ADC_BITS        10     	' Set number of bits in result
    Define  ADC_CLOCK       5     	' Set clock source (3=rc)
    Define  ADC_SAMPLEUS    20    	' Set sampling time in uS
    DEFINE OSC 8
    BNK1 VAR WORD
    BNK2 VAR WORD
    DUR VAR WORD
    
    
    ADCON0 = %00000001
    ADCON1 = %01111100
    ADCON2 = %10111110
    
    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
    endif
    IF PORTB.5 = 1 THEN 
    DUR = 4
    endif
    IF PORTB.6 = 1 THEN 
    DUR = 2
    endif
    IF PORTB.7 = 1 THEN 
    DUR = 1
    endif
    IF (BNK1 => 466) OR (BNK2 => 466) THEN FLASH
    goto MAIN
    
    
    
    
    FLASH:
    IF PORTA.4 = 1 OR PORTA.5 = 0 THEN 
    PORTB.0 = 0 : PORTB.1 = 0 : PORTB.3 = 1
    endif
    
    
    IF DUR = 1 THEN 
    PAUSE 1
    endif
    IF DUR = 2 THEN 
    PAUSE 2
    endif
    IF DUR = 4 THEN 
    PAUSE 4
    endif
    IF DUR = 8 THEN 
    PAUSE 8
    endif
    PORTB.0 = 1 : PORTB.1 = 1 : PORTB.3 = 0
    
    GOTO MAIN

  7. #7
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Question

    Hi, JM

    That looks to be dealing with high voltage ... and very high instant currents.

    May be also a switching up converter to think to ...


    soooo ...

    are you REALLY sure there's no spike on either an ADC input or 5v supply rails ???

    could we have a piece of scheme showing the Fet's drive and the ADC inputs ???

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  8. #8
    Join Date
    Feb 2004
    Location
    Michigan, USA
    Posts
    305


    Did you find this post helpful? Yes | No

    Default

    There could be spikes - I have yet to measure for that. And yes, we are switching 2 channels, both at 760W each. 24v at 31.6 Amps.

    I'd have to ask the whole forum to sign an NDA to show you the schematic, but the 5v line has a lot of capacitance but the inputs do not as I cant wait for the line to charge. From input pulse to output on needs to be less than 35uS. My customer wanted 5uS or less originally!!

  9. #9
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by jmgelba View Post
    My customer wanted 5uS or less originally!!
    Make it so . . http://www.realmagicwands.com/
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

Similar Threads

  1. pic18f analog comparator problem
    By david.silaghi in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 6th May 2009, 09:38
  2. Pic getting part power from Analog Port
    By ShaneMichael in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 22nd April 2009, 10:34
  3. Help with Analog Interrupt
    By brid0030 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 13th February 2008, 18:14
  4. 18F1320 ... Strange Memory
    By Acetronics2 in forum mel PIC BASIC Pro
    Replies: 43
    Last Post: - 9th April 2006, 09:55
  5. analog inputs on 16F716
    By schwinn_rider in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 6th October 2005, 04:07

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts