Author Topic: mikroe basic  (Read 16065 times)

0 Members and 1 Guest are viewing this topic.

Offline Simon

  • Global Moderator
  • *****
  • Posts: 14215
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
mikroe basic
« on: November 06, 2011, 03:31:11 pm »
So i use mikroe basic. But i have noticed something. If I use the PWM routines I can only get 8 bits resolution and not 10 on chips that support this (12F615 or 16F88). Now i know that for a full 10 bit resolution the chips use one 8 bit register and 2 bits of another register. if I put say 512 in as a value it goes to 100 or 0% (can't remember was a while since i noticed it). It's like the compiler runs the number round and round and gets back to the remaining value out of 255. 255 gives 100% duty 127 gives 50%.

I assume at this point that if i want to use 10 bit resolution I need to write straight to the register directly and forget the PWM comands in the compiler.
https://www.simonselectronics.co.uk/shop
Varied stock of test instruments and components including EEVblog gear and Wurth Elektronik Books.
Also, if you want to get ripped off: https://www.ebay.co.uk/usr/simons_electronics?_trksid=p2047675.l2559
 

Offline mobbarley

  • Regular Contributor
  • *
  • Posts: 200
  • Country: au
Re: mikroe basic
« Reply #1 on: November 08, 2011, 02:54:13 pm »
I use MikroC and find that their routine for adjusting the PWM chews a lot of program space (or it did pre-MicroC Pro).. I often just set the registers directly - its simple enough but you lose some hardware abstraction.
 

Offline Bored@Work

  • Super Contributor
  • ***
  • Posts: 3932
  • Country: 00
Re: mikroe basic
« Reply #2 on: November 08, 2011, 05:21:48 pm »
MikroE compilers aren't known for their quality. I recommend you look at other options, even if they appear to "suck" at first sight.
I delete PMs unread. If you have something to say, say it in public.
For all else: Profile->[Modify Profile]Buddies/Ignore List->Edit Ignore List
 

Offline GrumpyDave

  • Contributor
  • Posts: 24
Re: mikroe basic
« Reply #3 on: November 08, 2011, 05:28:48 pm »
What frequency are you running the PWM at?

You will probably find 10 bit PWM only works at quite low frequencys.

There is usually a formula in the datasheet somewhere to calculate how many control bits you can use for a given clock frequency and prescaler etc...
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 14215
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: mikroe basic
« Reply #4 on: November 08, 2011, 05:49:32 pm »
MikroE compilers aren't known for their quality. I recommend you look at other options, even if they appear to "suck" at first sight.

can you suggest any others ? I suck at programming never mind finding the right tools.

I forget the frequency but when 255 produces 100% something is wrong, if anything at 10 bits (1024) it should produce 25%, the resolution does not even come into this it is a misinterpretation by the compiler
https://www.simonselectronics.co.uk/shop
Varied stock of test instruments and components including EEVblog gear and Wurth Elektronik Books.
Also, if you want to get ripped off: https://www.ebay.co.uk/usr/simons_electronics?_trksid=p2047675.l2559
 

Offline FreeThinker

  • Frequent Contributor
  • **
  • Posts: 791
  • Country: england
  • Truth through Thought
Re: mikroe basic
« Reply #5 on: November 08, 2011, 06:00:08 pm »
Try http://www.oshonsoft.com/ and download the pic sim of your choice. It has a very nice basic and a PWM module for stepper control etc. And it's quite cheap.
Machines were mice and Men were lions once upon a time, but now that it's the opposite it's twice upon a time.
MOONDOG
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 14215
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: mikroe basic
« Reply #6 on: November 08, 2011, 06:18:42 pm »
But I'm looking for a compiler not a simulator
https://www.simonselectronics.co.uk/shop
Varied stock of test instruments and components including EEVblog gear and Wurth Elektronik Books.
Also, if you want to get ripped off: https://www.ebay.co.uk/usr/simons_electronics?_trksid=p2047675.l2559
 

Offline FreeThinker

  • Frequent Contributor
  • **
  • Posts: 791
  • Country: england
  • Truth through Thought
Re: mikroe basic
« Reply #7 on: November 08, 2011, 06:30:43 pm »
But I'm looking for a compiler not a simulator
It is also a basic complier and generates hex files you can load into your pic as normal
Machines were mice and Men were lions once upon a time, but now that it's the opposite it's twice upon a time.
MOONDOG
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 14215
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: mikroe basic
« Reply #8 on: November 08, 2011, 06:35:54 pm »
ah right, might take a look then, i did come across it before but thought it was a simulator only
https://www.simonselectronics.co.uk/shop
Varied stock of test instruments and components including EEVblog gear and Wurth Elektronik Books.
Also, if you want to get ripped off: https://www.ebay.co.uk/usr/simons_electronics?_trksid=p2047675.l2559
 

Offline gregariz

  • Frequent Contributor
  • **
  • Posts: 547
  • Country: us
Re: mikroe basic
« Reply #9 on: November 08, 2011, 07:22:46 pm »
MikroE compilers aren't known for their quality. I recommend you look at other options, even if they appear to "suck" at first sight.

can you suggest any others ? I suck at programming never mind finding the right tools.

I forget the frequency but when 255 produces 100% something is wrong, if anything at 10 bits (1024) it should produce 25%, the resolution does not even come into this it is a misinterpretation by the compiler

Are you doing any math with the numbers? I like their compilers, I think they are the best documented on the market right now but I've had problems with their floating point library and I haven't been able to pinpoint what is going on. I suspect some of their routines don't clean up properly. I run their keypad, lcd and adc routines inbetween doing some simple arithmetic and find that the numbers are not adding up. Quite a few people on their forum have questioned that library, but again no-one has been able to pin down whats going on. I use CCS C quite a bit now.
 

Offline ChrisKiwi

  • Contributor
  • Posts: 41
  • Country: nz
Re: mikroe basic
« Reply #10 on: November 09, 2011, 01:14:12 am »

can you suggest any others ? I suck at programming never mind finding the right tools.

I forget the frequency but when 255 produces 100% something is wrong, if anything at 10 bits (1024) it should produce 25%, the resolution does not even come into this it is a misinterpretation by the compiler

I have used Pic Basic, then upgraded to Pic Basic Pro when it was released see melabs.com  There is also a forum http://picbasic.co.uk/forum/index.php  Some of the people there have done some really good stuff in terms of sample code and templates, particularly around time slicing and interrupts.  I don't use it much these days (not for the last two years at least) as I've been working with Microchip C18.  If you want to try C I'd suggest HiTech (now owned by Microchip) and this site (note the "c" on the end of microchip)  www.microchipc.com which has a lot of code examples and FAQ's
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 14215
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: mikroe basic
« Reply #11 on: November 09, 2011, 06:59:36 am »
No i was not doing any math. My code was a logical statement the result of which determined if I was going to set a higher or lower duty and I was just literally telling the software which value out of 1024 I wanted the PWM duty to be, but it would not work on a 0-1023 scale only up to 255, 255 = 100% and 511 = 100% and so on so basically the compiler was doing something funny to any value over 255 and was totaly ignoring the 10 bit capability of the PWM module. I think i may look around at other options. I'd love to learn C but I'm a bit cautious as I'm told it is more like assembly. I just want to get the job done.
https://www.simonselectronics.co.uk/shop
Varied stock of test instruments and components including EEVblog gear and Wurth Elektronik Books.
Also, if you want to get ripped off: https://www.ebay.co.uk/usr/simons_electronics?_trksid=p2047675.l2559
 

Offline gregariz

  • Frequent Contributor
  • **
  • Posts: 547
  • Country: us
Re: mikroe basic
« Reply #12 on: November 09, 2011, 07:09:22 am »
I'd love to learn C but I'm a bit cautious as I'm told it is more like assembly. I just want to get the job done.
I agree, I'm not really a C fan but these days I'll use anything that helps me get jobs done as fast as possible. My biggest gripe with most compilers is the poor level of documentation, examples and tutorials.

On that note...

http://www.ccsinfo.com/videos/quickStart.asx
 

Offline GrumpyDave

  • Contributor
  • Posts: 24
Re: mikroe basic
« Reply #13 on: November 09, 2011, 09:35:00 am »
I forget the frequency but when 255 produces 100% something is wrong, if anything at 10 bits (1024) it should produce 25%, the resolution does not even come into this it is a misinterpretation by the compiler

Then maybe you should check the frequency?

Why do you think it is the compiler that is at fault? Its sounds like you have 8 bit resolution PWM to me, load 255 into the PWM at 8 bit resolution and you will get 100% (ish).
« Last Edit: November 09, 2011, 10:08:02 am by GrumpyDave »
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 14215
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: mikroe basic
« Reply #14 on: November 09, 2011, 12:36:11 pm »
why don't you re-read my post and understand it, what you refer to is a different issue. I am telling the compiler to do one thing and it is doing something else.

if I was running at two high a frequency i would get about the right duty rounded to the nearest bit. What is happening here is that the compiler is subtracting 256 from the value if over 255 until it gets a value of 0-255 and uses that. so 256 would give me 1/255 duty. This is the compiler doing math not me.

Basically the compiler is just working in 8 bits even though the PWM module is 10 bit - not very impressive. In future i will just write straight to the register.
https://www.simonselectronics.co.uk/shop
Varied stock of test instruments and components including EEVblog gear and Wurth Elektronik Books.
Also, if you want to get ripped off: https://www.ebay.co.uk/usr/simons_electronics?_trksid=p2047675.l2559
 

Offline GrumpyDave

  • Contributor
  • Posts: 24
Re: mikroe basic
« Reply #15 on: November 09, 2011, 01:20:38 pm »
ok well sorry I did not understand your description properly in the OP. The behaviour of your compiler is described much better by your last post.

You have confused me a little with your comment regarding the frequency though.

My understanding of the PWM behaviour is that at the max bit depth modulation is at 100%, if the bit depth is lower (e.g. Higher freq) then the modulation scales?

For example
10 Bit,  Equal or rgeater than 1024 = 100%,  512 = 50%
8 bit, Equal or rgeater than 255 = 100%, 127 = 50%
7 bit, Equal or rgeater than 127 = 100%, 64 = 50%

Say you count up from zero with 7 bit depth once it reaches 127 thats 100% and above this just stays at 100% or am I wrong?

 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 14215
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: mikroe basic
« Reply #16 on: November 09, 2011, 05:28:49 pm »
ok well sorry I did not understand your description properly in the OP. The behaviour of your compiler is described much better by your last post.

You have confused me a little with your comment regarding the frequency though.

My understanding of the PWM behaviour is that at the max bit depth modulation is at 100%, if the bit depth is lower (e.g. Higher freq) then the modulation scales?

For example
10 Bit,  Equal or rgeater than 1024 = 100%,  512 = 50%
8 bit, Equal or rgeater than 255 = 100%, 127 = 50%
7 bit, Equal or rgeater than 127 = 100%, 64 = 50%

Say you count up from zero with 7 bit depth once it reaches 127 thats 100% and above this just stays at 100% or am I wrong?

Yes the problem can be a bit difficult to understand and I probably made a better bash at explaining it in my last post. It is a problem that should not be. The maximum frequency is (Fclock/4)/bit depth. So from my understanding on a 10 bit system 1023 is 100% and 511 is 50% and so on. I think that if you try to use a frequency above the maximum the module will do it but will not do it to 10 bits but you have no control here and carry on as normal. For example there is even data of like 6.5 bit depth. I am uncertain how it all works but at the frequencies i was using there would have been no problem with 10 bit depth and 255 should be 25% not 100. I think the issue is that the compiler is not considering the other 2 bits that are in a seperate register from the main PWM duty (8bit) register. All registers are 8 bit. I think what the compiler did was subtract 256 as many times as need be to get a number that is less than 255 and then uses that.
https://www.simonselectronics.co.uk/shop
Varied stock of test instruments and components including EEVblog gear and Wurth Elektronik Books.
Also, if you want to get ripped off: https://www.ebay.co.uk/usr/simons_electronics?_trksid=p2047675.l2559
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 14215
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: mikroe basic
« Reply #17 on: November 09, 2011, 05:30:34 pm »
Simon have you tried posting this in the Mikro forums?

http://www.mikroe.com/app/webroot/forum/viewforum.php?f=97

I have MikroC pro but basically I use it as abbreviated assembly I write most of my own functions rarely use any of the libraries. I’ve never had any real issues with it for 200 bucks I got a C compilier lifetime and the EASYPIC6 board with all the trimmings. Granted it isn’t the best compiler out there but for the price its good enough. The main complaints from people seem to be the libraies  they should really just unlock them so people can correct any bugs. This would probably save them more in the long run.

Yes i posted it on there, when the topic was finally approved after days it got no replies and that was over 2 weeks ago.
https://www.simonselectronics.co.uk/shop
Varied stock of test instruments and components including EEVblog gear and Wurth Elektronik Books.
Also, if you want to get ripped off: https://www.ebay.co.uk/usr/simons_electronics?_trksid=p2047675.l2559
 

Offline FreeThinker

  • Frequent Contributor
  • **
  • Posts: 791
  • Country: england
  • Truth through Thought
Re: mikroe basic
« Reply #18 on: November 10, 2011, 09:20:48 am »
Hmm! Sounds like a casting error. Did you define a variable for the speed? is it a word or a byte? Could be that the variable is not big enough to hold the value and overflows. Would cause the problem you are having but I would of thought that the compiler would have complained at run time but it could slip through.
Machines were mice and Men were lions once upon a time, but now that it's the opposite it's twice upon a time.
MOONDOG
 

Offline ChrisKiwi

  • Contributor
  • Posts: 41
  • Country: nz
Re: mikroe basic
« Reply #19 on: November 10, 2011, 10:23:01 am »
I'd love to learn C but I'm a bit cautious as I'm told it is more like assembly. I just want to get the job done.

No, C is nothing like assembly.  There are probably two main differences between basic (pic basic at least) and C.  In basic all the variables are global, in C you decide which are local (to the functions you write) and which are global.  In basic you have gosub's, in C you call functions that can (but don't have to) return values or have values passed to them.  The advantage of this is that you  can re use your code with out modification because any variable names in the code your reusing don't have to match the names used in your new project because only the values are passed back and forth.  For example, you write a function to do an ADC conversion:

void int DoADC_Conversion(char Chan, char other_parameters);
{
put your code here
};

then, to perform the conversion you would write something like:

my_variable=DoADC_Conversion(Channel, any other parameters relating to the adc);

So, the above line of code:
1. Calls a function "DoADC_Conversion"
2. Passes "Channel" and "any other parameters relating to the adc" to the function
3. When the conversion is complete the result is returned and stored in "my_variable"

There are other advantages in using C, such as more compact code (because you write your own functions rather than using pre-rolled functions that need to cater to many possibilities) - though Pic Basic Pro is quite efficient and things called "pointers" which can access variables in memory more efficiently.

I am only scratching the surface ..... but at the end of the day it doesn't really matter what language you use as long as you get a result that works, that your happy with

OK..... are there any code tags we can use? to format code in posts?

 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 14215
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: mikroe basic
« Reply #20 on: November 10, 2011, 12:43:04 pm »
Hmm! Sounds like a casting error. Did you define a variable for the speed? is it a word or a byte? Could be that the variable is not big enough to hold the value and overflows. Would cause the problem you are having but I would of thought that the compiler would have complained at run time but it could slip through.

It was a word variable. Actually Mikroebasic is awful at picking up errors in code or rather errors that arise from a conflict between the code and the capabilities of the processor or the code conflicting over resources
https://www.simonselectronics.co.uk/shop
Varied stock of test instruments and components including EEVblog gear and Wurth Elektronik Books.
Also, if you want to get ripped off: https://www.ebay.co.uk/usr/simons_electronics?_trksid=p2047675.l2559
 

alm

  • Guest
Re: mikroe basic
« Reply #21 on: November 10, 2011, 04:16:28 pm »
Language may not matter that much, at least if you compare C to one of the BASIC dialects used for embedded development, the standard BASIC (whatever that is) lacks lots of critical features like many forms of bit manipulation (did it even have a shift operator?), short circuiting logic operators, integer types with defined length (like stdint), pointers, etc. Compiler choice definitely does matter, however, and there appear to be more good C compilers around than good BASIC compilers.
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 14215
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: mikroe basic
« Reply #22 on: November 10, 2011, 05:16:39 pm »
Yea i am starting to think that I should consider C. My problem with learning programming languages is that they seem to make explanations too concise and move too quickly, if I can't learn the language the usefulness of the compiler is lost on me.

Any suggestions on a good, free and well documented compiler for C ? I did here tell that the micro C one is better than their micro Basic
https://www.simonselectronics.co.uk/shop
Varied stock of test instruments and components including EEVblog gear and Wurth Elektronik Books.
Also, if you want to get ripped off: https://www.ebay.co.uk/usr/simons_electronics?_trksid=p2047675.l2559
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 13412
  • Country: gb
  • 0999
Re: mikroe basic
« Reply #23 on: November 10, 2011, 06:08:39 pm »
It's probably best to follow a generic C programming tutorial before applying it to MCUs, here's a link to the one I followed before I lost interest in C.
http://computer.howstuffworks.com/c.htm

GCC is probably the best compiler for practising C on the PC and it has been ported to some MCUs too,
 

Offline gregariz

  • Frequent Contributor
  • **
  • Posts: 547
  • Country: us
Re: mikroe basic
« Reply #24 on: November 10, 2011, 06:13:18 pm »
Yea i am starting to think that I should consider C. My problem with learning programming languages is that they seem to make explanations too concise and move too quickly, if I can't learn the language the usefulness of the compiler is lost on me.

Any suggestions on a good, free and well documented compiler for C ? I did here tell that the micro C one is better than their micro Basic

Hi-Tech C
http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en542849
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf