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.
I will move over to my SF thread with my problems, i spoke with Blueroom and the idea is I might do another junebug type board, based on the pK2 like the bug, but twice as big and using a 40 pin chip. These are for the club/teaching thing i do one day a week every two weeks at my sisters school.

We have been using the badger board with a 32bit ARM chip and C, but if i can get upto speed with SF i should be able to make 20-30 boards cheaply using what i got in my parts bin. Mostly they use the boards for data loggers and environmental stuff, end goal would be to write a module for the board. That way I could add some flexibility into what they do with the boards, and give them a chance to use basic. I have a load of some of the older 40 pin pics sitting about, the PK2 is solid and i dont really need anything else.

I wont get as much stuff packed into the board like Bill did, hence using a bigger board, but boards are cheap to have done now. I might change the program chip to a SMD one and use smaller buttons, again mainly because i have alot of them.

Found my SF forum details, still not activated although i joined back in April!!
 
Last edited:
Not using it?? INTOSC.BAS module!
I hope that's not really a question since post #50 doesn't include intosc.bas

As for the ELSE statement in # 50, have seen this in lots of code examples
That wouldn't surprise me. There's lots of stupid stuff out there.
Think about it...
Code:
IF Position1 = 0 THEN
   TOGGLE(pLAYER1)
   DELAYMS(50)
ELSE
 // if you get here, Position1 must already be = 1, otherwise the IF-THEN part would have executed
 // since Position 1 is already 1, why set it to 1 again? You can get rid of the whole ELSE part
 // besides THIS TRIES TO WRITE TO A PIN THAT'S AN INPUT!!!!!! YOU CAN'T SET AN INPUT. IT IS WHAT IT IS.
   Position1 = 1
END IF

LG -
Try registering again... maybe the email got lost or something.
Or drop an email to enquiries AT sfcompiler.co.uk
 
I dropped an email to the linked one, so will use above address thx. If what i plan works out the school would buy 30 licenses, but here is the catch and typical school thinking........

(me) Hi i need £50 to get a full compiler for the course

(HT) Ok does it do what we need?

(me) well probably but i need to make sure, thats why i want to buy one to check it before we go and buy 30 of them.

(HT) So you havnt tested the full version yet?
(me) No not yet because i dont have the full version
(HT) we cant buy it if you havnt tested it
(me) I cant test it unless we buy it
(HT) well cant we use something else?
(me) well yes we could
(HT) why dont we do that then?
(me) Ok, can i have £150 for the full version of y compiler
(HT) Why do you need that?
(me) Because i need to test it before we use it and you wont give me £50 to test the other option.
(HT) can we use something less than £150?
(me) Yes, can i have £50 for it
(HT) have you tested it......?

Honest short version of a typical purchase conversion, HT is head Teacher, whats worse is the following.
(me) can I have £1,200 for a new pump system for the green house
(HT) whats wrong with the old one?
(me) Nothing, but the other one uses £1 week more in electric
(HT) Ok put the form in and i will sign it off.

Old pump cost us £25, so not too many years to recover the money lol, actually the new pump has a much bigger flow rate that we now need, but the HT dosnt know this and didnt ask!
 
Sorry I grabbed the wrong code. I have the INTOSC.BAS module in my code that I am using with all the bel;ls and whistles included. Have numerous snippets to test out different code variations.
 
Sorry I grabbed the wrong code. I have the INTOSC.BAS module in my code that I am using with all the bel;ls and whistles included. Have numerous snippets to test out different code variations.
Get ONE lot of code working first, understand the code and optimize it. In fact choose the most simple version and make sure it both works as intended, is as heavily commented as you can make it including exactly what each line does and which registers it affects.

THEN add ONE modification to it and repeat the above. The idea isnt so much to fix your **** mousetrap, but to LEARN what you are doing. A couple of big giveaways that you dont try and learn how to program, the first is the statement that you see X or Y in a lot of code. When you read someones code and intend to use it, read through it and draw out a flow diagram for it (only until you know what your doing), this will quickly identify stupid use of things like the else statement above.

Dont get me wrong i havnt a clue with SF, but the moment i find another USB for the junebug (dog has chewed mine lol) I will be learning and teaching my LS, or more likely she will teach me. She is a absolute natural at it (well C anyway), i a not sure if its her age as around her age the brain changes, but whatever it is she reads C code and just understands it the same way you understand a normal conversation, she dosnt understand data sheets which is where i come in.

But all I do is tell her what the reg or bit is called and what it for, and off she goes. Its the same with spoken language, she has 3 friends and they decided 8-9 weeks ago to learn to speak Spanish for fun, using you tube all of them can hold a decent conversation in Spanish!! 8 seems to be a golden age to learn, by 12 it dwindle off alot, i notice it in the club/class i run at her school. From 8 - 10/11 they soak information in and it sticks like concrete, by 12 they seem to struggle more.

Her dream is to be a fashion designer but she likes doing crafts and anything interesting, she just seems to enjoy new skills. She can drive the small tractor but my mum wont let me teach her to drive the landrover in our field :(
 
I write short routines first then run to see if it works as planed then include it into my trial code. I grabbed the wrong code out of 8 different ones.
 
delete those that dont work, build your code as you go, you dont write short routines at all, you cut 'n' paste what can find then try and glue it together with random characters. Its time to admit to yourself your way dosnt work.

You need to start reading the code you use, things like the else issue mentioned above should have picked up. Same with the OSC pin that checks if the OSC is stable, learning what are basic registers to read and what you should write to is 101 stuff you have to learn. The most common one thats mentioned is you trying to write to a input, again a clear sign you dont read the code first and mentally work out what the code is doing.
 
....As for the ELSE statement in # 50, have seen this in lots of code examples. not really needed but....

MrDEB, the question of writing to input pins aside, I'm curious what problem you think you are solving with:

Code:
  IF Position1 = 0 THEN
          .....
     ELSE                                 
         Position1 = 1        
End If

What value do you think Position1 can be? The only way the ELSE statement will be executed is if Position1 is NOT EQUAL to zero. But if it's NOT EQUAL to zero, what MUST it be? Position1 is a single bit. The only option for its value is 0 or 1.

This code does nothing. The only thing it can achieve is to create an error. Do you have so little understanding of programming that you can't understand this? Or is it innate stubborness?


Regarding writing to inputs. You say you are writing to them so you know what value they are? Guesss what? You're fooling yourself. Let's say you have a stuck switch to ground. You write a 1 to the port pin. You know what value the port pin will be? ZERO, because it's the state of the port pin, not what you wrote to it. Again, a gross lack of understanding? Or stubborness?

Yes, you may have seen this in programs before. But only programs you have written because anybody who knows what they are doing wouldn't do this. It is wrong. And it is stupid.
 
IF Position1 = 0 THEN
I'm happy
ELSE
I'm sad LOL Some one pushed my button :banghead::banghead:
End If
 
Last edited:
IF Position1 = 0 THEN
I'm happy
ELSE
I'm sad LOL
End If


Some are happy with any position ;).

Which brings me straight in to encoders.......Does SF have an encoder lib? I cant find the part number at the moment, but i have a really odd encoder that isnt playing ball! Also i have never seen an encoder with 6 wires??
 
Which brings me straight in to encoders.......Does SF have an encoder lib? I cant find the part number at the moment, but i have a really odd encoder that isnt playing ball! Also i have never seen an encoder with 6 wires??

In an epic forum thread worthy of MrDEB, I talk about a project I did a few years back, Breaking Wine Glasses Acoustically. In that project, I used a rotary encoder from a VCR remote control to control an oscillator module. I believe I used a include module with the encoder. I will check when I'm near the computer a little later.

If you want to see a video of a wine glass going into resonance and shattering, there's a link on the last page of the forum thread. It is amazing to see how much the rim of the glass flexes before shattering!
 
I will check that out!! As mentioned in another thread, i am looking at cell fracturing using ultrasonics or resonant frequencies. Some cells are easy and others flex and mishapen but dont seem to fracture. The other big surprise was the wide range of frequency involved, in a cell you would think the frequencies would be pretty close each other. That would open a whole new area of research for things like cancer treatment if each cell type had its own frequency.

But that kind of stuff is way out of my league!! no nobel prize this year then for me :p
 
Looking at the program code, I found this:

SmartSelectImage_2018-05-11-06-58-39.png


Searching "Swordfish Basic Dialencoder.bas"
took me to the Swordfish module page. Sometimes you just need to know what you're trying to find.
 
I will check that out!! As mentioned in another thread, i am looking at cell fracturing using ultrasonics or resonant frequencies. Some cells are easy and others flex and mishapen but dont seem to fracture. The other big surprise was the wide range of frequency involved, in a cell you would think the frequencies would be pretty close each other. That would open a whole new area of research for things like cancer treatment if each cell type had its own frequency.

But that kind of stuff is way out of my league!! no nobel prize this year then for me :p

Interesting idea. Eric (my partner) is disappointed every year when he doesn't get the call from the Nobel committee.
 
Your right, half the battle is knowing where to look! I also dont get much time to spend on SF, i hope to grab some time this weekend. Its still a battle of wills with me and the school over who should buy the first full license! I might bluff it and find a different approach. Free version would have been fine for the demo, except the board we are using this year will need SD Card support.
Looking at SF it would suite the younger kids better, less work for me to build modules for the custom boards we use, the older kids are used to sil labs and GCC compiler, so they should also be ok with basic.
 
For rotary encoders I normally use this,
Code:
        const char lookup_table[] = {0,-1,1,0,1,0,0,-1,-1,0,0,1,0,1,-1,0};
        DecState<<=2;
        if(DecA1)
            DecState+=2;
        if(DecA2)
            DecState++;
        DecState&=15;
        Pos+=lookup_table[DecState];
It uses the current and previous states of A and B (DecA1 and DecA2 above) to make a 4 bit number and uses that to index into the lookup table.

Mike.
 
For rotary encoders I normally use this,
Code:
        const char lookup_table[] = {0,-1,1,0,1,0,0,-1,-1,0,0,1,0,1,-1,0};
        DecState<<=2;
        if(DecA1)
            DecState+=2;
        if(DecA2)
            DecState++;
        DecState&=15;
        Pos+=lookup_table[DecState];
It uses the current and previous states of A and B (DecA1 and DecA2 above) to make a 4 bit number and uses that to index into the lookup table.

Mike.
Thanks Mike thats handy! Also the 6 wires finally slowly (very slowly) dawned upon me and a sudden revelation took place, or in other words..........I stopped being thick and worked it out :D.

Edit, i have ordered a different encoder, he one that came feels a bit notchy, and not in a good way, BTW mike thats a real nice elegant way to do it, saves huge amounts of code compared to what i had in mind :D.
 
Last edited:
Well this project code has grown to massive size(the Bullit portion of it only), 3615 bytes and 38 variables with 14 sub routes BUT I finally have a code that basically does what it is supposed to do. Now to add in the game selection routine and the Mexican train routine.
I have several extra PCboards if anyone wishes to assemble then play. You pay shipping only.
 
What's a "sub route"? Is that an unintended path through your code that gives unexpected results?
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top