12f675_fuse_about_to_blow! - Page 12


Closed Thread
Page 12 of 24 FirstFirst ... 2891011121314151622 ... LastLast
Results 441 to 480 of 929
  1. #441
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Sometimes understanding the process is the difficult part. When I am asked to help modify a machine from manual to auto I will set up a video recorder so I can study the complete sequence the machine is expected to go through.

    In my last post I forgot a variable. You will need a variable to remember how many times the machine has been started. Let's call this M_S.

    The first time the machine starts all EEPROM locations will have the value of zero.
    So the first thing will be to increment M_S to 1 and save that.
    Now the machine will go into normal operation.
    The TOTAL is incrementing. Saving to EEPROM.
    The Parts_Run is incrementing. Saving to EEPROM, this location could have the name of PS_1.

    The machine is shut down and re-started.
    The TOTAL EEPROM location(s) is read and the value is placed into var TOTAL.
    M_S is read and if it is 1 then two things need to happen. M_S will now be incremented and saved back to EEPROM. Now the Parts_Run value will need to write to another EEPROM location, this location could be named PS_2.

    The number of parts ran the first time will be unchanged. You may want to display this on the LCD.

    The same thing will happen each time the machine re-starts withe the Parts Run value saving to a different EEPROM location.

    Lets say you set this up for 5 re-starts.
    Code:
    TOTAL  VAR WORD  'STORED IN EEPROM LOCATIONS 0 AND 1
    PS_1   VAR WORD  'STORED IN EEPRON LOCATIONS 2 AND 3
    PS_2   VAR WORD  'STORED IN EEPRON LOCATIONS 4 AND 5
    PS_3   VAR WORD  'STORED IN EEPRON LOCATIONS 6 AND 7
    PS_4   VAR WORD  'STORED IN EEPRON LOCATIONS 8 AND 9
    PS_5   VAR WORD  'STORED IN EEPRON LOCATIONS 10 AND 11
    M_S    VAR BYTE  'STORED IN EEPRON LOCATIONS 12 AND 13
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default

    Cheers mackrackit,

    I can see that it would be a good idea to actually draw up what it is I'm trying to achieve rather than just 'coding' as an idea arrives. These programs can soon grow and become very complicated.

    Will be a good 'mission' to achieve this one, I've learned and am still learning from it.

    Dave

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


    Did you find this post helpful? Yes | No

    Default

    Hi mackrackit,

    From the brief:

    M_S VAR BYTE 'STORED IN EEPRON LOCATIONS 12 AND 13
    Does M_S need to be set as a BYTE or a WORD? If it's a BYTE is this ok?

    Code:
    WRITE 12, M_S
    Dave

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


    Did you find this post helpful? Yes | No

    Default

    Good catch. It only needs to be a BYTE with one EEPROM location in this app.
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default

    Good catch.
    More a stumble than a catch (program wouldn't compile)

    Dave

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


    Did you find this post helpful? Yes | No

    Default

    Hi mackrackit,

    Slow but steady progress tonight. I wouldn't go so far as to say the end is in sight but things are moving along.

    Now here's a question. Since I joined this FORUM in February I think it was. I've gone from not being able to blink an LED to having a working LCD in under 12 weeks, not to mention the Serial Communicator and other stuff we've done.

    So here's the question: Have you ever considered writing a book for 'Newbies' like me? I'll be perfrectly honest here, determined as I am, if I hadn't found this FORUM, well I would really has struggled to move on let's put it that way.

    Just a thought.

    Dave
    Last edited by LEDave; - 8th May 2010 at 23:44.

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


    Did you find this post helpful? Yes | No

    Default

    BOOK
    Nope, I have though about getting an "education" so I could teach at the local college though. That would be fun.

    The problem I have with books are the authors. The is a popular author out there on this subject that is even a member of this forum. Many newbies come to this forum after reading his book(s) and they still do not know much more than you did when you came here. Does the book author help out on the forum? Nope. So it seems there are books out there with out support. What good is that other than the author making money.

    So I figure if someone wants to learn, skip the book and go straight to the people that really want to help others learn. For PBP that would be this forum.

    Keep hanging out here on the forum, read every post and take lots of notes, when you see someone with a problem and you have an answer post it.

    Then someday someone will say to you, have you ever considered writing a ......
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default



    I hear what you're saying mackrackit.

    Keep hanging out here on the forum, read every post and take lots of notes, when you see someone with a problem and you have an answer post it.
    That would be nice, to be able to give something back to the FORUM...One day!

    Dave

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


    Did you find this post helpful? Yes | No

    Default

    UPDATE:

    I'm getting steadily closer.....!

    One piece of the program isn't doing what I want it to.....Grrr.

    I may have to ask for a pointer.

    Dave
    Last edited by LEDave; - 9th May 2010 at 20:47.

  10. #450
    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.

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


    Did you find this post helpful? Yes | No

    Default

    Well I gave a good go and in the end my lack of knowledge failed me.

    Here's what the program does:

    1/ It displays the 'Total' on line one.
    2/ It displays the number of Machine Starts on line two.

    Here's where things go wrong though. On line three it displays the Parts run count 1-5 but the number of parts run between stops always equals 'Total' and not 'Total - parts run' ie the difference.

    I've spent hours trying to crack it but I'm missing something.

    I'll post the whole program below, I'm sure there's lots of unnecessary and duplicated code (not to mention mistakes) within the program but hey I'm still a 'Newbie'.

    Dave
    Last edited by LEDave; - 10th May 2010 at 17:13.

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


    Did you find this post helpful? Yes | No

    Default

    Code:
    ANSEL   = %00000000    'Disable analog select so ports work as digital i/o.
    CMCON0  = %00000111    'Disable analog comparators.
    TRISA   = %00100000    'Set PORTA.5 as INPUT.
    PORTA   = %00000000    'Set PORTA pins all low.
    TRISC   = %00000000    'Set PORTC as OUTPUT.
    PORTC   = %00000000    'Set PORTC pins all low.
    
    DEFINE LCD_DREG     PORTC    'PORTC.0 WILL CONNECT TO DB4, PORTC3 TO DB7
    DEFINE LCD_DBIT     0
    DEFINE LCD_RSREG    PORTC
    DEFINE LCD_RSBIT    4        'PORTC.4 CONNECT TO LCD PIN4
    DEFINE LCD_EREG     PORTC
    DEFINE LCD_EBIT     5        'PORTC.5 CONNECT TO LCD PIN6
    DEFINE LCD_BITS     4
    DEFINE LCD_LINES    4
    DEFINE LCD_COMMANDUS 2000     
    DEFINE LCD_DATAUS 150
    
    DEFINE OSC 4
    
    TOTAL  VAR WORD  'STORED IN EEPROM LOCATIONS 0 AND 1
    PS_1   VAR WORD  'STORED IN EEPRON LOCATIONS 2 AND 3
    PS_2   VAR WORD  'STORED IN EEPRON LOCATIONS 4 AND 5
    PS_3   VAR WORD  'STORED IN EEPRON LOCATIONS 6 AND 7
    PS_4   VAR WORD  'STORED IN EEPRON LOCATIONS 8 AND 9
    PS_5   VAR WORD  'STORED IN EEPRON LOCATIONS 10 AND 11
    M_S    VAR BYTE  'STORED IN EEPRON LOCATIONS 12 
    
    clear                 'Re_set volatile memory to zero (Not EEPROM?)
    
    MAIN:
    
    gosub MC_S            'Set & increment M/C Starts Total subroutine
    gosub Power_up        'On Power_up GOTO READ EEPROM subroutine
    gosub Parts_Run       'Number of parts made
    
    
    Start:
    if PORTA.5 = 0  then  count_up: 'If button pressed start counting
    IF PORTA.5 = 1  THEN     Start: 'If button not pressed loop until it is
        
    Count_up:                 'Button has been pressed
    let Total = Total + 1     'Add one to value of Total taken from EEPROM
    pause 100
    LCDOUT $FE,2,"Total=",DEC TOTAL  'Display Total on LCD
    Write 0, Total.HIGHBYTE   ' Write high byte of Total word to EEPROM
    Write 1, Total.LOWBYTE    ' Write low byte of Total word to next address
    GOTO sTART:
    
    MC_S:                     'MC Starts subroutine
    READ 12, M_s              'Read current number of M/C Starts
    LET M_S = M_S + 1         'Increment value by one
    WRITE 12, M_S             'Save new value
    READ 12, M_s              'Read latest value
    pause 150                 'Give LCD a chance to Power_up
    LET M_S = M_S             'Set value to display
    LCDOUT $FE,$C0, "Machine Starts=",DEC M_S 'Display M/C Starts on LCD from EEPROM
    RETURN
    
     
    Power_up:                 'Power_up subroutine
    Read 0, Total.HIGHBYTE	  ' Read high byte
    Read 1, Total.LOWBYTe     ' Read low byte  
    LET Total = Total         'Set Total to value set in EEPROM Memory
    pause 150                 'Give LCD a chance to Power_up
    LCDOUT $FE,2,"Total=",DEC Total 'At Power_up display Total on LCD from EEPROM
                              'Memory which has been stored since Power_down
    return 
    
    Parts_Run:
    SELECT CASE M_S 
       CASE 1
       if M_s = 1 then PARTS1: 
       CASE 2
       IF M_S = 2 THEN PARTS2:
       CASE 3
       IF M_S = 3 THEN PARTS3:
       CASE 4
       IF M_S = 4 THEN PARTS4:
       CASE 5
       IF M_S = 5 THEN PARTS5:
    END SELECT 
    RETURN
    
    PARTS1:
    let PS_1 = Total
    WRITE 2,PS_1.HIGHBYTE
    WRITE 3,PS_1.LOWBYTE
    READ  2,PS_1.HIGHBYTE
    READ  3,PS_1.LOWBYTE
    LET PS_1 = PS_1
    PAUSE 150
    LCDOUT $FE, $94,"Parts1=",DEC PS_1
    return
    
    
    PARTS2:
    LET PS_2 = Total - PS_1
    WRITE 4,PS_2.HIGHBYTE
    WRITE 5,PS_2.LOWBYTE
    READ  4,PS_2.HIGHBYTE
    READ  5,PS_2.LOWBYTE
    LET PS_2 = PS_2
    PAUSE 150
    LCDOUT $FE, $94,"Parts2=",DEC PS_2
    return
    
    
    PARTS3:
    LET PS_3 = TOTAL - PS_2
    WRITE 6,PS_3.HIGHBYTE
    WRITE 7,PS_3.LOWBYTE
    READ  6,PS_3.HIGHBYTE
    READ  7,PS_3.LOWBYTE
    LET PS_3 = PS_3
    PAUSE 150
    LCDOUT $FE, $94,"Parts3=",DEC PS_3
    return
    
    
    PARTS4:
    LET PS_4 = TOTAL - PS_3
    WRITE 8,PS_4.HIGHBYTE
    WRITE 9,PS_4.LOWBYTE
    READ  8,PS_4.HIGHBYTE
    READ  9,PS_4.LOWBYTE
    LET PS_4 = PS_4
    PAUSE 150
    LCDOUT $FE, $94,"Parts4=",DEC PS_4
    return
    
    
    PARTS5:
    LET PS_5 = TOTAL - PS_4
    WRITE 10,PS_5.HIGHBYTE
    WRITE 11,PS_5.LOWBYTE
    READ  10,PS_5.HIGHBYTE
    READ  11,PS_5.LOWBYTE
    LET PS_5 = PS_5
    PAUSE 150
    LCDOUT $FE, $94,"Parts5=",DEC PS_5
    return
    Last edited by LEDave; - 10th May 2010 at 17:09.

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


    Did you find this post helpful? Yes | No

    Default

    I am on a very small display right now so I might be missing something...

    It looks like having PS_1 and PS_2 and so on equaling TOTAL is the problem.
    The PS_X's should be independent of the TOTAL. If all of the PS_X's are added together then they will equal TOTAL.
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default

    Cheers mackrackit,

    It looks like having PS_1 and PS_2 and so on equaling TOTAL is the problem.
    The PS_X's should be independent of the TOTAL. If all of the PS_X's are added together then they will equal TOTAL.
    I'll have a think about that one and make some changes.

    Dave

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


    Did you find this post helpful? Yes | No

    Default

    Ok, I've got an idea to work on now (I was lost before). So each PS_1 - 2 - 3 etc, are all individual counting loops.So each time 'Total does one count it then enters PS_n so yo have one Total counter and five PS_n counters.

    I'm back on the scent now......

    Cheers mackrackit.

    Dave

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


    Did you find this post helpful? Yes | No

    Default

    In think you got it now.
    I made this up but you may not need it, sometimes even a "bad" flowchart helps.
    Name:  EPPROM_FLOW.jpg
Views: 942
Size:  102.4 KB
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default

    Brilliant flowchart mackrackit

    Yes over the last hurdle now (I think). I've got PS_1-5 counting their own totals. Small problem in that the counts started from one all the time, then I realised that the button condition could set the count which your flow chart confirmed

    All being well the 'Mission' will be completed tomorrow.

    Watch this space...

    Dave

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


    Did you find this post helpful? Yes | No

    Default

    One last question (I think).

    The very first time the M/C is started we want 'Total' to equal zero (after all nothing's been made yet) So how do I initialize EEPROM 'Total' to zero the first time the M/C runs?. The second time it starts it reads the stored value of 'Total' and adds to that.

    The reason I'm asking this is because every time I compile and run the program, there seems to be a value already stored on EEPROM 'Total'.

    Dave

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


    Did you find this post helpful? Yes | No

    Default

    Probably the best way for testing would be to write a program that writes zero to all of the EEPROM locations that you are using then re-code the chip with your main program.

    If this was for real life then a hidden reset switch or jumper could have a routine to write zeros run. Then when the jumper is removed the code jumps over the zero routine and runs the main program.
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default

    Cheers mackrackit

    So allowing for the fact that Total may contain 'random' data at start I think I've finished the 'Mission'....Hoorah!

    I've added the average parts run over the five runs on line four of the LCD. Here's the program. What do you think?:

    Code:
    ANSEL   = %00000000    'Disable analog select so ports work as digital i/o.
    CMCON0  = %00000111    'Disable analog comparators.
    TRISA   = %00100000    'Set PORTA.5 as OUTPUT.
    PORTA   = %00000000    'Set PORTA pins all low.
    TRISC   = %00000000    'Set PORTC as OUTPUT.
    PORTC   = %00000000    'Set PORTC pins all low.
    
    DEFINE LCD_DREG     PORTC    'PORTC.0 WILL CONNECT TO DB4, PORTC3 TO DB7
    DEFINE LCD_DBIT     0
    DEFINE LCD_RSREG    PORTC
    DEFINE LCD_RSBIT    4        'PORTC.4 CONNECT TO LCD PIN4
    DEFINE LCD_EREG     PORTC
    DEFINE LCD_EBIT     5        'PORTC.5 CONNECT TO LCD PIN6
    DEFINE LCD_BITS     4
    DEFINE LCD_LINES    4
    DEFINE LCD_COMMANDUS 2000     
    DEFINE LCD_DATAUS 150
    
    DEFINE OSC 4
    
    TOTAL  VAR WORD  'STORED IN EEPROM LOCATIONS 0 AND 1
    PS_1   VAR WORD  'STORED IN EEPRON LOCATIONS 2 AND 3
    PS_2   VAR WORD  'STORED IN EEPRON LOCATIONS 4 AND 5
    PS_3   VAR WORD  'STORED IN EEPRON LOCATIONS 6 AND 7
    PS_4   VAR WORD  'STORED IN EEPRON LOCATIONS 8 AND 9
    PS_5   VAR WORD  'STORED IN EEPRON LOCATIONS 10 AND 11
    M_S    VAR BYTE  'STORED IN EEPRON LOCATIONS 12
    AV_Parts_Run var word 'STORED IN EEPRON LOCATIONS 13 AND 14
    
    clear                 'Re_set volatile memory to zero (Not EEPROM?)
    
    MAIN:
    gosub MC_S            'Set & increment M/C Starts Total subroutine
    gosub Power_up        'On Power_up GOTO READ EEPROM subroutine
    
    
    Start:
    if PORTA.5 = 0  then  count_up: 'Button pressed start counting
    IF PORTA.5 = 1  THEN     Start: 'If button not pressed loop until it is
        
    Count_up:                 'Button has been pressed
    let Total = Total + 1     'Add one to value of Total taken from EEPROM
    pause 100
    LCDOUT $FE,2,"Total=",DEC TOTAL  'Display Total on LCD
    Write 0, Total.HIGHBYTE   ' Write high byte of Total word to EEPROM
    Write 1, Total.LOWBYTE    ' Write low byte of Total word to next address
    gosub Parts_Run           'Number of parts made
    GOTO START:
    
    MC_S:                     'MC Starts subroutine
    READ 12, M_s              'Read current number of M/C Starts
    LET M_S = M_S + 1         'Increment value by one
    WRITE 12, M_S             'Save new value
    READ 12, M_s              'Read latest value
    pause 150                 'Give LCD a chance to Power_up
    LET M_S = M_S             'Set value to display
    LCDOUT $FE,$C0, "Machine Starts=",DEC M_S 'Display M/C Starts on LCD from EEPROM
    RETURN
    
    Power_up:                 'Power_up subroutine
    Read 0, Total.HIGHBYTE	  ' Read high byte
    Read 1, Total.LOWBYTe     ' Read low byte  
    LET Total = Total         'Set Total to value set in EEPROM Memory
    pause 150                 'Give LCD a chance to Power_up
    LCDOUT $FE,2,"Total=",DEC Total 'At Power_up display Total on LCD from EEPROM
                              'Memory which has been stored since Power_down                      
    return 
    
    Parts_Run:
    SELECT CASE M_S 
       CASE 1
       if M_s = 1 then PARTS1: 
       CASE 2
       IF M_S = 2 THEN PARTS2:
       CASE 3
       IF M_S = 3 THEN PARTS3:
       CASE 4
       IF M_S = 4 THEN PARTS4:
       CASE 5
       IF M_S = 5 THEN PARTS5:
    END SELECT 
    RETURN
    
    PARTS1:
    let PS_1 = PS_1 + 1
    WRITE 2,PS_1.HIGHBYTE
    WRITE 3,PS_1.LOWBYTE
    READ  2,PS_1.HIGHBYTE
    READ  3,PS_1.LOWBYTE
    LET PS_1 = PS_1
    PAUSE 150
    LCDOUT $FE, $94,"Parts1=",DEC PS_1
    return
    
    
    PARTS2:
    LET PS_2 = PS_2 + 1
    WRITE 4,PS_2.HIGHBYTE
    WRITE 5,PS_2.LOWBYTE
    READ  4,PS_2.HIGHBYTE
    READ  5,PS_2.LOWBYTE
    LET PS_2 = PS_2
    PAUSE 150
    LCDOUT $FE, $94,"Parts2=",DEC PS_2
    return
    
    
    PARTS3:
    LET PS_3 = PS_3 + 1
    WRITE 6,PS_3.HIGHBYTE
    WRITE 7,PS_3.LOWBYTE
    READ  6,PS_3.HIGHBYTE
    READ  7,PS_3.LOWBYTE
    LET PS_3 = PS_3
    PAUSE 150
    LCDOUT $FE, $94,"Parts3=",DEC PS_3
    return
    
    
    PARTS4:
    LET PS_4 = PS_4 + 1
    WRITE 8,PS_4.HIGHBYTE
    WRITE 9,PS_4.LOWBYTE
    READ  8,PS_4.HIGHBYTE
    READ  9,PS_4.LOWBYTE
    LET PS_4 = PS_4
    PAUSE 150
    LCDOUT $FE, $94,"Parts4=",DEC PS_4
    return
    
    
    PARTS5:
    LET PS_5 = PS_5 + 1
    WRITE 10,PS_5.HIGHBYTE
    WRITE 11,PS_5.LOWBYTE
    READ  10,PS_5.HIGHBYTE
    READ  11,PS_5.LOWBYTE
    LET PS_5 = PS_5
    PAUSE 150
    LCDOUT $FE, $94,"Parts5=",DEC PS_5
    
    READ  2,PS_1.HIGHBYTE
    READ  3,PS_1.LOWBYTE
    LET PS_1 = PS_1
    READ  4,PS_2.HIGHBYTE
    READ  5,PS_2.LOWBYTE
    LET PS_2 = PS_2
    READ  6,PS_3.HIGHBYTE
    READ  7,PS_3.LOWBYTE
    LET PS_3 = PS_3
    READ  8,PS_4.HIGHBYTE
    READ  9,PS_4.LOWBYTE
    LET PS_4 = PS_4
    READ  10,PS_5.HIGHBYTE
    READ  11,PS_5.LOWBYTE
    LET PS_5 = PS_5
    
    let AV_Parts_Run = (PS_1 + PS_2 + PS_3 + PS_4 + PS_5)/5
    write 13,AV_parts_Run.HIGHBYTE
    WRITE 14,AV_Parts_Run.LOWBYTE
    READ  13,AV_parts_Run.HIGHBYTE
    READ  14,AV_Parts_Run.LOWBYTE
    let AV_Parts_Run = AV_Parts_Run
    PAUSE 150
    LCDOUT $FE, $D4,"AV_Parts_Run =",DEC AV_Parts_Run
    end
    Last edited by LEDave; - 11th May 2010 at 16:52.

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


    Did you find this post helpful? Yes | No

    Default

    I am on the road again with a small display but what I can see looks good!

    I take you have ran it a few times and it is working as expected?
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default

    I take you have ran it a few times and it is working as expected?
    I've got a bug (it maybe a small infestation!)...(I could have swore it worked earlier!)

    I spoke too soon, 'Mission' incomplete. I'll try and debug it later tonight.

    Dave

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


    Did you find this post helpful? Yes | No

    Default

    I added a couple things, messes up your averaging part (never gets there now) but maybe this will help.
    Other than that it is looking good!!!!
    Code:
    MC_S:                     'MC Starts subroutine
    READ 12, M_s              'Read current number of M/C Starts
    LET M_S = M_S + 1         'Increment value by one
    '#######
    IF M_S > 5 THEN
    M_S = 0
    ENDIF
    '#######
    WRITE 12, M_S             'Save new value
    READ 12, M_s              'Read latest value
    pause 150                 'Give LCD a chance to Power_up
    LET M_S = M_S             'Set value to display
    LCDOUT $FE,$C0, "Machine Starts=",DEC M_S 'Display M/C Starts on LCD from EEPROM
    RETURN
    
    Power_up:                 'Power_up subroutine
    Read 0, Total.HIGHBYTE      ' Read high byte
    Read 1, Total.LOWBYTe     ' Read low byte  
    '#######
    IF TOTAL > 5000 THEN
    TOTAL = 0
    ENDIF
    '#######
    LET Total = Total         'Set Total to value set in EEPROM Memory
    pause 150                 'Give LCD a chance to Power_up
    LCDOUT $FE,2,"Total=",DEC Total 'At Power_up display Total on LCD from EEPROM
                              'Memory which has been stored since Power_down                      
    return
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default

    Hi mackrackit

    Thanks for the 'addins' I've run the program and apart from 'Total' (when the program starts for the first time after compiling not equalling zero) I reckon it works, even the Av_Parts_Run works if you subtract that spurious 'Total' figure, so well pleased.

    What do you reckon?

    Dave

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


    Did you find this post helpful? Yes | No

    Default

    Set things up so when a pin is held HIGH at start-up the EEPROM is re-set to zeros. Then you should have a complete counting/storage system that can be re-set.

    Now we have to think of something else for you to do
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default

    Set things up so when a pin is held HIGH at start-up the EEPROM is re-set to zeros. Then you should have a complete counting/storage system that can be re-set.
    Gotcha......

    Now we have to think of something else for you to do"
    How about this for a quick diversion: How are we on using a PIC to drive a servo motor?

    We've been getting a visitor to our garden late at night (we think it's a Badger) and would like to film it. I've got a FUTABA FP-5148 servo that I'd like to link up to a cable release to press the record button on a video camera after receiving an input from a PIR to the PIC.

    The sequence is this:

    1/ PIR 'beam' get broken by 'Creature'.
    2/ PIC activates servo to move cable release out and turn camera on.
    3/ PIC waits 10 secs while camera boots up.
    4/ PIC activates servo again moves cable release out turns camera record on (same button).

    The camera will record on it's own for 10 mins then powers down.

    5/ If PIR been is still broken (creature still there) after 9min:30secs servo presses record button again.

    6/ PIR beam 'closes' creature has gone, camera powers down.

    What do you think mackrackit?

    Dave

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


    Did you find this post helpful? Yes | No

    Default

    Sounds like fun...
    But what do you do when you find out it is a badger... or not

    Do you have the data sheet for the servo? PIR?
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default

    But what do you do when you find out it is a badger... or not
    I hadn't considered the 'or not' option......

    Do you have the data sheet for the servo? PIR?
    Well the PIR is just using a set of normally open contacts.The actual PIR is 12V I don't have a data sheet but I'm thinking that if I use 5V on the N/O contacts with a resistor onto the PIC that should be alright (I hope).

    The servo itself is a FUTABA FP5148 I don't have a data sheet for this either but I could email Futaba and ask for one (it's and old three wire job) I've looked on their website but all the product numbers have moved on so nothing to go on. It was for a model glider.

    It probably an old version of one of these below:

    http://www.futaba-rc.com/servos/servos.html

    Not much for you to go on mackrackit I know, what do you think though worth a try?

    Dave
    Last edited by LEDave; - 12th May 2010 at 19:54.

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


    Did you find this post helpful? Yes | No

    Default

    Yip. Worth a try.

    Someone here I am sure knows about this servo, voltage and things.
    I will guess 5 volts will work.

    PIR will be easy...
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default

    Ok the project's underway.

    What were you thinking for the next 'Mission' mackrackit?
    Last edited by LEDave; - 12th May 2010 at 20:36.

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


    Did you find this post helpful? Yes | No

    Default

    I was thinking something with ADC and LOOKUP tables. But have not really figured out a project yet.
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default

    I was thinking something with ADC and LOOKUP tables. But have not really figured out a project yet.
    Sounds very interesting. As ever though as and when mackrackit (you know I appreciate your time and effort putting into me).

    I'll try and progress the project for now.

    Dave

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


    Did you find this post helpful? Yes | No

    Default

    Starting to use servos? here is an interesting thread.
    http://www.picbasic.co.uk/forum/showthread.php?t=8000
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default

    Well I wasn't expecting that as a header!:

    Automatic Toilet Flusher
    Anyroad, some interesting stuff there. A lot of the reading I'm doing on servo's say to use a separate power supply for the motor and common the grounds up. Why would you want to do that? Is it a noise thing?

    Dave

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


    Did you find this post helpful? Yes | No

    Default

    I found this posted by Bruce, kind of answers my last question:

    Make sure you're using a separate power supply for your servo, and you have a common ground between them. Running a servo from your controller power supply can cause problems if you aren't using a hefty bench type power supply with a lot of filtering to remove motor noise.

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


    Did you find this post helpful? Yes | No

    Default

    Yup, as always Bruce gives good advice.

    If the servor is a small one like the ones from the basic stamp folks you can get away with one battery pack and a large capacitor. At least they sell their little robots that way and they do work pretty well.
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default

    PROJECT UPDATE:

    PIR was a snip. Works fine off a 12V battery and has a pair of N/C contacts for 5V onto the PIC.

    I've managed to mount the servo into a housing and 'rig_up' a bracket to hold the cable release in position for the servo, looks good and should work a treat.

    All I need to do now is finish the program. I'm off all this week but Mrs LEDave has had me replacing the garden fence No sense of priority some people!!!

    I'll post my program up asap.

    Dave

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


    Did you find this post helpful? Yes | No

    Default

    I'm off all this week but Mrs LEDave has had me replacing the garden fence No sense of priority some people!!!
    And if the badger is on the outside you may not need this project???
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default

    And if the badger is on the outside you may not need this project
    Lol....

    Wooden panels down the sides, wire and post at the bottom, we back onto an open field (Badger friendly fencing!).

    That said, they come in from the front, down the side of the building and into the back garden (we think), talk about nerve.

    The project will prove once and for all what's going on in the wee hours.

    Dave

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


    Did you find this post helpful? Yes | No

    Default

    Fence update: I should have got a man in..... No, I should have got two men in!

    Hopefully tomorrow I'll have a bit of time to set too with the program.

    Dave

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