16F628A Serin timeout and Timer1


Closed Thread
Results 1 to 6 of 6
  1. #1
    Rubicon's Avatar
    Rubicon Guest

    Default 16F628A Serin timeout and Timer1

    Hello,

    I'm hoping someone can point me in the right direction here.

    PIC16F628A
    4MHz crystal
    Battery powered

    At the moment I have a program that basically naps most of the time over approx 1.5 seconds then awakens to power a receiver to check RB0 for a qualifier byte and match the following byte against a constant. Every cycle it increments a word size counter that in turn increments another byte size counter to exend the overall time-count to three days. Every so many cycles it also checks the PIC battery. After three days the program shuts-down. This seemed O.K. but with a timeout on the Serin as long as the receivers picking something up either modulated or random noise the timeout doesn't expire and the count goes out the door. The Serin timeout not timing out isn't an overly bad thing in that the receiver PIC has to get in sync with the transmitters signal but a constant source of random noise could keep it forever active.

    I want to have the WDT on for the Nap command as it's battery powered so after fumbling through the datasheet and application notes my confused mind asks for help on the timers.

    I don't really know what to do to ensure an accurate and by accurate I mean a +- 1 minute three day overall time count with the Serin timeout but as I type this I can see from an App-note that I could keep the WDT on with Timer1 in Asynchronous Counter Mode and using an external 32.768 oscillator (prescale of 2 for 4 seconds) have an over-flow of the TMR1 register cause an Overflow Interrupt and an interrupt service routine can make sure to turn off power to the receiver (if it's still on from the failed Serin timeout) and increment the counters for the three day overall timeout and battery check.

    Does this sound about right? If not what do you suggest? I know it's certainly easier for me to type out than to do as I haven't had to do anything like it before. Any pointers in the right direction greatly appreciated as it makes searching the archive easier when you know what to look for.

    Regards,

    Andrew.

  2. #2
    Join Date
    Dec 2003
    Location
    Wichita KS
    Posts
    511


    Did you find this post helpful? Yes | No

    Default

    Hello Andrew,

    I am not sure if I fully understand your problem, but let me throw this out to you...

    The SerIn has two things that can help you...

    The Wait until and the timeout.

    I am assuming that the ["A"] (wait until "A" is received, then get the next character) is causing your probem.

    To help get rid of noise, you need to ground the pin with a resister.

    The timeout can be pointed to the place you want to go if no signal is received.

    Serin InputPin, T300, 500, Label,["A"],DataStorage

    500 millisecond timeout and goto Label.

    if ok, put data in DataStorage and continue on.

    What I am not sure about, is if Serin is in receive mode, and is receiving data (good or bad) whether that 500 milliseconds will operate or not. I have not tested it, and I didn't see it in the manual. But I want to assume it is operating.

    Are we on the same page?

    Dwayne
    Ability to Fly:
    Hurling yourself towards the ground, and missing.

    Engineers that Contribute to flying:
    Both optimists and pessimists contribute to the society. The optimist invents the aeroplane, the pessimist the parachute

    Pilots that are Flying:
    Those who know their limitations, and respect the green side of the grass...

  3. #3
    Rubicon's Avatar
    Rubicon Guest


    Did you find this post helpful? Yes | No

    Default

    Dwyane

    Thanks for the reply and sorry for my lack of clarity. I really must post when I'm fresh and not so late at night.

    I have the Serin wait and the timeout with a pullup resistor and they work fine with the exception that when the receiver is in fact receiving something the timeout fails. I understand that this is just how it is when using the timeout in Serin. Its essentially the same as if you don't have a pull-up/pull-down resistor to eliminate noise - the transducer line/power supply/component noise with high opamp amplification keeps retriggering the timeout.
    SERIN PORTB.0,T300,200,NOSERIN,[CODE],B9

    As the receiver is ultrasonic (currently using a 40Khz transducer) I've found that there are many things that emit ultrasonics at or close to that frequency, enough anyway to keep the PIC Serin timeout retriggering. For instance a previous computers power supply two rooms away from the reveiver kept its Receive Indicator LED flickering and the timeout from working. An additional problem is that a transducer will resonate most easily at a particular frequency, 40kHz for example but it'll also resonate at other frequencies just not as easily - a good cause for me to investigate bandpass filters!

    This is why I'm after a way other than the program cycle to keep a time count and to turn the receiver off to save battery power when stuck in the Serin timeout.

    Do you think the Timer1 part of my first post is a viable option?

    Andrew.

  4. #4
    Join Date
    Oct 2004
    Location
    Hangover, Germany
    Posts
    289


    Did you find this post helpful? Yes | No

    Lightbulb

    Hello,

    forget the timeout-option in "serin" when you receive rf-transmissions.

    I've build it like this:
    I use Timer1 to measure a timelimit.
    So, start Timer1,
    Repeat receive 1 character trough serin,
    if the character is your lead-in receive the rest,
    until timer1 ends.
    go sleep....

    It may be necessary to slow down the transmitter by using DEFINE CHAR_PACING 1000 because you are using slow software rather than fast hardware!

    For me it it not necessary to receive each transmission!
    PBP 2.50C, MCS+ 3.0.0.5, MPLAB 8, MPASM 5.14, ASIX Presto, PoScope, mE mikroBasic V7.2, PICKIT2

  5. #5
    Rubicon's Avatar
    Rubicon Guest


    Did you find this post helpful? Yes | No

    Default

    Thankyou all for your help.

    As the transmitter is only sending the qualifier byte and a single code byte over and over at 300bps I'll drop the Serin timeout and give the Serin Timer1 timeout option a go this weekend.

    Once again thanks.

    Regards,

    Andrew.

  6. #6
    Join Date
    Oct 2004
    Location
    Hangover, Germany
    Posts
    289


    Did you find this post helpful? Yes | No

    Wink

    Think about some leading bytes ($55) in order to syncronize the receiver...
    PBP 2.50C, MCS+ 3.0.0.5, MPLAB 8, MPASM 5.14, ASIX Presto, PoScope, mE mikroBasic V7.2, PICKIT2

Similar Threads

  1. rfPIC Serin problem
    By gavo in forum mel PIC BASIC Pro
    Replies: 52
    Last Post: - 11th March 2008, 17:52

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