PDA

View Full Version : Tachometer code problems.



PICy
- 29th October 2004, 17:39
Hello.

My ebay purchase came through the door this morning - A PIC programmer & PICBasic Compiler v1.44 :-)

After a lot of confusion i managed to get PBC working with CodeDesigner Lite, but i havent managed to get much further!

I have done a lot of programming in the past, and the samples i have read shouldnt be too hard to get my head around.

My first project (after the blinking light etc) is to make a tachometer. I have been reading up and think that 'pulsin' will be the best way to go, but im not sure. I am a little confused as half of the resources i have found for 'PICBasic' have either returned PBP, or other types of PICBasic. e.g. i spent a while reading up on variables, 'Dim myvar as Byte' and 'myvar VAR BYTE' didnt work, it took a while for me to realise that it probably wasnt my fault! Also, many people making tachometers have used a 'Count' command, but i dont think that exists in PBC either!

My questions are basically;

*Would pulsin be the best thing to use?
*Are variables just refered to as B0, W1 etc? (using 'Symbol' to name them)
*What happens if a number is too big to fit into a variable? Will the number overflow into the next var, or will only the left hand side be stored?


Thank you for your time!
PICy



P.S. Is it just me, or can nobody post in the mel PIC BASIC board?

Melanie
- 30th October 2004, 14:20
> My questions are basically;

> *Would pulsin be the best thing to use?

Not really although you could. Pulsin returns the PERIOD of the pulse (ie it's duration), it does not tell you how many Pulses you're going receive in any given time period. If you're going to measure a High Pulse and a Low Pulse, sum them together, you can then 'guesstimate' that your running at 'x' Hertz, but really it will be no better than a guess.

It would be better to COUNT, but since PBC hasn't got that feature (at least it hasn't in my manual), it would be more sensible to start a Clock (ie TMR1) and Count the number of pulses that are received in say 100mS.

> *Are variables just refered to as B0, W1 etc? (using 'Symbol' to name them)

Not having PBC, then again according to the manual it looks like you've only got variable B0-Bx (as Bytes), and W0-Wx (as Words). You can rename them to whatever is convenient, and I would certainly recommend you do so... example...

Symbol TachoCount = B0

See 2.8.2 in the PBC manual.

> *What happens if a number is too big to fit into a variable? Will the number overflow into the next var, or will only the left hand side be stored?

It'll roll thrugh zero and start counting all over again (ie only the relevant significant digits - be they eight or sixteen - are stored)...

eg (for a Byte)..

$FD, $FE, $FF, $00, $01, $02 etc..

or if it's a Word...

$FFFD, $FFFE, $FFFF, $0000, $0001, $0002 etc

There is no flag or other indication to say it's done so... but a bit of math will tell you if you've blown the limit...

B2=B0+B1
If B2 < B0 then goto Overflow

If you're adding two numbers together, the the sum must be 'equal to' or 'more than' that what you started with... if it's 'less than', then you've overflowed.

Melanie

PS. eBay purchases are a little tricky as I don't think you've got a supported upgrade path according to MeLabs unless the seller is an authorised Distributor.

lester
- 30th October 2004, 19:19
The mel PICBASIC forum is active for new posts now.

sorry, I did not know it was inactive untill PICy mentioned it. I thought there was no interest!

PICy
- 30th October 2004, 21:49
Thank you for your help! You have cleared up a number of issues that would have had me confused for hours :-)

On the ebay note, i plan to buy PIC Basic Pro when i get the money. It seems much better than PBC

Thanks again for your help!

mister_e
- 31st October 2004, 10:36
PICy,
i really don't suggest you to buy any at EBAY. chances are 99.9% that you'll not be able to update it after if, of course, the disk you'll receive is working.

Too many people use this crapy site to buy for cheap.... that's o.k to save money i agree. but for a program like PIcBasic Pro... see this

http://www.melabs.com/support/upgrade.htm

i think that EBAY is agood place if you want to spend money on already used stuff (sale for new one for ¼ regulare price) As i say often, it's a good junk yard

PICy
- 31st October 2004, 12:09
I didnt buy from ebay for the software, i got it for the programmer ;-)

At the time i intended to use ASM, but i thought as i had it, i may as well try it.

mister_e
- 31st October 2004, 12:47
>I didnt buy from ebay for the software, i got it for the programmer ;-)

OUF ... smart move. Wich programmer you get ?

>At the time i intended to use ASM, but i thought as i had it, i may as well try it.

you can have a free limited version of PBP there.
http://compilespot.com/startdemo.htm

May i suggest you MicroCode Studio (free version) as shell to put your code instead of CodeDesigner??

http://www.mecanique.co.uk/code-studio/index.html

regards