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.

18f43K20 timing woes

Status
Not open for further replies.
Obviously, you've forgotten whose thread you're posting in. Keep it up and you'll end up like Jon.
I knew there was something i was forgetting lol
so 2:1 it gets 18 pages
 
MrDEB, a few things...

Since you're using the intosc.bas module, remove
Code:
CONFIG fOSC = INTIO67 ' Internal oscillator, IO on pins 6 and 7
That's automatically handled by the intosc module for you, and it'll just confuse things when you change it later.
While you're at it, remove the duplicate 'INCLUDE "SetDigitalIO.bas"' statement.

Anyway, the IO setting of PORTA.6 and PORTA.7 have no effect on PORTC.6 and PORTC.7

but when the PIR2 TRIPS, THE PORTC.6 & 7 come on as well but not supposed to
I assume PORTC.6 and PORTC.7 are connected to your Green1 and Pwr_On LEDS? Which one is which?

There's more to your code than you're showing... how about posting the whole thing, and what you expect to happen with the HLVD module.
 
Jerry You wrote the IntOSC .bas Its nice work I was thinking it set's the whole ball of wax.
The sample shows how to use it Nice job.
Code:
device = 18F26K22
clock = 64

// optional - wait for intosc freq stable bit (the module defaults to not waiting)
'#option _INTOSC_IOFS_WAIT = true
include "intOSC.bas"
Rest of the gunk goes here
And a little more
Code:
device = 18F1320
clock = 8
include "IntOSC.bas"
include "USART.bas"
include "EEPROM.bas"
include "Convert.bas"

SetBaudrate(br19200)
Write("Program starting...",13,10)
while true
   Write("High",13,10)
   delayms(500)
   Write("Low",13,10)
   delayms(500)
wend
 
Well here is the whole enchilada at this point in time. The code is supposed to just monitor the battery condition but when the battery voltage goes down to 3.1 the yellow LOW Battery led comes on BUT portc.6 & 7 decide to come on as well.
Seriously thinking of eliminating the HLVD section but portc has no connections to portc ??
Have a second assembled board to test present code on,
 
MrDEB, do you ever proofread your posts after you click the button? You still don't get code tags (or you just refuse to indent to help people understand your code), and in the above case, you didn't even include the code you said you did. You expect people to take time to help you, but your can't even check to see that what you posted makes sense.
 
OUPS! my wife interrupted me
basic code
DEVICE = 18F43k20 ' Tell the compiler what chip we are using
CLOCK = 20 ' Tell the compiler what we will be setting the clock to (Mhz)
CONFIG MCLRE = OFF
CONFIG fOSC = INTIO67 ' Internal oscillator, IO on pins 6 and 7
CONFIG boren = off
'INCLUDE "INTOSC8.bas"
'INCLUDE "InternalOscillator.bas"
INCLUDE "SetDigitalIO.bas"
INCLUDE "Utils.bas"
DIM x AS BYTE
DIM Time AS LONGWORD
DIM Et_time AS LONGWORD
//INPUTS
DIM Mexi AS portA.0
DIM Bullit AS portA.1
DIM Master_Swt AS portE.0
DIM Position1 AS portB.0
DIM Position2 AS portB.1
DIM Position3 AS portB.2
DIM Position4 AS portB.3
DIM Position5 AS portB.4
DIM Position6 AS portB.5
DIM Position7 AS portB.6
DIM Position8 AS portB.7
DIM Position9 AS portD.0
DIM Position10 AS portD.1
//TIME SELECT
DIM Time1 AS portA.2
DIM Time2 AS portA.3
DIM Time3 AS portA.4
DIM Time4 AS portA.5
//OUTPUTS
//PLAYER POSITIONS leds
DIM pLAYER1 AS PORTC.0
DIM pLAYER2 AS PORTC.1
DIM pLAYER3 AS PORTC.2
DIM pLAYER4 AS PORTC.3
DIM pLAYER5 AS PORTC.4
DIM pLAYER6 AS PORTC.5
DIM pLAYER7 AS PORTC.6
DIM pLAYER8 AS PORTC.7
DIM pLAYER9 AS PORTD.2
DIM pLAYER10 AS PORTD.3
//TIMING LEDS
DIM Green1 AS portD.4
DIM Green2 AS portD.5
DIM Yellow1 AS portD.6
DIM Yellow2 AS portD.7
DIM MST_LED AS PORTE.1
//HLVD LEDS
DIM Low_bat AS portA.6
DIM Pwr_on AS portA.7
SUB HLVD()
HLVDCON =%00011100 'see section 22.0 for setup and table 26-4 for voltage setting
'set to 4 volts in this case 11100 = 3.1 volts
PIR2.bits(2) = 0
IF PIR2.bits(2) = 1 THEN 'check HLVD interrupt
Green1= 0 'LED = ON
PIR2.bits(2) = 0 'clear HVLD interrupt
ELSE
Green1= 1 'LED = OFF
END IF
TOGGLE (Pwr_on)
DELAYMS(50)
END SUB

//HLVDCON =%00011100 'see section 22.0 for setup and table 26-4 for voltage setting
'set to 4 volts in this case 11100 = 3.1 volts
//PIR2.bits(2) = 0
{
portC.0 to C.7 = blue player leds players 1 to 8
portD2 & 3 = blue player leds players 9 to 10
portA.6 & 7 = HLVD A.6 = LOW battery A.7 = Pwr on
portD.4 & 5 = greem leds timming
portD.6 & 7 = Yellow leds
portE.1 = red master switch led
}
SUB ET ()
pLAYER1=1
DELAYMS(1000)
TOGGLE(pLAYER1)
DELAYMS(500)
IF Time1=0 THEN Et_time=500 END IF //port A.2
IF Time2=0 THEN Et_time=750 END IF //port A.3
IF Time3=0 THEN Et_time=1000 END IF //port A.4
IF Time4=0 THEN Et_time=1500 END IF //port A.5

END SUB
//THIS routine cycles the LEDS off/on as per ET select routine
SUB Time_Countdown() //1000ms = 1 second x 5 Green, Green, Yellow, Yellow, RED
FOR x = 0 TO 7 //2500ms total on time1
Green1=0 //3750ms time2
DELAYMS(1000) //5000ms time3
Green1=1 //7500ms on time4
DELAYMS(1000)

NEXT
MST_LED= 1
DELAYMS(500)
TOGGLE(MST_LED)
DELAYMS(300)
END SUB


setalldigital
INPUT (Time1)
INPUT (Time2)
INPUT (Time3)
INPUT (Time4)
OUTPUT(pLAYER1)
OUTPUT(pLAYER2)
OUTPUT(pLAYER3)
OUTPUT(pLAYER4)
OUTPUT(pLAYER5)
OUTPUT(pLAYER6)
OUTPUT(pLAYER7)
OUTPUT(pLAYER8)
OUTPUT(pLAYER9)
OUTPUT(pLAYER10)
OUTPUT(Green1) //portd.4
OUTPUT(Green2) //portd.5
OUTPUT(Yellow1) //portd.6
OUTPUT(Yellow2) //portd.7
'OUTPUT(Pwr_on) //porta.7
'OUTPUT(Low_bat) //porta.6
OUTPUT (MST_LED)
'Trisa=%00000000
'TrisB=%11111111 'make all INputs
'TrisC=%00000000 'make all outputs
'Trisd=%00000000
HLVDCON =%00011100 'see section 22.0 for setup and table 26-4 for voltage setting
'set to 4 volts in this case 11100 = 3.1 volts
PIR2.bits(2) = 0
Position1=1
Position2=1
Position3=1
Position4=1
Position5=1
Position6=1
Position7=1
Position8=1
Position9=1
Position10=1
pLAYER1 = 0
pLAYER2 = 0
pLAYER3 = 0
pLAYER4 = 0
pLAYER5 = 0
pLAYER6 = 0
pLAYER7 = 0
pLAYER8 = 0
pLAYER9 = 0
pLAYER10 =0
'Pwr_on =0
MST_LED=0
Green1 = 1 //OFF
Green2 = 1
Yellow1 = 1
Yellow2 = 1
Time = 50
'Low_bat = 0
'Pwr_on = 0
MST_LED = 0
Time1=1
Time2=1
Time3=1
Time4=1
//et_time =
WHILE TRUE

IF Position1 = 0 THEN
TOGGLE(pLAYER1)
DELAYMS(50)
ELSE Position1 = 1
END IF

IF Position2 = 0 THEN
TOGGLE(pLAYER2)
DELAYMS(50)
ELSE Position2 = 1
END IF

IF Position3 = 0 THEN
TOGGLE(pLAYER3)
DELAYMS(50)
ELSE Position3 = 1
END IF

IF Position4 = 0 THEN
TOGGLE(pLAYER4)
DELAYMS(50)
ELSE Position4 = 1
END IF

IF Position5 = 0 THEN
TOGGLE(pLAYER5)
DELAYMS(50)
ELSE Position6 = 1
END IF

IF Position6 = 0 THEN
TOGGLE(pLAYER6)
DELAYMS(50)
ELSE Position6 = 1
END IF

IF Position7 = 0 THEN
TOGGLE(pLAYER7)
DELAYMS(50)
ELSE Position7 = 1
END IF

IF Position8 = 0 THEN
TOGGLE(pLAYER8)
DELAYMS(50)
ELSE Position8 = 1
END IF

IF Position9 = 0 THEN
TOGGLE(pLAYER9)
DELAYMS(50)
ELSE Position9 = 1
END IF

IF Position10 = 0 THEN
TOGGLE(pLAYER10)
DELAYMS(50)
ELSE Position10 = 1
END IF

' Green1=1 //portd.4
'Green2 = 1 //portd.5
'Yellow1=1 //portd.6
'Yellow2=1//portd.7
'Pwr_on=0 //porta.7
'Low_bat=0 //porta.6
{
DELAYMS(500)
MST_LED = 1
DELAYMS(1000)
TOGGLE (MST_LED)
DELAYMS(500)
ET()
Time_Countdown()
}
HLVD()
WEND
[code/QUOTE]
 
Screenshot_20180507-183727.jpg
 
Isn't the else statement saying IF pin.x=1 then pin.x=1 - Looks kinda redundant. However, who knows how the hardware is wired.

This is Deja Vu all over again - had an almost identical discussion about 10 years ago.

Mike.
 
Isnt this that super duper mouse trap you built?

There was stupid me thinking you were trying to build a flashing led. i.e go back to basics and learn... Why does the led have to flash? low battery led on. Jonsea dont take this the wrong way, but your not helping, nothing will change until you change it.

Ok swordfish you dosnt make you read the datasheet, but i advocate reading them so people get how the chip works. In this case i would advocate Mr Deb comments all code by line then at the start and end of each block of code, i would insist he reads the codes and comments exactly what his block of code has done. He isnt going any other way, sorry but i dissagree with this kind of constant spoon feeding the same way i would to a healthy 12 year old still being fed on the boob.

I am not being nasty, actually i am trying to help as its starting to look like we are the problem not the solution. If this is that mouse trap, you aint half got some nerve Mr Deb
 
In my earlier days when I had a bug, I'd describe how the code worked to anyone (Teddy, coffee cup etc.) that would listen (or not). The act of describing how code works will (almost always) make you realise where the bug is. I believe this method is now called "Rubber Ducking".

Mike.
 
8MHZ is burning some juice for a battery powered mouse trap. why do you need that kind of speed? Ok its 4 cycles but that is still really fast for this kind of thing. Also........ok iwill shut up now
 
In my earlier days when I had a bug, I'd describe how the code worked to anyone (Teddy, coffee cup etc.) that would listen (or not). The act of describing how code works will (almost always) make you realise where the bug is. I believe this method is now called "Rubber Ducking".

Mike.
Causes problems Mike, i used to do that with my sister while she gurgled in her cot, now she wants access to my parts bin!! I didnt drink coffee then and didnt have a teddy!! Rod for my own back lol

Actually it was you who told me to indent ( i still dont get that!) and comment the code line by line to start with, i kind of comment blocks now but it works
 
for the umpteenth time...
Code:
Position1=1
Position2=1
Position3=1
Position4=1
Position5=1
Position6=1
Position7=1
Position8=1
Position9=1
Position10=1
You can't write to an input pin

Code:
Time1=1
Time2=1
Time3=1
Time4=1
You can't write to an input pin

Code:
   IF Position1 = 0 THEN
       TOGGLE(pLAYER1)
       DELAYMS(50)
   ELSE                                 // you can only get here if Position1 = 1 already, so there's no point in this ELSE code
       Position1 = 1                // anyway, YOU CAN'T WRITE TO AN INPUT PIN

Do you see a pattern? What do you expect to happen when you write to a pin that's set as an input?

It's nice after all this you're not even using the INTOSC.BAS module!
By the way, 'CLOCK=20' is invalid for the internal osc... intosc.bas would have told you this had you used it
 
Try and think of a input pin being a read pin and a output pin being a write pin. Great mouse trap BTW, i guess it took a while to slip in seeing as you declared to not only have made it better but it was working.

Any known issues with SF and win 8.1? my system refuses point blank to install it

Does anyone actually approve forum applications at SF? i joined 5-6 weeks ago and still not approved! Not even sure i can remember the name i used now lol
 
Last edited:
Any known issues with SF and win 8.1? my system refuses point blank to install it
I know others have installed it on win8.1 with no issues. Is this the full version or the free SE version?

Does anyone actually approve forum applications at SF? i joined 5-6 weeks ago and still not approved
Maybe try again, esp if you don't remember how you registered. I know new users have been approved as recent as May 1.
 
Its the free version, i also couldnt get the LCD character add on program to install, it said i needed a updated file that i clearly done, i even followed the link to download the MS files it wanted :(. Shame i cant find a simple program that walks me through using this.

Could be me however, i am so used to ARM and pics etc, and different IDE's, It gets confusing. I want to use the Junebug with SF
 
Jon found a typing error in post #50
as for writing to an input I am in error but then I am aware of what the pin is supposed to be. Will take the errors out.
Not using it?? INTOSC.BAS module! after I inserted it into the code the timing work great. Just need to adjust the button debounce as the Leds start blinking when pressing desired button
I will add explanations to each line of code. As for the ELSE statement in # 50, have seen this in lots of code examples. not really needed but.
I tested a second board and with the HLVD module activated, the portC. 6 & 7 are enabled when the PIR2.bits(2) = 1 trip point is 3.1 volts.
 
Status
Not open for further replies.

Latest threads

Back
Top