12f675_fuse_about_to_blow!


Closed Thread
Results 1 to 40 of 929

Hybrid View

  1. #1
    Join Date
    Feb 2010
    Location
    I live in the UK
    Posts
    562


    Did you find this post helpful? Yes | No

    Default

    I bet you thought I'd left the Country the time this one has taken me. I must admit I really confused myself at times and went around in circles a little (ok, a lot).

    Anyway I think I've managed to convert mackrackit's 8bit ADC to a 10bit for the 16F684. I would be very interested to hear how I've done on this one. Seems to work, or have I just 'lucked in'?

    Code:
    DEFINE OSC 4
      
      @DEVICE_INTRC_OSC_NOCLKOUT
      @DEVICE_WDT_ON 
      @DEVICE_MCLRE_OFF
      @DEVICE_CP_OFF 
      
      ANSEL = %00000001 'CHANNEL AN0 
      ADCON1 = %01010000 'FOSC/16
      TRISA = %00000001  'AN0_Input Pin
      CMCON0 = %00000111 'COMPARATORS OFF. 
      CHAN0  VAR word   'VAR TO HOLD ADC0N READING (10-BIT)
    
        CHECK:
        GOSUB ADC_0 
        GOSUB BLINK       
        GOTO CHECK  
        
        BLINK:
        SELECT CASE CHAN0  
               
               CASE IS > 64    
                    TRISA = %11001111 
                    PORTA = %00010000       
               CASE ELSE 
                    PORTA = %00000000 
        END SELECT 
        RETURN
    
        ADC_0:       'READ AN0
        ADCON0 = %10000001      'BIT0=ADC ENABLE: BIT1=A/D CONVERSION STATUS BIT
                                'BITS2-4=AN0 CHANNEL SELECT BIT(CHS0): ADFM BIT1= right justified
        GOSUB   READ_AD
        CHAN0.highbyte = ADRESH  'A/D HIGHBYTE
        CHAN0.LOWBYTE  = ADRESL  'A/D LOWBYTE
        RETURN
    
        READ_AD:   'START THE ADC CONVERSION
        PAUSE 50
        ADCON0.1=1 '1 = A/D conversion cycle in progress.
                   'Setting this bit starts an A/D conversion cycle.
        WHILE ADCON0.1=1:WEND 'Do WHILE condition is TRUE (I like WEND!).
        RETURN
    Dave
    Last edited by LEDave; - 10th August 2010 at 21:18.

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    (I like WEND!)


    Looks like you got it!!!

    Now change the select case to use the ten bit values. 0 to 1023.
    And for you project you may want to play with some averaging. Analog will tend to drift with a temperature flux (resistors) or more so for your application how sensitive you want the LDR (stray car lights?).
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Feb 2010
    Location
    I live in the UK
    Posts
    562


    Did you find this post helpful? Yes | No

    Default

    I changed the value to 1022 and the led lit and occasionally flicked off then back on, so right at the end of the 10bit conversion / pot sensitivity. At a value of 1 the led lit with some pot 'travel' still left. So pretty spot on I'd say:

    And for you project you may want to play with some averaging. Analog will tend to drift with a temperature flux (resistors) or more so for your application how sensitive you want the LDR (stray car lights?).
    Mmm, interesting. I want to transmit the data (days total count) when it's dark and the parents have stopped feeding the young for the day. Like you say though, I don't want say the garden PIR light (when the Badger arrives) to effect things so some averaging and tweaking / testing needed here.

    As ever a big thank you for the 8bit ADC program pointer mackrackit. When it came to doing the 10bit conversion I've learned a lot about setting REGISTER bits, I'm still painfully slow but I guess that will improve with time / practise really interesting learning though.

    Code:
    ADFM BIT1= right justified
    Just spotted that this should read ADFM BIT7=1= right justified

    And as for WEND, I suppose elegant would be the word.

    Dave
    Last edited by LEDave; - 11th August 2010 at 10:56.

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Just spotted that this should read ADFM BIT7=1= right justified
    But your code was correct....

    Have you done a FOR/NEXT loop yet?
    Here is a snip from an 8 bit averaging. Pretty simple. Some like to throw out the first and last readings and only use the middle values. I guess it depends on the app..
    Code:
    GET_T:
      ADC_TEMP = 0
      FOR X_TEMP = 1 TO 20
      ADCON0=00000001
      GOSUB READ_AD
      S_TEMP = ADRESH
      ADC_TEMP = ADC_TEMP + S_TEMP
      PAUSE 250
      NEXT X_TEMP
      OUT_TEMP = ADC_TEMP / 20
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Dave
    Always wear safety glasses while programming.

  6. #6
    Join Date
    Feb 2010
    Location
    I live in the UK
    Posts
    562


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    Here is another way.
    It's not fair you know, Derrel Taylor may have the same initials as me, even the same surname but his brain must be at least twice the size........at least!

    Very clever program (I'll fess up I had to WIKI hysteresis(I had heard of it though)).

    Dave

  7. #7
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    I sometimes think DT is part machine The stuff he comes up with is invaluable around here. I am just happy that he shares his hard earned knowledge.

    The GUI from Bruce's site I think is written in Visual Basic. Here is something he has to offer.
    http://www.rentron.com/AD_LOG.htm

    Do you have a language for the PC that you use? You could make you own.
    Dave
    Always wear safety glasses while programming.

  8. #8
    Join Date
    Feb 2010
    Location
    I live in the UK
    Posts
    562


    Did you find this post helpful? Yes | No

    Default

    Have you done a FOR/NEXT loop yet?
    Yes, your good self and Henrik explained FOR/NEXT loop and LOOKUP when I was using a BCD driver to make a seven segment display count up and down from 0-9 and write my name. Seems like ages ago now, it was only February/March this year

    So your example adds the value S_TEMP to the stored value ADC_TEMP which is done 20 times, then the ADC_TEMP value is output as OUT_TEMP a 20 cycle average (I hope I've read this right).

    Now I'm thinking thermocouple / ADC / Seven segment display.....Another project!

    Ah, before I forget, from your ADC/rentron explanation link you posted earlier. The ADC conversion is displayed on a rather nice data logger display, is this logger included in the Microcode studio package the same as the Serial Communicator? Image below:

    Dave
    Attached Images Attached Images  

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