Closed Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: (Microcontrollers request) Need help

  1. #1
    manbearpig001 is offline Newbie
    Join Date
    Jul 2010
    Posts
    27
    Rep Power
    0

    Question (Microcontrollers request) Need help

    Hey everyone
    ive been looking for some help on a recent project im working on. I need to create a code-activated locking system. I have worked out the hardware, however i need help with the software. I am using a pic 16f628a, and need help figuring out how i can check whether or not the correct buttons are being pressed in the correct order. When the correct order is accomplished, it needs to turn on a motor.

    Anyone who knows about programming microcontrollers, please contact me at andrewbourhis@gmail.com.

    I can send you the schematic i drew up as well if needed.

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Oct 2007
    Location
    /dev/null
    Posts
    4,513
    Blog Entries
    8
    Rep Power
    59

    Re: (Microcontrollers request) Need help

    You probably don't want to use code for that. I suggest you do it in hardware, unless the code needs to be able to be changed.

    Maybe something like this:
    Code:
    module DigitalLock(clk, reset, keys, unlock);
        parameter NKEYS=10;     // Number of keys
        parameter PCLEN=10;     // Length of the passcode
    
        input wire clk, reset;
        input wire [NKEYS-1:0] keys;
        output reg unlock;
    
        reg [1:0] state;
        localparam S_WAIT = 2'd0;
        localparam S_KEY = 2'd1;
        localparam S_INVALID = 2'd2;
    
        // 8-digit hardcoded decimal passcode. This can be changed to
        // suit the lock (alphabetic, alphanumeric, whatever).
        // In this case, the passcode is 5-9-0-4-1-2-7-3
        wire [9:0] passcode [0:7];
        assign passcode = {10'd5, 10'd9, 10'd0, 10'd4, 10'd1, 10'd2, 10'd7, 10'd3};
    
        // Index into the passcode array. The number of bits in the index
        // should be ceil( log2(N+1) ), where N is the number of digits in
        // the passcode.
        reg [INDEXW-1:0] index;
    
        // Main FSM
        always @( posedge clk ) begin
            if( reset ) begin
                state <= S_WAIT;
                unlock <= 1'b0;
                index <= 0;
            end
            else begin
                case( state )
                    S_WAIT: begin
                        state <= (keys != 0) ? S_KEY : S_WAIT;
                        index <= 0;
                    end
    
                    S_KEY:
                        // Reset button has been hit. We're now ready to start
                        // accepting digits from the keypad.
                        if( index > (PCLEN - 1) ) begin
                            // We're beyond the end of the passcode, which means
                            // that the user entered all the right digits. Strobe
                            // the unlock signal and go back to waiting.
                            state <= S_WAIT;
                            unlock <= 1'b1;
                        end
                        else begin
                            // Each bit in the "key" array represents a key.
                            // The way we check the passcode is to accept a key-
                            // stroke, look at the number in the passcode array
                            // that our index points to, and see if the corresp-
                            // onding bit in the key array is set. If so, then
                            // the correct digit has been entered, and we move
                            // on to the next digit. If not, we jump to the
                            // S_INVALID state, where we ignore everything until
                            // a reset signal is sent.
                            if( key & (1 << passcode[index]) == key) begin
                                // Mask is nonzero and only one key is being
                                // pressed. Move on to the next digit.
                                index <= index + 1;
                                state <= S_KEY;
                            end
                            else begin
                                // Invalid key pressed. Hang until the reset
                                // key is pressed.
                                state <= S_INVALID;
                                index <= 0;
                            end
                        end
                    end
    
                    // We only get here if the user pressed an invalid key.
                    // This'll hang and ignore any keystrokes until the reset
                    // button is pressed.
                    S_INVALID: begin
                        unlock <= 1'b0;
                        state <= S_INVALID;
                        index <= 0;
                    end
    
                endcase
            end
        end
    
    endmodule
    sudo rm -rf /

  4. #3
    manbearpig001 is offline Newbie
    Join Date
    Jul 2010
    Posts
    27
    Rep Power
    0

    Re: (Microcontrollers request) Need help

    quick question

    can you modify this code to fit my pin selection please?

    here is the schematic



    A5 is the reset button, and A1 is the lock button. When A1 is pressed, i want A6 and A4 to be activated.

    When the code is correctly punched in, i want A2 and A3 to be activated

    B0-B7, and A0 are the 9 code numbers, in order from B0 being 1, B1 being 2, etc.

    Also, once the code is punched in correctly, i only want the motor running for roughly 3-5 seconds. If you can point out to me the part of the code where i can change this, that would be great.

    Thanks so much

  5. #4
    Join Date
    Oct 2007
    Location
    /dev/null
    Posts
    4,513
    Blog Entries
    8
    Rep Power
    59

    Re: (Microcontrollers request) Need help

    The timing depends on the clock cycle. I'm thinking 5-10Hz should be enough; how about you? The key array can be hooked up however you want. It's just an interface; you do the wiring yourself. The other things need to be changed a bit. The motor running bit will need to trigger a separate countdown module which'll hold the motor signal high until it hits zero, then deactivate it. I'll try to work on it later today and get back to you.

    Edit: Do you know Verilog / have the capability to synthesize it? Otherwise this is pointless.
    sudo rm -rf /

  6. #5
    manbearpig001 is offline Newbie
    Join Date
    Jul 2010
    Posts
    27
    Rep Power
    0

    Re: (Microcontrollers request) Need help

    I do not have Verilog, however i dont seem to be in need of hardware help at the moment. I need help with writing an assembly script that runs my locking system. That schematic i posted was the schematic i plan on using.

    Also, i was planning on using the pic's internal timer, not adding a crystal, primarily due to the fact that i have no idea how to set up the crystal both programatically, and in the hardware design.

    thanks

  7. #6
    Join Date
    Oct 2007
    Location
    /dev/null
    Posts
    4,513
    Blog Entries
    8
    Rep Power
    59

    Re: (Microcontrollers request) Need help

    Ok, I found a datasheet on it, reading it now.
    sudo rm -rf /

  8. #7
    manbearpig001 is offline Newbie
    Join Date
    Jul 2010
    Posts
    27
    Rep Power
    0

    Re: (Microcontrollers request) Need help

    k sweet, thanks for the help

  9. #8
    Join Date
    Oct 2007
    Location
    /dev/null
    Posts
    4,513
    Blog Entries
    8
    Rep Power
    59

    Re: (Microcontrollers request) Need help

    Gonna be a while, though.
    sudo rm -rf /

  10. #9
    manbearpig001 is offline Newbie
    Join Date
    Jul 2010
    Posts
    27
    Rep Power
    0

    Re: (Microcontrollers request) Need help

    haha look, i know how to turn on/off the motor, and i know how to set up my pins for input and output etc.

    all i could use help with, is how to declare an array of integers, then assign each button to a number, then check if the buttons pressed match the array.

    (or any other way that could create the same function)

  11. #10
    Join Date
    Oct 2007
    Location
    /dev/null
    Posts
    4,513
    Blog Entries
    8
    Rep Power
    59

    Re: (Microcontrollers request) Need help

    The way I did it in the Verilog code was create a matrix of bits, and assign a button to each column. Whenever a button was pressed, the input would be checked against the matrix. If that row matched, then a counter would be incremented and the next row in the matrix would be checked. Once you hit the end, that means that the right buttons were pressed in the right order.

    Edit: My computer just suffered an epic crash, so this is going to be a looong while. Probably faster if you look up tutorials on Google.
    Last edited by dargueta; 07-30-2010 at 11:52 PM.
    sudo rm -rf /

Closed Thread
Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Assembly PIC Microcontrollers: Need help with project
    By manbearpig001 in forum General Programming
    Replies: 3
    Last Post: 01-05-2011, 09:46 PM
  2. Simple request
    By Taoist in forum C and C++
    Replies: 1
    Last Post: 12-15-2009, 05:20 PM
  3. UDP NAT request-reply
    By Code in forum C# Programming
    Replies: 0
    Last Post: 09-22-2008, 11:27 AM
  4. Code Request Please
    By elvenrunelord in forum JavaScript and CSS
    Replies: 9
    Last Post: 07-12-2008, 05:13 AM
  5. -[Request]- Come In..
    By Mef in forum C and C++
    Replies: 2
    Last Post: 06-23-2007, 07:50 PM

Bookmarks

Posting Permissions

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