1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

Junebug help??

Discussion in 'Microcontrollers' started by MrDEB, Apr 8, 2009.

  1. MrDEB

    MrDEB Active Member

    Joined:
    Apr 16, 2007
    Messages:
    4,364
    Likes:
    22
    It is a great learning tool

    In the short time I have had the unit it has worked great. Just wish the directions on usage were a little bit more descriptive.
    I learned that you turn off all the di switches to program an in circuit PIC
    I need to use it more often. Just as soon as I finish up building and testing my CRITTER RIDDER proto type.
    Tested it today, seems to work.Want more testing.
    found several small problems. Had to change a line of code, found several questionable solder joints, need to make some small revisions to pc board lay out.
     
  2. mvs sarma

    mvs sarma Well-Known Member

    Joined:
    Oct 29, 2006
    Messages:
    3,512
    Likes:
    76
    Location:
    Hyderabad, India.
    CONGRATULATIONS. Your long correspondance served you well. Nice to note.
    Perhaps it may be time to close this post and start fresh one for newer designs.
     
  3. MrDEB

    MrDEB Active Member

    Joined:
    Apr 16, 2007
    Messages:
    4,364
    Likes:
    22
    I am contemplating adding a deer counter

    to count how many times the PIR is triggered.
    but a method to proceed.
    assuming I can use the 18F1320 memory? or add additional memory?? with a hearing aid battery as backup power to keep the memory alive??
    any thoughts
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. 3v0

    3v0 Coop Build Coordinator Forum Supporter

    Joined:
    Jul 14, 2006
    Messages:
    9,404
    Likes:
    227
    Location:
    OKLAHOMA USA

    I assume the processor is either sleeping or running at a low clock rate when not generating sounds. No need for external memory or batteries. Normal RAM will not be lost unless the batteries go dead.

    Set a counter to zero on startup and bump it once each time the PIR is triggered. Have the user press a switch which will have the uC blink out a code to indicate the count.

    If for some reason you want to keep the value when the power is gone store it to EEPROM.

    ================= but ===================

    This is starting to look like feature creep. I suggest you focus on getting the unit into the hands of your customers.


     
  6. MrDEB

    MrDEB Active Member

    Joined:
    Apr 16, 2007
    Messages:
    4,364
    Likes:
    22
    PIR is triggering in daylight

    indoors the unit will shut off but outside it keeps triggering.
    going to add a CDS cell bu for right now I am going to insert some code to trigger the unit every 15-20 minutes. Just for test purposes until I get the PIR working right.
    now for code. Will research on swordfish but any help would be appreciated.
    looking at a foot step detection using homemade geophone
    Circuit - Human Traffic Footstep Detecto - Circuits designed by David A. Johnson, P.E.
    Circuit - Earthquake Alarm Hobby Circuit
     
  7. MrDEB

    MrDEB Active Member

    Joined:
    Apr 16, 2007
    Messages:
    4,364
    Likes:
    22
    is there a better way to time event?

    working with a code snippet on Junebug.
    GOAL = to insert a timed event (take pin 9 RB1/INT1) LOW FOR A FRACTION OF A SECOND TO TRIGGER THE OUTPUT ON PIN 18(RB3/CCP1)this simulate the PIR until I can get the unit to work in daylight. TESTING effectiveness of unit in relation to repell deer from ones garden.
    using Junebug to test code by turning on one LED(porta.0) for 20minutes then turning off for 10ms.
    present code is LED on for 40 seconds then off for 10ms(just guessed on the 40 seconds)
    expanding the 40seconds on to 20 minutes on (no real accuracy needed, just about 15-20 minutes between events(PIR simulation)
    QUESTION = a more efficient method to time this sequence?
    Code (text):

    Device = 18f1320
    Clock = 8
    Config OSC = INTIO2, WDT = OFF, LVP = OFF
    OSCCON = $62
    TRISA=%10111110         //A0 & 6 output
    PORTA=1
    While (true)
        Toggle(PORTA.0)
        DelayMS(100)
        toggle(porta.0)
        delayms(20000)
    Wend
    End
     
     
  8. MrDEB

    MrDEB Active Member

    Joined:
    Apr 16, 2007
    Messages:
    4,364
    Likes:
    22
    milli second math?

    am I assuming correctly that 1 ms = 1/1000 of a second
    in my code snippet I have 20,000ms equals about 40 seconds
    so if I want 20 minutes then 600,000ms = 20 minutes?
    OR
    is there a more efficient method of deriving at 20 minute delays?
    after I get this snippet into my PIC for real life testing I plan on adding a cds to control the unit in daylight (triggers every 20 minutes) then at night switch to the PIR.
    this is my next code endeavor but for now going with every 15-20 minutes.
     
  9. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,808
    Likes:
    135
    Location:
    morristown,tn
  10. MrDEB

    MrDEB Active Member

    Joined:
    Apr 16, 2007
    Messages:
    4,364
    Likes:
    22
    QUESTION why is timer better?

    more efficient or just more accurate?
    I really could care less about the accuracy.
    Perhaps the PIC would get "lost" with say a 600,000 ms delay??
    will take a closer look at the code snippet but it looks long
     
  11. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,808
    Likes:
    135
    Location:
    morristown,tn
    That's not it your delay will set and count for 20 min. And that's all it will be doing till it's done. Timers are better for that. You don't have to use all that code It just shows you how it works. Set up the timer. That's the part you need .
     
  12. Sceadwian

    Sceadwian Banned

    Joined:
    Oct 27, 2006
    Messages:
    14,047
    Likes:
    141
    Location:
    Rochester, US
    You'll have to shield it. PIR's don't like direct sunlight, CDS cell isn't going to help with motion sensing.
     
  13. MrDEB

    MrDEB Active Member

    Joined:
    Apr 16, 2007
    Messages:
    4,364
    Likes:
    22
    if I shield the PIR then it won't detect

    my new plan is to set up a timer that triggers the unit(PIC) every 15-20 minutes then have the cds or photo transistor enable the PIR when it gets dark out side.
    posted a short snippet of code but be80be suggests setting up a timer instead of a delay.
    trying to figure out the timer?
    do I just set up an interrupt , set up a TM0 on RB2/INT2 (RB0/INT0=dip switch output and RB1/INT1=PIR input) so RB2/INT2 (pin 17 on the 18F1320)is only int pin left?
    a timer is the better choice over a delay? I assume.
    going to play with Junebug to try and get some insight??
     
  14. Sceadwian

    Sceadwian Banned

    Joined:
    Oct 27, 2006
    Messages:
    14,047
    Likes:
    141
    Location:
    Rochester, US
    Shield the PIR from the sun, not from the view.. a simple curved plate over the very top of the sensor. It'll still detect leg motion, and won't go off for birds.
     
  15. MrDEB

    MrDEB Active Member

    Joined:
    Apr 16, 2007
    Messages:
    4,364
    Likes:
    22
    I have the top shielded

    Are there different PIRs to work in sunlight?
    for now I plan on just instituting a 15-20 minute timer for daylight.
    I contemplated a DIY geophone. not sure if it would pick up a deers footsteps.
     
  16. MrDEB

    MrDEB Active Member

    Joined:
    Apr 16, 2007
    Messages:
    4,364
    Likes:
    22
    getting lost fast

    just want to add a 20 minute timer Is this method workable?efficient??
    the red are the additions to existing code.
    Code (text):

    [COLOR="Red"]PORTB.1=0[/COLOR]//triggers unit to sound
    If PORTB.1=0 Then //if button 1 pressed add PIR=1 here pin 9
    For i = 1 To 200 //play 20 tones
        Tone=Rand(5) //each tone is random frequency
    DelayMS(Speed) //and for 1.00 seconds
    Next //end for loop
    [COLOR="Red"]TOGGLE PORTB.1
    delayms(600000)//about 20 minutes[/COLOR]
    Else //otherwise
         Tone=5 //silence
         i=Rand(255) //make rand more random
    EndIf //end if condition
    Wend //end of while loop
     
    this is a temp for testing. want to have 20 minute delays only in daylight as PIR dosn't work in daylight.
    My plan is to use a photo transistor in the PIR section to disable the PIR durring daylight.circuit board needs to be redesigned.
    PIR to be enabled at night. until then I just want to cycle the unit on every 20 minutes.
     
  17. Sceadwian

    Sceadwian Banned

    Joined:
    Oct 27, 2006
    Messages:
    14,047
    Likes:
    141
    Location:
    Rochester, US
    No, delayms won't work on long delays like that, exactly how long you can delay with delayms depends on your clock speed and the compiler you're using, you'll need to do a custom loop or setup a timer with several incremental registers.
     
  18. MrDEB

    MrDEB Active Member

    Joined:
    Apr 16, 2007
    Messages:
    4,364
    Likes:
    22
    still trying to figure out basic

    what is %10111111 am assuming it points to certain regesters?
    using tris = makes port an output?
    trying to get a 20 minute loop created but keep getting errors.
    using Junebug leds to test but will insert into my critter ridder code after getting a loop set up.
    Code (text):

    Device = 18f1320
    Clock = 8
    Config OSC = INTIO2, WDT = OFF, LVP = OFF
    OSCCON = $62
    TRISA=%10111110         //A0 & 6 output
     dim ctr as byte
    PORTA.0=1
    ctr=1

    While (true)
        Toggle(PORTA.0)
        ctr=ctr+1 // want to start a loop that
        //counts for 20 miniutes
       
        if ctr <100 then false
       
       
    Wend
    End
     
     
  19. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,808
    Likes:
    135
    Location:
    morristown,tn
    It set's what pins on porta are input or output
     
  20. MrDEB

    MrDEB Active Member

    Joined:
    Apr 16, 2007
    Messages:
    4,364
    Likes:
    22
    where to find more info?

    like what the numbers refer to
    I started changing the numbers and see the results.
    somehow I got on the Junebug led 1(A0/A6) to flash then led7(A0/A7) then led led 4 & 5(A7/A6 & A7/A0) came on simultaneously.
    tried to figure how but ??
    any clue about building a loop that will count for 20 miniutes.
    looked at the timer code snippets but ??
    I need to find a book on this basic swordfish or a book that will help guide me.
    otherwise I am just taking code and fiddeling with it and hoping I stumble onto something.
     
  21. 3v0

    3v0 Coop Build Coordinator Forum Supporter

    Joined:
    Jul 14, 2006
    Messages:
    9,404
    Likes:
    227
    Location:
    OKLAHOMA USA
    The junebug LEDs are charlieplexed.

    Three IO lines (RA0,RA6.RA7) are used to turn on six leds.

    To turn on any given LED you make one of the three lines an input. With the remaining two lines you can turn on one LED by making one line HI and the other LOW. You can turn on a second LED by making the HI line LOW and the LOW line HI.

    If you look at the schematic in the junebug assembly instructions you can see why. JPUG #1 covers charlieplexing on the junebug in great detail. Maybe too deep for where you are at. Don't know.
     

Share This Page