I Need Help.. I want to generate controlled pulses


Closed Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Nov 2007
    Posts
    4

    Default I Need Help.. I want to generate controlled pulses

    Hey all.. how are you.. hope ur doin well..

    my problem z dat i wana generate pulses with specific frequency... the code should take interruption from the user (keypad) so that if he/she presses pad1, frequency changes to 1 hz.. if he/she presses pad2, then frequency changes to 10 hz, 3 gives 50 hz, 4 gives 100 hz.... i need it as soon as possible... and thnx for your help and support
    Last edited by alabbadi; - 10th November 2007 at 16:05. Reason: spelling mistake

  2. #2
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,806


    Did you find this post helpful? Yes | No

    Default

    Since you posted on the Wish list, this could be a pious hope!

    Also don not expect some one to write your code and give it to your plate. We have bussiness to take care off!

    Try something and sure we will give a hand.

    Ioannis

  3. #3
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    what's a frequency.. it's just some hig and low pulse of a certain length.
    1. Now you should know how to calculate the frequency period? This gives you some info about how much time the pulse will be high, then low
    2. Easy to use Keypad routine, just plug it into your code and enjoy!

      Matrix Keypad routine - Read this
      http://www.picbasic.co.uk/forum/showthread.php?t=3250

      But download the latest version bellow
      http://www.picbasic.co.uk/forum/atta...2&d=1181850086
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  4. #4
    Join Date
    Nov 2007
    Posts
    4


    Did you find this post helpful? Yes | No

    Default

    here is my code:


    ===============================================
    Define LOADER_USED 1

    ' Define LCD connections
    Define LCD_DREG PORTD
    Define LCD_DBIT 4
    Define LCD_RSREG PORTE
    Define LCD_RSBIT 0
    Define LCD_EREG PORTE
    Define LCD_EBIT 1


    ' Define program variables
    col Var Byte ' Keypad column
    row Var Byte ' Keypad row
    key Var Byte ' Key value
    fre Var byte ' half pulse time
    LED0 var PORTD.0 ' Alias PORTD.0 to LED

    OPTION_REG = $7f ' Enable PORTB pullups
    'OPTION_REG.7 = 0 ' Enable PORTB pullups

    ADCON1 = 7 ' Make PORTA and PORTE digital
    Low PORTE.2 ' LCD R/W low (write)

    Pause 100 ' Wait for LCD to start

    Lcdout $fe, 1, "Choose Your Frequency" ' Display sign on message

    'On Interrupt Goto myint ' Define interrupt handler
    'INTCON = %10010000 ' Enable INTE interrupt

    loop1: Gosub getkey ' Get a key from the keypad

    'On Interrupt Goto myint ' Define interrupt handler
    'INTCON = 144 ' Enable INTE interrupt

    loop3: if key = 1 then
    Lcdout $fe, 1, "1 Hz"
    fre = 500
    gosub loop2
    endif

    loop4: if key = 2 then
    Lcdout $fe, 1, "10 Hz"
    fre = 50
    gosub loop2
    endif

    loop5: if key = 3 then
    Lcdout $fe, 1, "50 Hz"
    fre = 80
    gosub loop2
    endif

    loop6: if key = 4 then
    Lcdout $fe, 1, "100 Hz"
    fre = 40
    gosub loop2
    endif

    'disable interrupt

    loop2: High LED0 ' Turn on LED connected to PORTD.0
    Pause fre ' Delay for "fre" seconds

    lOW LED0
    Pause fre ' Delay for "fre" seconds

    'gosub getkey
    'goto loop1


    'if key = 1 then
    'goto loop3
    'endif

    'if key = 2 then
    'goto loop4
    'endif

    'if key = 3 then
    'goto loop5
    'endif

    'if key = 4 then
    'goto loop6
    'endif

    ;Disable interrupt ' No interrupts past this point
    'myint: 'gosub getkey
    'goto loop1
    'INTCON.1 = 0 ' Clear interrupt flag
    'Resume ' Return to main program
    'Enable interrupt

    goto loop2

    'goto loop1

    'enable interrupt

    Return ' Go back to loop and blink LED forever


    ' Subroutine to get a key from keypad
    getkey:
    Pause 500 ' Debounce

    getkeyu:
    ' Wait for all keys up
    PORTB = 0 ' All output pins low
    TRISB = $f0 ' Bottom 4 pins out, top 4 pins in
    If ((PORTB >> 4) != $f) Then getkeyu ' If any keys down, loop

    Pause 50 ' Debounce

    getkeyp:
    ' Wait for keypress
    For col = 0 To 3 ' 4 columns in keypad
    PORTB = 0 ' All output pins low
    TRISB = (dcd col) ^ $ff ' Set one column pin to output
    row = PORTB >> 4 ' Read row
    If row != $f Then gotkey ' If any keydown, exit
    Next col

    Goto getkeyp ' No keys down, go look again

    gotkey: ' Change row and column to key number 1 - 16

    key = (col * 4) + (ncd (row ^ $f))
    Return ' Subroutine over

    End
    =================================================


    1) the problem is that by using this code, generated pulses cud not change using the interrupt code.. which i cudnt fix!!!! this is where i need help...
    {at the begining, i need the code to check for the pressed keypad and loop as the corresponding frequency... then the code should check for any interruption from the user if he/she pressed any key.. if he pressed any other key, the frequency should change accordingly,,, if not it should cont looping to generate the previous frequency}


    2) another thing is that i need ur help in understanding the concept of working of the keypad connection diagram (when we press the keypad, does it give 1 or 0)

  5. #5
    Join Date
    Nov 2007
    Posts
    4


    Did you find this post helpful? Yes | No

    Default

    i jst wud like 2 add one more thing which is that im using PIC16F877A microcontroller with its "LABX1, learning board" which means that keypads r already there installed and ready to use...

  6. #6
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,806


    Did you find this post helpful? Yes | No

    Default

    I don't know about the LABX1 board, so cannot help you on that.

    About the other matter, as stated, and if I understood it correctly, you need to have a clean frequency at the output while checking the keyboard with PBP interrupts?

    I think it is not going to work as expected, since the PBP interrupts are slow and will introduce jitter at the output.

    I believe it would be easier to use just four inputs and 4 buttons and check these while you have the output High or low and you are waiting for the respective time to exprire.

    Like this:
    loop:
    High output
    gosub check_buttons
    pause xx msec (you have to find the best value here)
    low output
    pause yy msec (you have to find the best value here)
    goto loop

    check_buttons
    if but1=0 then
    xx=value1:yy=value1a
    return
    endif
    if but2=0 then
    xx=value2:yy=value2a
    return
    endif
    if but3=0 then
    xx=value3:yy=value3a
    return
    endif
    if but4=0 then
    xx=value4:yy=value4a
    return
    endif
    return

    Now you have to find by trial and error the most accurate values for the value1 through value4a

    P.S. Experienced programmers might laugh at the above example, but I think you have to start with something simple before jump into interrupts. If you really need interrupts, consider Darrel Taylors Instant Interrupts. The definite solution.

    Ioannis
    Last edited by Ioannis; - 17th November 2007 at 12:30.

  7. #7
    Join Date
    May 2004
    Location
    brighton
    Posts
    149


    Did you find this post helpful? Yes | No

    Default

    i totally agreed with u Ioannis

  8. #8
    Join Date
    May 2004
    Location
    brighton
    Posts
    149


    Did you find this post helpful? Yes | No

    Default

    1 hz.. if he/she presses pad2, then frequency changes to 10 hz, 3 gives 50 hz, 4 gives 100

    f=1/T so you can find T for each of your freqs
    that would then be pause xx etc

    Isaac

Similar Threads

  1. Generate AX. 25 Modem signals with a PIC.
    By Pic Toy in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 3rd January 2008, 13:31
  2. Count pulses between VARIABLE TIME
    By RodSTAR in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 15th October 2007, 12:44
  3. Timing input pulses and re-outputting them
    By jamie_s in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 28th February 2007, 01:50
  4. Timed pulses on 2 pins
    By Danie Joubert in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 15th March 2004, 07:38
  5. Counting pulses
    By srspinho in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 19th November 2003, 00:54

Members who have read this thread : 1

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