Continue to Site

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.

  • 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.

PIC and sleep command.

Status
Not open for further replies.
mramos1 said:
WOW.. That is cool.. So they set high on one termistor, ground junction, and count. Then go high on POT, ground junction and count? Subtracting thermistor from POT and that is the value?

I am lost on it, I see the logic with the two to compensate the for battery getting lower, just not the sequence to do it.

Check the source, it's on the EPE site and is called 'Freezer', it's in the PIC source code listing.

Essentially though you make the resistor you're NOT using an input, make the other an output and low, and wait to make sure the cap is discharged - then simply take the pin high and count until the input goes high as well. Do the same with the second output pin, and you have two readings you can compare, you even have an adjustable pot you can alter with a screwdriver!.

It's so delightfuly simple!.

My mod, which they published, was simply to connect the sounder across two I/O pins and drive it bridged, LOT'S louder, with no extra components! - don't you just love a mod like that?.
 
Nigel Goodwin said:
Check the source, it's on the EPE site and is called 'Freezer', it's in the PIC source code listing.

Essentially though you make the resistor you're NOT using an input, make the other an output and low, and wait to make sure the cap is discharged - then simply take the pin high and count until the input goes high as well. Do the same with the second output pin, and you have two readings you can compare, you even have an adjustable pot you can alter with a screwdriver!.

It's so delightfuly simple!.

My mod, which they published, was simply to connect the sounder across two I/O pins and drive it bridged, LOT'S louder, with no extra components! - don't you just love a mod like that?.

I will check it out (the source). Yea, the sounder mod you showed me awhile ago when I had to get a plus and minus from two pic pins.. hehehe.. And it worked.

I will try that configuration tonight with the .2uF I have and see how it counts at 32Khz. Maybe I will mod the buzzer too. hehehe.. And if I flip the all to inputs after measuring and pause 30 seconds (not sleep) that would help the battery as well. Or would I flip to to output and put a low on them.
 
I wired the new version, but went back to the older version, still at a loss as to why it did not work.

Buzzer works. Beeps every 30 seconds, so the uC is working fine at 32Khz...

I hooked the multimeter (slow) and I can see the bcf LDR drop the LDR/CAP junction on the darn meter, and the meter respond back to a high, and the buzzer is beeping before it is back to a high.. This is killing me. I know the pin is going low, but my software reads 255 1's..

part of code not making since.. It is like TRIS is not flipping GPIO.0 back to input and it is always reading a high...

Code:
        bcf     LDR             ; ground out LDR/cap junction
		movlw	d'255'			; for 255 msec 
		call	mdelay
        movlw   b'00000001'     ; flip LDR for input  (HERE)
        tris    GPIO            ;
        clrf    count           ; zero counters, count = number of highs from RC, lcount is passes to check
		movlw	d'255'			;do 255 checks
		movwf	lcount
loop
        btfsc   LDR             ; if bit is high  <-- skip if clear 0???
        incf    count,f         ; increment count
        decfsz  lcount,f        ; decrement loop counter
        goto    loop            ; if loop counter <> 0 loop    

        btfsc   count,7         ; test bit 7 if more than 128 highs
        goto    buzz            ; if true go buzz
nap
 
Last edited:
Nigel Goodwin said:
It looks like you're not selecting the correct bank for the TRIS register?.

There is no TRIS register in a 509. You have to use the TRIS instruction.

Mike.
 
I will drag out the scope tonight. The circuit works with the atmel, so I really wanted to figure out what is wrong.

The code looks fine? I added HERE and <--- where I might have a problem.

My reads appears to always be high and I see the pin is low. Also pulled out another F509 to make sure I did not break the chip. Same problem.
 
Could I suggest a slight mod to your code which may throw some light as to the problem. aswell as a delay after writing zero to GPIO.0, wait for it to become zero and then have a delay.

I.E.
Code:
		bcf     LDR             ; ground out LDR/cap junction
WaitLDR		btfsc	LDR
		goto	WaitLDR
		movlw	d'255'			; for 255 msec 
		call	mdelay
		movlw   b'00000001'     ; flip LDR for input  (HERE)
		tris    GPIO            ;

This will prove that the pic is at least able to discharge the cap and that the resistive value of the preset and LDR conduct less than 20mA when the pin is low.

Mike.
 
Pommie said:
I.E.
Code:
		bcf     LDR             ; ground out LDR/cap junction
WaitLDR		btfsc	LDR
		goto	WaitLDR
		movlw	d'255'			; for 255 msec 
		call	mdelay
		movlw   b'00000001'     ; flip LDR for input  (HERE)
		tris    GPIO            ;
Will try that. But if I bcf LDR, I would need to TRIS LDR back to an input before the test right?
 
mramos1 said:
Will try that. But if I bcf LDR, I would need to TRIS LDR back to an input before the test right?

No, no need, when you read a pin that is set to output it always reads the level on the pin and not the latch. You do of course have to set it to input after the delay to allow the cap to charge.

Mike.
 
OK.. Got out the scope since I did not hear comments on TRIS from Pommies good idea "on see if it is going low at all" (my thought was it was not going back to input for some reason).. And I still think I have to TRIS it back to input "1" to make Pommie's check work, if not that is a nice feature but not tring it tonight.. I am stamping this one DONE. It WORKS GREAT :)

** EDIT: Pommies code would have worked, read his later post. Nice feature of the PIC **

Anyway, what the multimeter said was confirmed. I said, OK bigger CAP and more discharge time. It was a tad better. Dropped a 50K POT in with the LDR (yea I took that out 'DUH' at some point) and opened it to max.. Long RC, so I turned until I got my beep (and then shortened my charge time to save battery)..

Thanks for the help.

Possible problem I see, is a lot of good analog guys avoid the uC forum, they see all the chip numbers in the topics and go not a chip I have ever heard of (and the uC guys go, what does that one have, let me go look), and also the software to code and burn them..

Anyway, my thought is they would have went, a 32Khz OSC and the RC you have (let me get my calculator and confirm it; though they already know) each cycle taking x amount of time, it is back to a high before you can read it.

I was missing the RC window.

BUT, I read the datasheet over and over, know there is a pin you have to set in options to use it as its default is wrong to me (on a pin that I was not using and will avoid for this chip), and I learns much more.

I guess this is what makes it fun.

Next project will be a 16F628a.. Yes Nigel, I bought plenty of them and it will be in MPLABS, I like it. Going with the low speed internal OSC and ASM.

All that money in compilers, I should have listened, I could have an ICD2 and $150 in my pocket for something....
 
Last edited:
Pommie said:
No, no need, when you read a pin that is set to output it always reads the level on the pin and not the latch. You do of course have to set it to input after the delay to allow the cap to charge.

Mike.

I posted at the same time you did (close anyway)... So ingore that part of mine.

No kidding. I will remember that.. Crap.. Some times you read the sheets and go, I got it. And just miss things.

That is a nice feature for the RC stuff..
 
Pommie said:
twice.

Mike.

Too funny.. Hey, it works. And I learned, so it was all good to me.. Thanks for the HELP... Lot of sharp guys here..

What time is it there.. I am in the States EST.. 9:24PM here.. Just wonder how many hours you Ausie guys are away from me.. hahahaha..
 
It's 11:30 AM here, just about to go put up some fencing in the paddock. Been waiting for it to warm up as we're in winter.

Mike.
 
Pommie said:
It's 11:30 AM here, just about to go put up some fencing in the paddock. Been waiting for it to warm up as we're in winter.

Mike.

It is backwards from here, a good friend is there, came over here for years and went back (maybe he is tring to tell me something).. Getting ready to wind down, not up our day.. Summer, 10PM at night and hurricane season here.. And HOT at heck..

Thanks for the help again.. And what the heck is a paddock (hehehe)?
 
Status
Not open for further replies.

Latest threads

Back
Top