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

HT12D and HT12E encoder/decoder issues

Discussion in 'Electronic Projects Design/Ideas/Reviews' started by MrDEB, Dec 4, 2012.

  1. MrDEB

    MrDEB Active Member

    Joined:
    Apr 16, 2007
    Messages:
    4,414
    Likes:
    23
    interrupt 2x instead of 1x

    Been hacking this for a day and a half trying to configure to get one interrupt to enable LED on portA.5 but getting two cycles through code instead of one.
    When I started I was getting 3x.
    I only need 1x
    Also thinking I should get a lower current draw during SLEEP. Presently drawing 4,2ma during sleep.
    Code (text):
    {
    *****************************************************************************
    *  Name    : UNTITLED.BAS                                                   *
    *  Author  : Doug                                *
    *  Notice  : Copyright (c) 2013 [select VIEW...EDITOR OPTIONS]              *
    *          : All Rights Reserved                                            *
    *  Date    : 1/4/2013                                                       *
    *  Version : 1.0                                                            *
    *  Notes   :  had 3x but now 2x. Only need 1x                                                              *
    *          :                                                                *
    *****************************************************************************
    }



    Device = 18F2420

        Clock = 8
    Include "InternalOscillator.bas"
    Dim RBIF As INTCON.0  //port change interupt flag
    Dim RBIE As INTCON.3 //port change interupt enable

    Dim LED1 As PORTA.5
    Dim led2 As PORTA.3
    'xxxxxxxxxxxxxxxxxxxx
    'interrupt
    'xxxxxxxxxxxxxxxxxxxxx
    Interrupt PORTB_Change()
    // Save(0) // Save the system variables
     If RBIF = 1 Then // Check if the interrupt was a PORTB change
    // RBIF = 0  ' moved to end
     WREG = PORTB // Be sure to read the contents of PORTB to
     // clear the mismatch
     
     // PORTB 7:4 has changed

     LED1 = 0
     DelayMS(5000)
     Toggle (LED1)
     DelayMS(500)

     EndIf
     RBIF = 0      // clear flag  this changed from 3x to 2x
    // Restore // Restore the system variables
    End Interrupt
     
    Sub PORTB_Interrupts(Control As Boolean) // Small routine to enable/disable PORTB Interrupts.
     If Control = True
     Then
     RBIE = 1 //  interrupt enable bit
     Enable(PORTB_Change)
     Else //
     RBIE = 0 //
     Disable(PORTB_Change) //
     EndIf //
    End Sub
     
    Inline Sub Sleep()
     Asm
     Sleep
     End Asm
    End Sub
     
    // Start Of Program...
    TRISB = %11110000 // Make PORTB7:4 all inputs
    //TRISC = %00000000 // Make PORTC all outputs
     

     
    While True // Infinite loop
          PORTB_Interrupts(true) // Enable PORTB interrupts

          Sleep // Put the PIC to sleep and wait for a change
     // on PORTB 7:4
    Wend

     
     
  2. MrDEB

    MrDEB Active Member

    Joined:
    Apr 16, 2007
    Messages:
    4,414
    Likes:
    23
    fixed interrupt multiplies

    moved the WREG = PORTB statement (clears the mismatch) after the interrupt does its thing (turn on LED).
    Now to get the circuit to draw less than 4.4ma. Tried changing the osccon.bits(7) = 0 but didn't help(this is after the sleep instruction.)
    Thinking of changing the clock frequency?

    Code (text):
    Interrupt PORTB_Change()
    // Save(0) // Save the system variables
     If RBIF = 1 Then // Check if the interrupt was a PORTB change
     //RBIF = 0  ' moved to end
     //WREG = PORTB // Be sure to read the contents of PORTB to
     // clear the mismatch
     
     // PORTB 7:4 has changed
     
     LED1 = 0
     DelayMS(5000)
     Toggle (LED1)
     DelayMS(500)

     EndIf
     RBIF = 0      // clear flag  this changed from 3x to 2x
    // Restore // Restore the system variables
      WREG = PORTB // Be sure to read the contents of PORTB to
     // clear the mismatch

    End Interrupt
     
     
  3. MrDEB

    MrDEB Active Member

    Joined:
    Apr 16, 2007
    Messages:
    4,414
    Likes:
    23
    changing the clock didn't change the current draw during SLEEP
    tried using OSCTUNE=1000000 (min frequency)
    open for suggestions unless this is it but read that .1ua is possible?
     
  4. dave

    Dave New Member

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


     
  5. MrDEB

    MrDEB Active Member

    Joined:
    Apr 16, 2007
    Messages:
    4,414
    Likes:
    23

    Found issue = I still had solder jumpers connecting a second switch and some LED cathodes. Contemplated during lunch
    Got current draw down at present to .043ma.
    Now to connect the transmitter and associated circuitry and connect up the HLVD connections and reprogram. I removed all connections to PORTB pins except the two turn switches (waiting for tilt switches and connect up filters as per data sheet.
     
  6. JonSea

    JonSea Well-Known Member

    Joined:
    Oct 1, 2012
    Messages:
    1,197
    Likes:
    109
    Location:
    Seattle, WA
    I think you had other problems than pull-up resistors. The Impact of Pull-up Resistors shows the current draw.

    If you have a 10k pull-up on a switch, the worst case current draw is 0.5 mA while the switch is pressed and close to nothing when the switch is open. Of course, this assumes the associated port pin is configured as an input. If it's configured as an output, the current draw would be 0.5 mA if the output was low (and nothing if high).

    The current limiting resistors on LEDs won't draw any current if the LEDs aren't illuminated (assuming the LEDs are installed with the correct polarity).

    However, it's good practice to open the solder jumpers for unused switches and LEDs on the TAP-28 board.
     
    Last edited: Jan 5, 2013
  7. MrDEB

    MrDEB Active Member

    Joined:
    Apr 16, 2007
    Messages:
    4,414
    Likes:
    23
    I opened all the solder jumpers except the S1 jumper and LED1 jumper.
    Assembled a second Tap-28 w/o the crystal and reconfigured the connections of the transmitter pwr pin and any other connections I had to portB except the two switches I use to tell the PIC what to transmit (PortB interrupt). Today hopefully get the HLVD configured/connected for battery condition monitor as well as get my ports in code reconfigured.
    AFTER I get this project as is working I am going to experiment using the 18F25K20 pic as it is much cheaper.
    As a side note,, I see Tullys Coffee almost went belly up. Have had Tullys and IMO better that that high priced GREEN LABEl stuff so called coffee.
     
  8. JonSea

    JonSea Well-Known Member

    Joined:
    Oct 1, 2012
    Messages:
    1,197
    Likes:
    109
    Location:
    Seattle, WA
    I find it interesting....

    When it's pointed out that your conclusions don't make sense, that the current draw from an unneeded pull-up resistor is nearly 10 times what it would be in the worst case condition (the associated port pin a low output) and you just blow it off without a mention.

    Don't you wonder if the pin was set to be an output? If the resistor was 10x smaller than the norm? Of if something totally unrelated got changed in the process? I've found that mysterious problems I ignore come back to bite me in the butt later on, always at the worst possible time. *shrug*. It's your project (with many hours of support by others!) so you can do what you want, but it seems like you'd have the intellectual curiousity to at least wonder.....
     
  9. MrDEB

    MrDEB Active Member

    Joined:
    Apr 16, 2007
    Messages:
    4,414
    Likes:
    23
    I didn't shrug off your response. I realized still had solder jumpers that needed to be removed. And yes I had the s1/rb5 as well as s2 and rb4 configured as inputs. My conclusion to remove the solder jumpers worked. I needed the s1 jumper still intact but after removing all the jumpers except for s1 the current went down as expected.
    As far as things that bite in the butt, I reconfigured my code and failed to realize that I no longer had the external osc on board and the dang thing didn't work. It did before. Took a lunch break, a wisky-7 and realized that I had a different Tap-28 w/o the ext osc. Inserted internal .bas and all is well.
    At present inserting code for the HLVD on RA.5 and can't find any reference if it can be connected directly to the Vdd w/o the voltage divider No clue so soldering in two resistors.
    Have yet to see any reference in code that anyone has used this feature? but it looks fairly, easy just configure the HLVDCON register bits.page 243-247 and page 339 in the data sheet.
     
  10. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,869
    Likes:
    144
    Location:
    morristown,tn
    HLVD What do you plan to do with this
     
  11. MrDEB

    MrDEB Active Member

    Joined:
    Apr 16, 2007
    Messages:
    4,414
    Likes:
    23
    Battery monitor. I was wanting to eliminate the voltage divider as indicated in the schematic I posted using two 50k resistors then I realized the pic has an HLVD onboard.
    Was wanting to just connect RA.5 to Vdd but data sheet shows a voltage divider. So much for progress.
     
  12. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,869
    Likes:
    144
    Location:
    morristown,tn
    It needs one to work that how you set the trip point and two if setup is wrong it waste power.
     
    Last edited: Jan 6, 2013
  13. JonSea

    JonSea Well-Known Member

    Joined:
    Oct 1, 2012
    Messages:
    1,197
    Likes:
    109
    Location:
    Seattle, WA
    Ummmm....speaking of measuring battery voltage....

    In some version of what you're trying to do, you have the micro running from 2 or 3 presumably alkaline cells, and you want to use the micro's ADC to measure the battery voltage. What is going to be the reference voltage?

    Some of the 18F K-series have some form of FVR (Fixed Voltage Reference), but depending on the chip in question, these work in different ways. There are some discussions of the FVR at Digital-DIY that explain how to use some of the variations. The 18F25K20 is the crudest form. It has an FVR, but it can't be used as a reference for the ADC. If Vdd is used as the reference, and the FVR channel is measured, some math allows determining what the actual Vdd value is. No voltage divider required but you have to follow the math to make it work. Other K-series parts do allow using the FVR as a reference so are a bit easier to use. Again, the details have been discussed at Digital-DIY.

    As far as I am aware, the FVR is a feature of (some of the) K-series only. If you're going to use a non-K-series part, you need to provide a stable reference to the ADC. There are some references on this over there too.

    I'm not trying to rain on your parade but considering the details is kind of important.
     
  14. MrDEB

    MrDEB Active Member

    Joined:
    Apr 16, 2007
    Messages:
    4,414
    Likes:
    23
    I realize what your saying Jon, I am going by what the data sheet says. You specify the device voltage trip point and the direction of change.
    the HLVD module is enabled, a comparator uses an internally generated reference voltage as the set point How it differs from what I have in my posted schematic--not sure so I will connect it up and vary the voltage just to see how well it works. If not, back to my original design of two 50k resistors as voltage divider(yea same as using the HLVD module?)
    My big question is the diagram is for an external input. Wondering if connecting the Vdd directly to the HLVD input would work? No reference I have found to doing this. The module monitors for drops in VDD.
     
  15. JonSea

    JonSea Well-Known Member

    Joined:
    Oct 1, 2012
    Messages:
    1,197
    Likes:
    109
    Location:
    Seattle, WA
    image.jpg Wow. MrDEB may have stumbled across something that will work.

    The unanswered question in MrDEB's post is of course the range of the High/Low Voltage Detect circuitry and therefore the need for a voltage divider. A little research in the data sheet found this table for a standard 18F-series part.

    For this 5 volt part, there are 16 increments of about 0.2 volt spacing, but note the tolerances on the measurement. For example, setting 0111 can vary from 2.96 v to 3.28 v depending on chip tolerances. With the flat discharge characteristics of alkaline batteries, selecting the correct range may have to be done for each part.
     
  16. MrDEB

    MrDEB Active Member

    Joined:
    Apr 16, 2007
    Messages:
    4,414
    Likes:
    23
    I am not real concerned about accuracy, just want to indicate when the battery may need to be recharged with plenty of leeway.
    The transmitter requires 2.4v so I was going for 3v to trigger the HLVD.
    If I go with Vdd/10k/HLVD input/ 50K'grd to start. then set the HLVD for 2.44 or 2.60.
    This should maybe cross our fingers give enough leeway. Perhaps a trim resistor but that's going overboard IMO
    If not then perhaps just use the ADC but Microchip put the HLVD on the chip for a reason. I looked on the microchip site about this hoping to be able to connect directly to Vdd or other info but zero!
    as far as batteries, am still considering rechargable
     
  17. JonSea

    JonSea Well-Known Member

    Joined:
    Oct 1, 2012
    Messages:
    1,197
    Likes:
    109
    Location:
    Seattle, WA
    Geez oh grief. I hand this to you on a silver platter and you still don't get it... Between the table (the key piece you didn't even think to look for) and the schematic of the internal arrangement in the section you quoted from, you have EVERYTHING needed to UNDERSTAND how to make it work.

    If you are going to make a reliable battery test, "I'm not really concerned with accuracy" is just not going to cut it.

    It's somebody else's turn. Anybody?
     
  18. MrDEB

    MrDEB Active Member

    Joined:
    Apr 16, 2007
    Messages:
    4,414
    Likes:
    23
    I understand how it works but maybe and how to implement but I misunderstood something?
    My goal is to have a simple LED indicator of battery condition. Accuracy in this application is OK but not a prime goal. When the user is done for the day of bike riding, if the battery is close to 3v then the LED begins to blink. I have a voltage divider made up of two 15K resistors connected to RA5. Just need to program the HLVDCON and see what the results are. but at the same time wondering if just using the ADC of say RA0 then using a FUNCTION statement would it be basically the same thing. BUT as stated, Microchip put this HLVD on the chip for a reason so might as well use it to make life simpler. One big advantage of using the HLVD is it probably uses a better implemented voltage reference than the ADC and or lower current draw.
     
  19. MrDEB

    MrDEB Active Member

    Joined:
    Apr 16, 2007
    Messages:
    4,414
    Likes:
    23
    DUH hit me on the head with a stick!!
    while setting up the HLVD I see I don't need to connect the external voltage divider. Just program the desired bits unless an external voltage source is desired. So I want
    hlvdcon = 00110110 which equates to 2.74 - 3.04 volts.
    Will give it a go.
     
  20. JonSea

    JonSea Well-Known Member

    Joined:
    Oct 1, 2012
    Messages:
    1,197
    Likes:
    109
    Location:
    Seattle, WA
    *shrug*

    You are missing several points but that's not my concern.

    Do you even know what the discharge curve for whatever-the-heck batteries you're planning on using looks like? Most are very flat until the battery is nearly dead, and then they drop like a rock. At 3 volts for a 3 alkaline cell pack, you'll have only minutes of warning before the batteries are dead.

    "When the user..."??? If you are planning on selling this claptrap to the innocent public, you have to pay attention to the details. Somebody is going to get killed.

    image.jpg
     
  21. MrDEB

    MrDEB Active Member

    Joined:
    Apr 16, 2007
    Messages:
    4,414
    Likes:
    23
    YES I need to decide on battery type so battery discharge curve is not known. My mistake 1
    unit draws a max of 15ma intermittently but .04 during sleep so I need to calculate how long will batteries last between 2.5 volts and 3 volts at a 15ma discharge rate.
    Battery pack, depending on battery chemistry is 4.5v (3-AA alkaline) or less as most rechargeable are 1.2v. Am avoiding Lithium Ion for exploding issues.
    I realize I need more details.
     

Share This Page