PDA

View Full Version : 16F628A ired with battery



Michael
- 5th March 2006, 18:34
I have a 16F628A ired xmtr/rcvr pair that works just fine on the breadboard, as long as I keep a steady 5volt on my xmtr.

I'm using a steady 5v from power supply on the rcvr and a seperate 5v battery on the xmtr.

I have 8 inputs on the xmtr PIC pulled to ground through 10k's and a logic high on the input(s) will give the same in my SEROUT data.

Now, like I say, if the xmtr is always tied to Vdd and I simply take an input high, than I see a coresponding LED light on the receiver's PORTB. BUT....when I take both the Vdd and the same input pin high together...the LED will latch on and stay on even after I've unpowered the PIC and input pin.
Of course, I'd like to "power up" the PIC when I use the transmitter as it will be battery operated.

I have the WDT and Brown out disabled on both PICs.

I'm puzzled because on my rcvr code I have.....

SERIN PORTA.0,T1200,50,NONE,[QUALA,QUALB],DAT

IF DAT.0 = 1 THEN
PORTB.0 = 1
ELSE
PORTB.0 = 0
ENDIF
(REPEATS FOR OTHER 7 BITS)

GOTO START

NONE:

DAT = 0
PORTB = 0
GOTO START

So, if there is no serial data (battery off on xmtr) then it will jump to NONE:
which should turn off PORTB.....right?

Or am I doing something wrong?

Like I say.....the LED will stay latched on.

THANKS VERY MUCH for your help.

penelopepug
- 6th March 2006, 14:01
Changing the state of a pin and powering up the pic at the same time can cause problems because the pic has not initialized. A better approach would be to put the pic to sleep indefinately and wake it up via an interupt on portb or a single portb.0 input. The pic will normally draw 2 to 8 uAMPs depending on the pic. This can represent years of battery life. You would have to disable the wathdog timer to have the pic sleep indefinately. If your going to wake the pic up with any button pressed, you could gang the buttons to portb.0 with diodes. Oh, one other important point; I'm not sure about the PIC628A but I think it will operate down to 3 volts, perhaps less. This is important because you can avoid the use of a power wasting voltage regulator. You'll never get down to super low power consumption with a regulator unless there is something I'm not aware of. Of course you have to have a transmitter that operates on 3 volts too. All of the above is precisely what I did when I recently built an RF remote control. The pic is operating but asleep until a button is pressed. When a button is pressed, it wakes up the pic, enables the RF transmitter and sends the key command. The key command is delayed by 15ms until the transmitter is keyed up and steady. Then if no buttons are pressed after a few seconds, it goes back to sleep. I'm no expert like so many on these forums so I invite other to jumps in please. Here is a snippet of my code for a PIC16F876;

'MP3 Transmitter
'Program for PIC16F876

'-----------------------------------------------------------------------------------------
Include "modedefs,bas"

@ DEVICE pic16F876, HS_OSC
' System Clock Options
@ DEVICE pic16F876, WDT_OFF 'essential to be off to sleep permanently
' Watchdog Timer
@ DEVICE pic16F876, PWRT_OFF
' Power-On Timer
@ DEVICE pic16F876, BOD_OFF
' Brown-Out Detect

ADCON1 = 7 'turn off analogs

'PIN DESIGNATIONS
Dataout var porta.0 'Serial Data Out
TXEnable var porta.1 'Enable Transmitter
'Spare var porta.2 '
'Spare var porta.3 '
'Spare var porta.4 '
'Spare var porta.5 '
'Interuptpin var portb.0 'Interupt port where all buttons connect with diodes.
Prevbut var portb.1 'Play previous song
Playbut var portb.2 'Sort Playlist by Title
Upbut var portb.3 'Scroll up
Shufflebut var portb.4 'Play Random Song Next
Reversebut var portb.5 'Reverse Playlist
Randbut var portb.6 'Randomize Playlist
Titlebut var portb.7 'Sort Playlist by Title
'Spare var portc.0 '
'Spare var portc.1 '
Downbut var portc.2 'Scroll Down (need resistor here)
Volupbut var portc.3 'Increase Volume (need resistor here)
Voldnbut var portc.4 'Decrease Volume (need resistor here)
Qbut var portc.5 'Queue song (need resistor here)
Pausebut var portc.6 'Pause button (need resistor here)
Nextbut var portc.7 'Play next song (need resistor here)
'------------------------------------------------------------------------------------------

'SET VARIABLES
Timer var Word
Timer = 0

OPTION_REG.7 = 0 ' Enable PORTB pull-ups
OPTION_REG.6 = 0 ' Set RB.0 Interupt to detect falling edge on RB.0

TrisA = %11100
Trisb = %11111111
Trisc = %11111111

Scan: INTCON.4 = 0 'Disable interupt here
Timer = 0
Active: For Timer = 0 to 4000
Low TXEnable
Low Dataout
If Upbut = 0 then Upkey
If Downbut = 0 then Downkey
If Volupbut = 0 then Volupkey
If Voldnbut = 0 then Voldnkey
If Randbut = 0 then Randkey
If Titlebut = 0 then Titlekey
If Reversebut = 0 then Reversekey
If Shufflebut = 0 then Shufflekey
If Playbut = 0 then Playkey
If Prevbut = 0 then Prevkey
If Nextbut = 0 then Nextkey
If Pausebut = 0 then Pausekey
If Qbut = 0 then Qkey
pause 1 'Goes to sleep after about 5 seconds of inactivity
Next Timer
PORTA = 0
PORTB = 0 'turn off all outputs
PORTC = 0
INTCON.1 = 0
Goto LowPwr

LowPwr: INTCON.4 = 1 'Enable PORTB.0 Interupt
@ Sleep 'Go to sleep permanently until change to PORTB.0 Pin (must have Watchdog off)
Goto Scan 'wake up by an interupt (any button), go back to work

Titlekey:High TXEnable
Pause 15
Serout Dataout, N1200, ["A","Z",1]
pause 12
goto Scan

Michael
- 6th March 2006, 16:38
Thanks very much....I'll try that on my xmtr end of things. I didn't realize the pic drew such little current in the sleep state.

That sounds like it may well solve the problem although searching this forum I also ran across some posts on SERIN and TIMEOUT.

I guess the TIMEOUT will react to ANY change in pin state, noise or otherwise? So it's a good idea to use a pulldown on the SERIN pin? I don't see anything but a steady low when my panasonic ired receiver isn't receiving.....no noise, so I didn't bother.

I was wondering if, in my code, I'm using TIMEOUT correctly and I'd like to understand it better.


SERIN PORTA.0,T1200,50,NONE,[QUALA,QUALB],DAT

(1) Does it then wait 50ms wait for a pin state change and go to NONE

or

(2) Does it wait 50ms for a pin state change, look for the qualifiers and then go to NONE? (if the qualifiers aren't there).

Or is all this about a toggle on the pin nonsense and it looks for legit RS232?

Thanks again for the help.

penelopepug
- 7th March 2006, 01:18
Your serin pin would be connected to the demodulated output pin of your receiver, so a resistor on the serin pin would not accomplish anything. The thing is, with your transmitter not keyed, the receiver will still pick up spurious RF which will be ported out of the demodulated output pin. Then, your serin will ultimately interpret this noisy data as a valid command unless you put qualifiers in your data stream. I was getting invalid commands from noise until I added the second qualifier. That's why in my code I have "A" and "Z" as the qualifiers and the number is the command code. As for your serin TIMEOUT question, yes, if the pin does not change state it times out and goes to NONE. My receiver is not battery operated so I do not have anything in place to put it to sleep and wake it up such as a serial interupt. There is likely better ways to qualify the data and I would appreciate it if some people would post some further information. Here is a part of my RX code for you to see. Again, I am not an expert but this works perfectly for my application;

'Winamp Receiver Controller. Feeds button switches to KeyWiz keyboard controller via RF
'link from remote control
'Revised January 15, 2006
'Transmitter Program is winamptx.txt
'-----------------------------------------------------------------------------------------
Include "modedefs,bas"

@ DEVICE pic16F876, HS_OSC
' System Clock Options
@ DEVICE pic16F876, WDT_ON
' Watchdog Timer
@ DEVICE pic16F876, PWRT_ON
' Power-On Timer
@ DEVICE pic16F876, BOD_ON
' Brown-Out Detect

ADCON1 = 7 'turn off analogues

'PIN DESIGNATIONS
Datain var porta.0 'Data in from RF Module
Testled var porta.1 'I'm Alive!
'Spare var porta.2 '
'Spare var porta.3 '
'Spare var porta.4 '
'Spare var porta.5 '
Homebut var portb.0 'Home button to move curser to first track
Zbut var portb.1 'Z
Enterbut var portb.2 'Enter
Upbut var portb.3 'Up Arrow
Sbut var portb.4 'S
Rbut var portb.5 'R (Need CTRL + R for Reverse) and (CTRL + SHIFT + R for Randomize)
Endbut var portb.6 'End Button to move curser to end button
Onebut var portb.7 '(Need CTRL + SHIFT + 1)for Sort by Title
CTRLbut var portc.0 'CTRL
SHIFTbut var portc.1 'S
Downbut var portc.2 'Down Arrow
Altbut var portc.3 'Alt
'Spare var portc.4 'Spare
Qbut var portc.5 'Q
Cbut var portc.6 'C
Bbut var portc.7 'B
'------------------------------------------------------------------

'------------------------------------------------------------------------------------------
B0 var byte
B0 = 0
B3 var bit
B3 = 0
'------------------------------------------------------------------------------------------

'SET VARIABLES
TrisA = %11101
Trisb = %11111111
Trisc = %11111111

High PortA.2:High PortA.3:High PortA.4:High PortA.5
High PortB
High PortC

'I'm Alive!
High Testled
pause 100
Low Testled
pause 100
High Testled
pause 100
Low Testled
pause 100
High Testled
pause 100
Low Testled
pause 100


Scan: Serin Datain, N1200,["A","Z"],B0 'wait for 2 synchronizing qualifiers before loading into B0
If B0 = 5 Then Scrollup
If B0 = 13 Then Scrolldown
If B0 = 11 Then Volup
If B0 = 12 Then Voldown
If B0 = 1 Then Sortlst
If B0 = 2 Then Randomize
If B0 = 3 Then HomeEnd
If B0 = 4 Then Shuffle
If B0 = 6 Then Enterplay
If B0 = 7 Then PrevTrack
If B0 = 8 Then NextTrack
If B0 = 9 Then Pauseplay
If B0 = 10 Then Queue
goto Scan

Sortlst: Low CTRLbut:Low SHIFTbut
Pause 30
Low Onebut
Pause 50
high CTRLbut:High SHIFTBut:High Onebut
pause 200
goto Scan

Randomize: Low CTRLbut:Low SHIFTbut
Pause 30
Low Rbut
Pause 50
high CTRLbut:High SHIFTBut:High Rbut
pause 200
goto Scan

Michael
- 7th March 2006, 12:34
Looks like your building a winamp interface...."Keywiz"?...I'll have to look into that....sounds interesting.

So, if your getting noise on the infrared receiver output, it really never goes through the timeout?

I think what I may need to add in my code is "IF DAT = 0" then GOTO START and keep it in that loop.

DAT= 0

START:
SERIN BLAH BLAH [QUALA,QUALB],DAT

IF DAT = 0 THEN START


I know the 16F628a will operate on 3v minimum but I imagine 4 aaa cells would be safer.....wish there was a button cell that was readily available, inexpensive and do the job....that would be nice.

penelopepug
- 7th March 2006, 13:56
Hi again. I forgot that you are using IR not RF. So I assume you are genereating a 38khz carrier. I'm not actually sure if IR receivers are sussceptible to IR noise because the requirement for a 38khz carrier should elliminate most noise issues if not all, I would guess. I would just put a logic probe on your serin pin or scope it. Sorry for the RF information. Here is a link to an Energizer (cylindrical) battery performance information, if you plan to use alkalines. http://data.energizer.com/PDFs/alkaline_appman.pdf. There's a lot more out there for other battery types if you search for "battery discharge curves" for example.

I found that my 16F876 operated down to about 2.4 volts with the brownout detect disabled. As such I am running my transmitter on 2 AAs. Of course there is low voltage versions of most PICs including the 16F628A as I recall.