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.

HT12D and HT12E encoder/decoder issues

Status
Not open for further replies.
You're right. LVP is an absolute mystery. Nobody knows what it is or what it does. Well, wait. Maybe the data sheet says something.... Oh. It's not a mystery. Right there in the data sheet. Imagine that. Perhaps you should look at it sometime.

I'll save you the trouble of reading the data sheet and becoming confused. LVP should be off. This will always be true for you and most readers here.

You might make clear that a piece of code your posting is a fragment, just a part of what you are trying to do. And explain exactly what it is you think/expect/believe/want it to do. Since following this project in nearly 60 pages of forum posts and with all your changes is not humanly possible, it will aid people who are trying to help you.

MrDEB Programming Style
 

Attachments

  • image.jpg
    image.jpg
    758.2 KB · Views: 194
Just in case you don't believe the datasheet is a good reference, here is the first item that comes up on a Goggle search:

PIC18F LVP. This is a good reference on the dangers of enabling LVP.

Just set it to off. It will be fine.
 
Well blow me over, 8volt programming?
I guess from now on just make sure the LVP is off
Thanks Jon, interesting reading
 
lol All I can say is I am on a mission and not much will sawy me off coarse. Determination and lots of experimenting to see what and how things work and why.
I have been cursed at, laughed at etc. but I have a goal that I am shooting for. Laugh all you want.
 
I wonder where this is at

Code:
// default fuses...
config
   OSC = HS,
   FCMEN = OFF,
   IESO = OFF,
   PWRT = ON,
   BOREN = ON,
   WDT = OFF,
   WDTPS = 128,
   PBADEN = OFF,
   STVREN = ON,
   LVP = OFF,   // What's this one say ??????
   XINST = OFF,
   DEBUG = OFF

I wonder what happens here
Code:
 PORTB_Interrupts(True) // Enable PORTB interrupts
  If saveport.bits(5) = 0 Then
Once it happens it stays that way. You have to reset the variable in main
And where did you set saveport to $F why because it 0 to start it shouldn't change till a portb on change happens but how would you know you didn't set it any where in your code.

And one more thing what this mean
Code:
While True // Infinite loop
Never happen why it's false if saveport is %00000000 it can't change can It????.
 
Last edited:
All good points Burt. I started editing my code to get some of the garbage out and make corrections. Moved the switch routine to the While/Wend loop.
Tried running the code and it works but it now hangs up in the battery test. It worked before I connected to transmitter and some editing of code. It appears the transmitter is lowering the voltage below the pic requirement and causing a loss of power. Need to address issues but I need to drive to California today for a funeral. Be back in one week then will address issues.
PORTB_Interrupts(True) // Enable PORTB interrupts
If saveport.bits(5) = 0 Then
this is within the while wend loop and enables interrups if there was a portb change.
While True // Infinite loop
this keeps looping checking for an interrupt call. As long as its true then no interrupt routine.
Right now all works except the bad battery. The good battery works.
I think I added a reset of the interrupt falg and didn't need to thus it is alwasys getting reset when it shouldn't be set.
 
Interrupt Collision!!

I ran the HLVD code and it works just finew. lower the voltage via the MPLAB down below the trip point and led0 lights up, above the trip point and bat led is enabled.
Changing the voltage in MPLAB saves having to use an external variable supply.
Code:
{
*****************************************************************************
*  Name    : UNTITLED.BAS                                                   *
*  Author  : [select VIEW...EDITOR OPTIONS]                                 *
*  Notice  : Copyright (c) 2013 [select VIEW...EDITOR OPTIONS]              *
*          : All Rights Reserved                                            *
*  Date    : 1/15/2013                                                      *
*  Version : 1.0                                                            *
*  Notes   : working code 1/15/2023                                                               *
*          :               2/1/2013                                                 *
*****************************************************************************
}
Device = 18f2520
Clock = 8
Include "internalOscillator.bas"
Include "utils.bas"
 
Dim led0 As PORTC.3  //blue led
Dim led1 As PORTC.4  //green led
Dim led2 As PORTC.5  // red
Dim bat As PORTC.2   // extra green
Dim s1 As PORTB.4    //switch
Sub bat_test()
     If PIR2.bits(2) = 1 Then          'check HLVD interrupt
     led0 = 1
     led1 = 0
     led2=0
     bat = 0
     DelayMS(1000)
     Toggle(led0)
   EndIf 
 If PIR2.bits(2)=0 Then
     led0 = 0
     led1 = 0
     led2 = 0
     bat=1           // good battery
     DelayMS(2000)
     Toggle(bat)
     
 End If
 
   
 End Sub

SetAllDigital
Output(bat) 
Output(led0)
Output(led1)
Output(led2)
Input(s1)
 
led0 = 0
led1 = 0
led2= 0
bat = 0
 
HLVDCON =%00111000     'see section 22.0 for setup and table 26-4 for voltage setting 
                        'set to 3.39 volts in this case
 
PIR2.bits(2) = 0        'clear HLVD interrupt flag
PIE2.bits(2) = 1        'enable HLVD interupt (section 22.2, sentence 5)
'intcon.bits(7) = 1     'enable HLVD interupt (section 22.2, sentence 5)
                        'not needed for polled result 
           
 
While 1 = 1
     If s1 = 1 Then
     bat_test()
     Else
     bat =1          //extra green
     DelayMS(500)
     Toggle(bat)
     DelayMS(500)
     End If
     PIR2.bits(2) = 0         'clear HVLD interrupt
Wend
NOW for the interrupts colliding
When I insert the working battery test routine (hlvd) all works until I get to the trip point. BAM!! the pic just locks up. I raise the voltage and reset the pic and it works again until the trip point is achieved.
Reading Burts posts about EVENTs and maybe try this out.


https://www.electro-tech-online.com/threads/more-swordfish-basic-help-please.116360/
Maybe to wrong approach but feel the portB interuupts are screwing everything up.
Thought about using interrupt priority but ??
 
I know this is an exercise in frustration, but...

Somewhere in the dim dark past of this thread (or one of many on this same topic) you stated that you wanted to check the battery only when a switch was pressed.. Is this not a true statement or have you changed you mind?

If this is true, why do you even have the HLVD routine generating at interrupt? I posted a working example of how to poll the HLVD module to check if the voltage is below the trip point. Interrupts were not used in the code I posted. When the switch is pressed, check the voltage. No interrupt required.

Even if you do want to do the more logical approach of checking the voltage during normal program execution, interrupts are not needed. Just insert the polled HLVD check into the main program loop.

To summarize, the one and only interrupt you need is the one to wake the micro when a button is pressed. One. Only one. No others.
 
I must have missed or misinterpreted about the polling of the HLVD.
YES I want to be able to push a button to check the battery condition. In my many approaches I think I tried where bit 5 was 0 so no interrupts but when I combined the HLVD as posted with the rest of the program code, everything locks up when the HLVD arrives at the trip point, regardless if bit 7 is set or not (high or low trip point)
Yesterday I connected the s3 (battery test) to a different port pin but that didn't work. Will go back to square one and try again without the interrupt in the HLVD. maybe I missed something.
 
Geez oh grief.... I posted working code in message #73...a hundred messages and nine forum pages ago.

What does "bit 7 (high or low trip point)" have to do with interrupts?!?!?

You don't need an interrupt to check HLVD. In fact, you have stated you don't want an interrupt - you only want to check battery condition during an ill-conceived test triggered by a button press. So WHY are you using an HLVD interrupt?
 
I tried the hig low voltage trip point to determine if the code is working as it is supposed to.
Will reread post #73. Maybe I mis interperted or missed something.
As I stated, I tried with and without interrupts on the HLVD but will try out post #73 again
 
AM I missing something?

I eliminated the battery test sub and put in the WHILE 1 = 1 loop but at the trip point the pic still locks up.
HLVDCON = %00011000 // 3.12 volts
I studied both code snippets and fail to see any significant difference.
I even took out the sleep routine but to no avail.
Post #73 I tried way back then and yes it works as does my last revised code I posted today until I get the portB interrupts in the mix. But the HLVD has the interrupts disabled. Contemplating having the HLVD blink an LED when battery is LOW but without a button press.
the following code does same as post #73 but it checks s3 saveport.bits(4)

If saveport.bits(4) = 0 And PIR2.bits(2) = 1 Then
led0=1
DelayMS(1000)
led0=0
PIR2.bits(2) = 0
Else
saveport.bits(4) = 1
GD_bat =1
DelayMS(1000)
GD_bat=0

End If
------------------------------------------------
POST #73

if pir2.bits(2) = 1 then 'check HLVD interrupt
*
ledblue = 0
pir2.bits(2) = 0 'clear HVLD interrupt
*
else
ledblue = 1
end if
*
toggle (ledyellow)
delayms(1000)
*
wend
 
Making some progress - a little

If I make pie2.bits(2) = 0 it works after trip point BUT on its own. If I press s3 after the trip point the whole mess locks up.
want to research pie2 and pir2. Its not listed in the HLVDCON register?
Code:
While 1=1 // Infinite loop
 PORTB_Interrupts(True) // Enable PORTB interrupts   MOVED TO END but no change

 If saveport.bits(6) = 0 Then
      LEFT
 End If
 
 If saveport.bits(5) = 0 Then
     RIGHT
 End If
 If s3 = 0 then PIE2.bits(2) = 1   
 else 
 PIE2.bits(2) = 0     //HLVD enable bit
 end if
if PIR2.bits(2) = 1 then
    led0=1
    DelayMS(1000)
    led0=0
    PIR2.bits(2) = 0
 // HLVDCON.bits(5) = 0   
 Else 
 PIR2.bits(2) = 0
    GD_bat =1
    DelayMS(1000)
    GD_bat=0
 // HLVDCON.bits(5) = 0     
 End If 
  
'xxxxxxxxxxxxxxxxxxxxxxxxxxx
 

 
 Sleep
Wend
 
want to research pie2 and pir2. Its not listed in the HLVDCON register?

Does your Acrobat Reader lack a search function? Mine has one. In fact, every one I've ever used has one. Maybe you can try it sometime instead of making everybody else do your "research" for you.

If I make pie2.bits(2) = 0 it works after trip point BUT on its own. If I press s3 after the trip point the whole mess locks up.

Ok, if PIE2.bits(2) = 0 makes it work, then what in the he?? are you thinking with this?

Code:
 If s3 = 0 then PIE2.bits(2) = 1

WHY? What exactly do you expect that to do?

From the data sheet:

22.2 HLVD Setup
The following steps are needed to set up the HLVD module:

1. Write the value to the HLVDL<3:0> bits that selects the desired HLVD trip point.

2. Set the VDIRMAG bit to detect high voltage (VDIRMAG = 1) or low voltage (VDIRMAG = 0).

3. Enable the HLVD module by setting the HLVDEN bit.

4. Clear the HLVD interrupt flag (PIR2<2>), which may have been set from a previous interrupt.

5. Enable the HLVD interrupt, if interrupts are desired, by setting the HLVDIE and GIE bits (PIE2<2> and INTCON<7>).

An interrupt will not be generated until the IRVST bit is set.

Are interrupts desired? Let me answer that for you again. NO! So PIE<2> should NOT be set - that means it should be ZERO!

Admittedly, I didn't handle this correctly in the code I posted, but everything you need to know was there!

Code:
{
*****************************************************************************
*  Name    : HLVD Test                                                      *
*  Author  : Jon Chandler                                                   *
*  Notice  : Copyright (c) 2013 Creative Commons 3.0 sa-by-nc               *
*          : All Rights Reserved                                            *
*  Date    : 1/8/2013                                                       *
*  Version : 1.0                                                            *
*  Notes   : Poll the HLVD register to detect low Vdd voltage.              *
*          : Register settings may vary with device.                        *
*****************************************************************************
}

Device = 18f2520
Clock = 20

include ("utils.bas")

Dim LEDYellow As PORTB.3
Dim LEDBlue As PORTC.0

SetAllDigital

Output(LEDBlue)
Output(LEDYellow)

ledblue = 0
ledyellow = 0

delayms(2000)

LEDBlue = 1
LEDYellow = 1

hlvdcon =%00011011      'see section 22.0 for setup and table 26-4 for voltage setting 
                        'set to 4 volts in this case

pir2.bits(2) = 0        'clear HLVD interrupt flag
pie2.bits(2) = 1        'enable HLVD interupt (section 22.2, sentence 5)    '******************* this line should have been rem'd out *****************
'intcon.bits(7) = 1     'enable HLVD interupt (section 22.2, sentence 5)
                        'not needed for polled result    

while 1 = 1

    if pir2.bits(2) = 1 then          'check HLVD interrupt

            ledblue = 0
            pir2.bits(2) = 0          'clear HVLD interrupt
    
        else
            ledblue = 1
    end if
    
    toggle (ledyellow)
    delayms(1000)
       
wend



I'm sorry I missed the line commented on in the code above. But geez, it was labeled "enable HLVD interrupt" with the section of the documentation given. You should be able to understand to that point at least!!!!!!

Done. Finished. Complete. I give up. You're on your own. Find somebody else to write your code - lord knows you can't do it yourself. I am sorry to be harsh, but there are 60 pages of forum posts on this relatively simple project at least. How much help can you expect???????????????
 
The setting of pie2.bits still does not completely solve the issue of the pic locking up. YES it still locks up if the voltage goes too far past the trip point.
I stated I am going to research the pie2 and pir2 registers but got called away. I only got this far into the locking up issue by experimentation not by anything you suggested.
Read the data sheet = yes
Follow your code that you posted but Jerry wrote as I understand it = yes
code works by itself = yes
you stated no interrupts = I eliminated interrupts temporally and now it kinda gets along with the code I basically wrote. YES I wrote the TX code in my program.
YES You and Burt helped some until the HLVD locking up issue showed up.
 
...You and Burt helped some until the HLVD locking up issue showed up...

Helped some???

Oh boy you have an ability for understatement! I feel so underwhelmed by your appreciation.

Help some more?

Doubtful.
 
FOUND solution or it appears to work

If I disable the HLVD from the start but enable it in the BATTERY TEST sub routine all seems to work.
Am able to get in and out of the HLVD routine instead of just in and not out.
here is the sub routine that I wrote that works so far. Lowered the voltage from 4v down to 2.9 (trip point is set at 3.12volts) then back again all the while pressing s3 to check on battery voltage. More testing then house cleaning if all works.
Code:
' xxxxxxxxxxxxxxxxxxxxxxxxxx
Inline Sub  BATTERY_TEST()
'xxxxxxxxxxxxxxxxxxxxxxxxxxx
' BAD BATTERY
HLVDCON = %00011000    // 3.12 volts   HLVD is enabled
If PIR2.bits(2) = 1 Then       // interrupt flag bit


  // check hlvd flag
     // rbif = 0                 
     // rbie = 0  //interrupt enable bit
     // TX_pwr = 1    //turn on transmitter
    led0 = 1     //blue led next to green BI color in final plan
         DelayMS(1000)
    Toggle(led0)
    PIR2.bits(2)=0  // clear interrupt flag
    PIE2.bits(2) = 0                    // allow interrupt temp
//HLVDCON.bits(5) = 1                 // set the IRVST bit for interrupts
 Else
 
     
 ' GOOD BATTERY

      // TX_pwr = 1    //turn on transmitter
       GD_bat = 1       // green led next to blue GD_bat = good battery
              DelayMS(1000)
       Toggle( GD_bat)
              DelayMS(1000)
       TX_pwr = 0                       //turn off transmitter
    EndIf  
//PIE2.bits(2) = 0                    // allow interrupt temp
//HLVDCON.bits(5) = 0                // set the IRVST bit for interrupts    
HLVDCON = %00001000    // 3.12 volts   
End Sub
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top