Brian's Timer Changes

Brian

Inactive
Joined
Jul 30, 2001
Messages
1,194
Reaction score
0
I made a technical change to the timer's for the future.
ArkansasElkHunter put me on this problem and until now it has kicked my Butt.  Finally, I got it to work properly.

He had asked if I could make it possible to interrupt the chip with the buttons(count,delay) even if the PIC was in the delay between picture modes.
Well, I finally got it work right.  Now if you take a picture with the timer and it goes into the delay between pictures you can push the count or delay button and interrupt the delay without affecting the count or anything else.  This interrupt is only for the count and delay button and not the PIR.  So if you have triggered the PIC and it took a picture and went into the delay between pictures the PIR cannot trigger the PIC again until it times out but the push of one of the buttons will end the delay and show you the appropriate option depending on which button you pushed.
Sounds like a simple thing huh.  NOT.
Its one of the harder things I have tackled so far.  Just thought I would mention the change for the future.  If you get a chip from me in the future they will have this option.  It is really handy while testing the chip.

:rofl
 



ArkansasElkHunter

Well-known member
Joined
Jan 19, 2002
Messages
1,748
Reaction score
0
Good job Brian,

I don't have any trouble, but others seem to.  they thinh there is something wrong because the led won't blink when they push the button.   I keep telling them to sneak up on it and be still.  

The 60 seconds warm up is like a kid waiting on Christmas.  Seems like it takes forever.  Does this mean you can change modes during warm up or it that just for the Day Night options.
 

Brian

Inactive
Joined
Jul 30, 2001
Messages
1,194
Reaction score
0
ArkansasElkHunter,

That is just for the day/night option.  The first delay is still unable to do anything for the delay or count.
 

jayber

Well-known member
Joined
Aug 20, 2002
Messages
2,010
Reaction score
0
Do you take chip trade-in's???  HeHe  Maybe I'll wait to get my second digital working with your 'new' developments before updating the first.  :smile-big-blue:  Excellent job again Brian!!  
 

Archilochus

Well-known member
Joined
Mar 27, 2001
Messages
1,285
Reaction score
0
ArrrgggGGGhh.... I've been hacking on the VERY same problem... I was going to send you a mail asking how you get around it :)

I'm working something like this:

   ;delay routine
   ;
FOR CounterA = 0 TO Delay        ;Delay value read from EEPROM - set during "setup" routine
   SLEEP 10
   GoSub btnChk                       ;Go to subroutine that checks button status every
NEXT CounterA                          ;10 seconds with sleep in between

Problem is it can take up to 10 seconds of keeping the button pressed to "break" the loop.
Guess it could have a shorter SLEEP cycle.

Archilochus
 

Brian

Inactive
Joined
Jul 30, 2001
Messages
1,194
Reaction score
0
Arch,

Don't check the button status all the time.

Setup the interrrupt routine with the ON INTERRUPT command and let the PIC wake itself from the sleep if a button is pushed.  
Then you can set your loop in the main body to wake after the sleep command and refresh the camera.

Defines go here.

On interrupt goto myint

Loop:
          sleep 420       ' this is the 7 minute refresh loop minimizing power consumption.
          refresh high
          pause 500
          refresh low
          goto loop

myint:
        if intcon.0 = 1 then goto Label1  'means a pushbutton caused the interrupt and not the PIR.
        shutter high
        refresh high
        pause 4000
        shutter low
         refresh low
label1:INTCON = $80
         resume start

start:
      Here is where you deal with the pushbuttons.
      By controlling the INTCON registar you can turn the periphial pins and the interrupt pin on and off individually.  This was what was giving me fits for awhile.

Hope this helps.
 

Tinhorn

Well-known member
Joined
Mar 13, 2001
Messages
3,516
Reaction score
0
This won't work in the case you described Arch but there is a way to break out of a For/Next Loop, set the value for "A" to "Delay" within the For/Next Loop,  it thinks it has made the count and will exit the loop

At least in most BASIC's it will

For A = 1 to Delay
      gosub xxxx
      if c = 5 then A = Delay
next

Tinhorn
 

Archilochus

Well-known member
Joined
Mar 27, 2001
Messages
1,285
Reaction score
0
Thanks Brian, Tinhorn,
Trying to learn this PIC BASIC programming is almost harder than learnin Spanish was (the small bit I did manage to learn has mostly been forgotten :-(

Brian...That does look like a much better way to handle the interrupts!  Have to go back and start re-working my attempts.

Tinhorn... That's a nice way of breaking a FOR..NEXT loop - a self-modifying loop! - would have taken me a looong time to figure that trick out on my own!  I think the only reason the bit of code above worked at all is because the subroutine RETURNed within the FOR..NEXT loop, which then finished normally.  Or at least it seemed to work OK when I programmed a test version into a PIC.

Thanks again,
Arch
 

Tinhorn

Well-known member
Joined
Mar 13, 2001
Messages
3,516
Reaction score
0
Arch,

You're right, the Gosub will <return> there, where it came from.  

Altho a subroutine could have some code that makes it "NOT" RETURN there, that's bad practice and leaves the "Stack" dirty, which can come back and bite you.

I forgot to mention that some lanquages have an "Exit For" command so you wouldn't need to set the counter as I mentioned above.

Tinhorn
 

Brian

Inactive
Joined
Jul 30, 2001
Messages
1,194
Reaction score
0
Arch,

Have you got the interrupts where they work yet.  Meaning the interrupt pin and the periphial(spelling) pins.

You need to know how to interrupt the chip with the interrupt pin(usually portb.0) and the other port B pins which are periphial pins.

This is critical in minimizing the current drain all the time and getting the functionality of the chip.  This is usually configured with the INTCON register.

THe OPTION register controls the other functions like edge trigger and so on.  I suggest you become very famaliar with these registers because they setup the whole chip for what you are trying to do.  ONce you master these then you are on your way.

The rest of the programming follows the conventional techinques like Tinhorn explained with the loops and the stack.

PBP handles the stack for you so this is not as much of a problem as with other languages.

Try a simple interrupt routine like I listed above and build from there.  My entire program revolves around this routine.

Also, use sleep whenever possible to save power.  Any other time the PIC will draw 1mA to operate.

Let me know how it goes and if I can help more.
 

Archilochus

Well-known member
Joined
Mar 27, 2001
Messages
1,285
Reaction score
0
Hi Brian,
I did have success with a simple test program - it set an single interrupt on PortB0, went to sleep with the 7 minute refresh cycle, wake up on falling edge of PortB0, and conditionally take a pic based on "setup" and "day/night" inputs.

Things got hairy when I started trying to add in all the other fun stuff - pushbutton setup for various options, security code entry, dual picture mode, frame count shutdown, event count/display.

The strange thing is most of the routines worked fine when I ran them by themselves just to test each idea out.  But when I stick them together I get all sorts of odd results.  I guess what Tinhorn mentioned about one section of code being incompatible with another section could be the problem.

Got so many questions I could keep ya busy for a week!!  I try to make an attempt at hacking my way through a problem before callin for help.  Waiting for the real 'emergencies' ;-)
>>>>
Ain't it odd how ya just can't be satisfied with the "basic" functions for the cam??  There's more program memory -  bet I can fit one more option in there!!!  Can't figure how you sqeeze all the functions into one of those 8 pin chips...

Arch
 

Hill Hopper

Banned
Joined
Mar 10, 2002
Messages
1,570
Reaction score
0
You guys sound like you are having too much fun. Thats the next project I want to learn is programming PICs. I used to do one hell of a lot of programming back when 64k was a TON of memory, but havent done much in the last 15 years or so. PICs fasinate me.

Butch
 

Archilochus

Well-known member
Joined
Mar 27, 2001
Messages
1,285
Reaction score
0
Hop right in HH! You can get all kinds of free software from Microchip.  Lots of easy & free programmers to build on the 'net.  With your programming experience, you'll no doubt have an easier time of it than I'm having!

The possibilities with these PICs / AVRs /etc seem almost endless.....

Arch
 


Top Bottom