PDA

View Full Version : PIC device + PICBasic recommendation



Llamabob
5th January 2007, 17:41
Hello,

I've got a project that I've been working on part time for about 2 years, and I'm finally serious about finishing it, which may involve me scrapping my other uC approach with their assembly / C environment and going to something more productive like PICBasic.

My delima is that I "think" I need at least four 16-bit timers, which from what I've seen is beyond the peripherial mix of the 8-bit PICs. I've never used a PIC before, so any suggestions would be greatly apprecited.

What I'm trying to do is measure two positive digital input signals that range from 0.7mS to 2.3mS in width, which repeat every 50mS. I also have two digital outputs, where I produce a similar signal... ranging from 0.7mS to 2.3mS every 50mS. Sometimes the output signal's values track the input signals values, and other times, the uC will output its own value independent of input, still within that range.

I've tried using an 8-bit hardware timer on each input and output to do this, but 256 steps are too large, and my box would introduce quantization noise into the system. So currently, I use a 16-bit timer/counter on each input and output. With this approach, I'm stuck with a requirement of four 16-bit timers / counters, which is beyond the 8-bit peripherial mix of the PIC from what I've seen.

With the non-Pic 8-bit uC that I used, to minimize the number of counters, I also tried an approach using a single counter, enabling the input pin interupts, then doing a time-stamp on each pin transition, then on the trailing edge, calculating the pulse width. With that approach, there was unacceptable jitter between the input and output.

Any recommendations that would keep me in the 8-bit world using PICBasic would be appreciated.

Thanks!
Bob

Tim
6th January 2007, 00:28
Hello Bob

if I understand your requirement right, your looking to time two input signals and output two signals.

Lets look at the timing of the 2 signals for starters

I take it you generating an interrupt on the change of the signal and starting / stopping the time on the change back. As you will probably be aware there are a number of ways to do it, but here is some more food for thought.

1 set up the inputs to RB.0 and RB.1 and config the interrupt on the rising edge of each, Then when you get an interrupt you can look at the source and start the timer. Config the interrupt to go off on the falling edge and leave. Then next interrupt look if the interrupt was the other source or the new source and start / stop / record the time as required.

The accuracy will be dependent on the timing of the changes, the speed of your code to handle 2 at once etc and the xtal.

Another option is to take out the xtal /4 from the pic and feed it back into the timer which is set up as a counter. The signal gates this clock pulse in via a transistor etc and also is linked to an input. In your prog you look at the state of the input and if its say low and not letting the clock through you know you can read the value in the timer and get an accurate value.

The first version will time the both sides of the signal the other only one.

Any way your looking at 2 timers.

The 18Series pics I have seen have up to 2 x 8 bit and 3 x 16 bit timers so you have used 2 of your 3 so far.

The output timers could be either 16 bit or you could implement an 8 bit to interrupt on roll-over and count the roll overs your self. Not that elegant but do able.

It all comes down to the accuracy you require as there could be a situation were you have all 4 timings happening at once and that means you could be up to 50 us out on the last one.

I think this is a situation were you keep the discussion going and every body sticks an idea in and you take the best.

If you have any more info then post it. Knowing more about your requirements will make the solution easier to find.

fanie
6th January 2007, 01:19
going to something more productive like PICBasic

Haven't looked back yet !

Great explanation Tim !! Wish I knew so much...

Llamabob
6th January 2007, 12:42
Thanks Tim,

That is good food for thought. On the inputs, I currently do them like you describe in your first paragraph... interrupt on rising edge, start timer, interrupt on falling edge, stop and record the width.

One thing I've tried on my other processor, that might work better on the PIC is to use a single 16-bit free-running timer for both inputs. On a positive edge interrupt, check to see which pin did it, then store the current 16-bit timer value for that pin. On the falling edge, see who did it, store the current count for that pin, and set a "ready" flag. This sounds like it could be fast and "deterministic".

Then in the main loop when you've got a lot more spare time, check for the availabilty of a new input value by polling the flags, and only then, do the subtraction between ValueA = ABS(Count2A-Count2B).

On my other processor, it had real issues trying to read a timer on the fly. It would actually have to do a lot of page-mode stuff just to get to the timer from an IRQ, then stop the timer first to do the read. It was awkward.

-----------

Okay... I'm going to buy PICBasic and try this out on the 18 series PIC.

What is a good eval board for the 18 series? I've seen some on Microchip's site, and I've seen some 3rd party ones with keyboards and LCD screens.

Thanks!!!!!!!
Bob

Tim
6th January 2007, 13:49
When you use the 18series Pic you can config the timers to do a no stop read on the timer

Once set up you do a read on the low byte this also at the same instance reads the high byte and places the result in the high reg. Like this

DIM MYREG AS WORD

MYREG.BYTE0 = TMR1L
MYREG.BYTE1 = TMR1H

If your doing a lot of reads to the same variable you could make a macro

macro ReadTmr1
MYREG.BYTE0 = TMR1L
MYREG.BYTE1 = TMR1H
endm

Then just type ReadTmr1 every time you want to do the read.

Depending on how serious you are to finish the product I would consider getting ISIS VSM for the 18 series. You can sim the pic with loads of signal coming in and scopes on the out side. Then you can really get the timing down to a fine level.

I'm not sure what route I would take to do this, its a matter of the accuracy you need. Setting one timer running and just logging the tmr result at the time of the signal change will be as quick as having 2 timers.

So thinking on it I would probably time with the one timer (say tmr0 in 16 bit mode) and then use tmr1 and tmr3 for the outputs

Remember in the main prog to look for the roll over flag on the input timer and account for it in the maths.

Lastly when you write your interrupt code, do it all in basic don't bother with asm. I recommend if you can read asm compile your code and hit F2. You will soon learn what the compiler is doing and feal confident that its writing great compact code.

Cruster
6th January 2007, 15:15
What is a good eval board for the 18 series? I've seen some on Microchip's site, and I've seen some 3rd party ones with keyboards and LCD screens.
Bob

http://www.crownhill.co.uk/product.php?prod=366
http://www.mikroe.com/en/tools/easypic3/

Llamabob
6th January 2007, 15:42
Does this sound like a good setup? Is there anything additional that I might need?

1. PDS Proton Development Suite
2. Proteus PIC18 Proteus VSM for PIC18 (Is this ISIS?)
3. Zif_40 40 Pin Zif Socket
4. ProtonLCDGLCD Proton Development Board - with LCD & GLCD (does this work with the 18 series?)

I've got that round red emulator from Microchip. Not sure if I'll need it.

I appreciate everyone's help !!

Thanks!
Bob

Cruster
6th January 2007, 15:49
Does this sound like a good setup? Is there anything additional that I might need?

1. PDS Proton Development Suite
2. Proteus PIC18 Proteus VSM for PIC18 (Is this ISIS?)
3. Zif_40 40 Pin Zif Socket
4. ProtonLCDGLCD Proton Development Board - with LCD & GLCD (does this work with the 18 series?)

I've got that round red emulator from Microchip. Not sure if I'll need it.

I appreciate everyone's help !!

Thanks!
Bob

Sounds great - virtually identical to what I have.

1). PDS, you won't find better..
2). VSM is the simulator, ISIS is schematic capture.
3). Saves wear & tear on the 40 pin DIL socket
4). Certainly works perfectly with the 18F452!

You might want to consider taking a look at Tims in circuit debugger. It's certainly cheaper than VSM..

http://www.p-icd.com/

.. it integrates nicely within PDS (as does VSM)

Llamabob
6th January 2007, 17:38
I just pushed the button, and now I'm the proud owner of all of this stuff.

I guess I can't post anything in the pre-sales area anymore. :)

Thanks for everyone's help !!!

Bob

Cruster
6th January 2007, 17:48
I just pushed the button, and now I'm the proud owner of all of this stuff.

I guess I can't post anything in the pre-sales area anymore. :)

Thanks for everyone's help !!!

Bob

Hey! Welcome on board!! :D

Tim
6th January 2007, 18:49
Hope I'm not to late

These days your hard to beat the Microelektronica boards for value. Available in the USA from http://circuit-ed.com. Don't bother with the ME compilers though...

However the problem with them is they look great with all those buttons and LED's but in reality you never use them so the only benefits are the built in programmer and USB socket etc. But I have to admit there very hard to better.

I have a MK1 Proton board and its still my no 1 dev board as it has the bread board.

However in real life I develop it all in the VSM and them make the end board. I very rarely use a dev board.

For the job you want to do I would stick with the VSM my ICD will be no good in that application.

If you change you mind on anything just send a mail to Crownhill the order will not be processed until Monday.

If you got the VSM and go to use it and have any questions come back here and I will answer any you have or start you with a basic board for your application.

Llamabob
6th January 2007, 21:35
However in real life I develop it all in the VSM and them make the end board. I very rarely use a dev board.

Sweet! I'd like to have the tools and experience to have that confidence.

I do like the MKii Proton board design because the breadboard seems a little more practical to me.

For the MKii board, I did a parameter search on the 18-series parts, and there's no 40-pin DIP part that has 3x16-bit and 2x8-bit timers. However, the PIC18F4685 has 3x6-bit and 1x8-bit, which may work in this board.

If I absolutely needed 3x16-bit and 2x8-bit timers, the smallest package is a 64-pin TQFP. That might necessitate me getting a Microelektronica BigPic4 board with the PIC18F8520.

Does that sound right?

Thanks,
Bob

Tim
6th January 2007, 22:46
Are you sure you need 2 x 8 bit?

If yes then a PIC18F8520 is a good choice especially as it is modelled in isis

Llamabob
7th January 2007, 03:11
I might only need one 8-bit. I was needing to generate an interrupt every 50mS for the output to do its thing.

Bob

Tim
7th January 2007, 11:18
Tmr 2 is a an 8 bit timer and has a pre scaler 1:1 1:4 and 1:16 you can combine that to match with PRT value and then on every match that can go through a postscaler that is 1:1 1:2 ....... 1:16

I doubt you will match it to exactly 50ms but you should get it close.

fanie
7th January 2007, 13:36
Eh Bob, now that you have all these nice and fancy equipment do you think you could develop... OOH gotta go, food's ready !

Llamabob
7th January 2007, 13:49
I'll let you know how confident that I am once I get the BLINK_LED program to work. :)

Bob

Richard
7th January 2007, 14:05
I have a MK1 Proton board and its still my no 1 dev board as it has the bread board.
If this (http://www.picbasic.org/solderless_dev_system.php) is a MK1 board, then it is my favourite too.

I like it because it only has the essentials - i.e. power, serial, reset & bootloader

Cruster
7th January 2007, 14:39
However in real life I develop it all in the VSM and them make the end board. I very rarely use a dev board.

Tim, are you saying that you go straight from the VSM directly to a PCB? Is most of your stuff of a digital nature or is it analogue?

Reason I ask is recently I had a high gain instrumentation type circuit & breadboarding it revealed a sensitivity to supply noise which I hadn't considered & wasn't immediately obvious, so a bit of a rethink was in order!

It wouldn't have been something which I'd have thought to simulate for so had I gone straight from VSM to PCB I'd have a problem.

Tim
7th January 2007, 14:58
I go from VSM to first stage real layout. Most of my stuff is digital, but where I have analogue elements and find an issue I might see something on the scope and then go back the VSM to introduce that noise into the system via a signal generator and some logic to see how the code copes.

My main work is coding and where others will put some smoothing onto a signal I will do it by over sampling. This is not because its correct but because like the analogue crowd they tend to fix things with hardware as they understand that side more I understand the code side better.

Ultimately it always takes more than 1 or 2 attempts to get the design right before you press the button and buy loads of boards.

So a point for others Never Never think its worth while buying loads of boards then try and fix it with code later, make 1 or at most 2 then find the errors and and log them for the next revision. So many people I see say "Well I have 100's already made and need it to work with the boards I have"

What I like about the VSM (aside from sim'ing the noise) is that the design cycle reduces to seconds on a design change.

Want to add a eeprom, no need for bits of wire all over the place just paste it on the VSM and your away.

Want to find out what's actually being stored on the Epprom? Just click a pull down and its there.

I know I go on about it all the time but once you understand just what can be done with the VSM you would be amazed.

Labcenter should make videos of a development/sim in action so you could really see for your self.

Tim
7th January 2007, 15:09
As an example of the use of the VSM and Proton, I did a little board to display a message on a 5 x (5 x 7) dot matrix led were the message scrolled vertically. (Apparently its ending up in the science museum)

So I developed it entirely in the VSM using a 18f1220, 74hc959's and the 5 x7 led dot matrix's.

The code took about 2-3 days and even simulated the storing of the messages in Program memory. This was all done with out any hardware present.

Once the basic code proved the wiring was correct(day 1) I got the PCB done, That took about a week and a bit to go from design to boards on my desk using Crownhills Proto pcb service.

If I had used the normal design cycle the whole thing would have taken at least 3 weeks, something the client could not afford.

fanie
7th January 2007, 15:13
Aparently the analog components you can simulate with the VSM is simulated quite good providing the component is supported, acording to users. Over 6000 analogue and digital device models supported... view then here http://www.labcenter.co.uk/index_uk.htm

Richard
7th January 2007, 15:17
using Crownhills Proto pcb service.
What do they charge ?

I'm paying about 50 for 3 60mm x 50mm from PCBPool's 8 day prototype service (too complex to mill on my machine).

Cruster
7th January 2007, 18:53
Aparently the analog components you can simulate with the VSM is simulated quite good providing the component is supported, acording to users. Over 6000 analogue and digital device models supported... view then here http://www.labcenter.co.uk/index_uk.htm

Yes, I've got VSM. :)

I was more wondering how Tim found going directly from it to PCB as usually I tend to breadboard first.

In the simulator, I wouldn't have thought to inject noise into my circuit at the point it was actually being picked up from. That info came from breadboarding the design.

VSM definitely has its place & I don't think there's anything else around which quite touches it. I do feel though that you need a little "apriori" knowledge (or experience) in order to get the best out of it.

A little like first using digital scopes where it helps in the initial "setting up" if you already know what it is you expect to be seeing... been caught out there before.

fanie
7th January 2007, 23:48
Chris,


how Tim found going directly from it to PCB

I think Tim has a lot of faith to trust that the VSM won't let him down and probably enough experience to know what to expect from his design, also it probably depends on the complexity of the circuit, in some app's you may want to breadboard or maybe just test a portion of the circuit, others you don't have to.

Cruster
8th January 2007, 00:37
Chris,
I think Tim has a lot of faith to trust that the VSM won't let him down and probably enough experience to know what to expect from his design, also it probably depends on the complexity of the circuit, in some app's you may want to breadboard or maybe just test a portion of the circuit, others you don't have to.

- and you use VSM or any simulation software?

Llamabob
13th January 2007, 16:55
I received my package of goodies last night.

Proton Development Suite
PIC18 Proteus VSM for PIC18
Proton Development Board

The UPS driver came by Friday but my wife was away, so we found where their hub was, and I drove 50 miles to pick it up at 7:00pm, so I could play with it this weekend.

I'm very impressed. I'm already doing some fairly advanced (for me) simulation of my application.

Bob

Mark Rodgers
14th January 2007, 02:57
The VSM is quite fabulous and will be worth any money you have spent on it, don't get fed up with its "quirks"(I am sure there is still some DOS code in there!) ask on here for any help, you will get better sense than F1(from Tim at least!)
Watching 2 pics talking to each other and showing stuff on their individual displays is amazing, also the best trick I have seen is to use a simulated pic connected to the COMPIM component and control an external bit of real RS232 hardware from totally virtual parts running virtual code in the simulator and plugged into the PC serial port.
WOW!

Enjoy.

fanie
14th January 2007, 11:39
Chris,


and you use VSM or any simulation software?

After about 20 years of designing stuff you start to get a feel for some things, for instance if you have a signal that needs amplification you already know what the circuit is going to look like... I can even make the layout without a schematic in some cases. I'm not claiming to be mr wonderfull or claiming I know it all - far from it - but one also tends to use the same setups that worked well in the past for newer designs also.

I also make a point of finding out how things work - exactly and specifically ! If I use a component it's almost as if I can 'see' how it is working - in most cases if you specifically understand the working of the peripheral components you also know exactly what the software should do to make the app work and then to do that is simply a matter of applying the commands.

I'm currently playing with the VSM, trying to get to terms with the way you use it. I think we get spoiled with the ease and logic some apps works and then you use something like the VSM and then you have to get 'used to' . Just try to work with CNC stuff creating toolpaths and such, these guys are screwed, good grief, there's no logic in the sequences they do anything. But as Mark say, don't get fed up with its "quirks" , the end result is what counts.

If I find the VSM is going to have an advantage for me I'll buy it of course, couldn't get the demo working before day before yesterday, then the switches won't work and then I discovered you have to select it in the left pane to work, you know... quirks !

There is only one major (in my opinion) drawback with the VSM and that is that an unsupported component that cannot be simulated otherwise may render the VSM useless. There are 4 components required to simulate 3 of my projects, without them I cannot simulate anything. They are all general and usefull components, the AC motor probably the most common... What ? no AC motor ! Might have saved Tim a bunch of time. I require two of Holtek's DTMF chips otherwise I cannot simulate one project at all... and it doesn't seem like Labcentre is responding too eager on the topic.

Then there's the price... multiply with 14.2 and you know what it is it's costing me. Yes it's different, you UK guys work 1:1 we have to x with 14.2. Will you buy it if the price is x 14.2 ? Just checking. Big decision.

Tim
14th January 2007, 14:07
In relation to the VSM. It's not for everybody, if your an analogue person and looking for strange behaviours in a circuit then its not for you. If how ever your using to to write code that's timing critical then its brilliant.

You should not think you will wire up the whole circuit exactly and then run the VSM and it will simulate it 100%.

I use it to simulate code and how it interacts with simple hardware. I do not know what its like at analogue as I never use it like that. But you could pay 1,000 more for a very high spec system and then not be able to sim your code.

Psymiley
15th January 2007, 13:35
Hope you don't mind me jumping in here - but has anybody used the 'starter' VSM by Proteus?
I'm looking at the 'Starter Kit' (with only 16F84, 16F877, 18F452 models). Do you still have free range with LCD's and other componants (resistors, etc), but JUST limited to the 3 uC's?
Can I use multiples of them too? (i.e 2 16F877's to talk to each other).

:)

Mark Rodgers
15th January 2007, 20:07
You will get all the functions of simulation (lcd, glcd, analogue etc) with only the PIC types you mentioned able to run code, a "full" licence will just give you many more PICs.

With the 877 you can simulate a huge portion of the 16F internal modules(and 12F) so developing the code for a 12F683 for instance can be done in an 877 if you then change the device specific registers at program time.

The modules in the PICS are very similar and for many(not all by any means) programs you write just using BASIC (and not register bashing ) the code produced by PDS will modify the parts that are different and your code will run.

Its not as convenient as the correct PIC but works well under lots of circumstances, it is a very enjoyable tool to have!

wsqiaa
26th June 2010, 18:57
moiD8e <a href="http://xwniygcelxbs.com/">xwniygcelxbs</a>, brqwoxfrverv (http://brqwoxfrverv.com/), qjzhtcqiqubl, http://chxbncwvcfxb.com/

Secoroco
2nd September 2010, 19:51
Dear Tim,

I just bought a Proton Development Suite IDE Program and I want to generate the *.HEX file by using PIC18F8520 but it shows me an error. Do you have an idea why this is happening?

newuser
2nd September 2010, 21:28
PIC18F8520 may not supported yet

SimonJA
2nd September 2010, 22:09
I think the 18F8520 is supported and has been for a while.

Which version of the <link rel="File-List" href="file:///C:%5CDOCUME%7E1%5CSimon%5CLOCALS%7E1%5CTemp%5Cmsoh tml1%5C01%5Cclip_filelist.xml"><!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:PunctuationKerning/> <w:ValidateAgainstSchemas/> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:Compatibility> <w:BreakWrappedTables/> <w:SnapToGridInCell/> <w:WrapTextWithPunct/> <w:UseAsianBreakRules/> <w:DontGrowAutofit/> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> </w:LatentStyles> </xml><![endif]--><style> <!-- /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:"Times New Roman"; mso-ansi-language:EN-GB;} @page Section1 {size:612.0pt 792.0pt; margin:72.0pt 90.0pt 72.0pt 90.0pt; mso-header-margin:36.0pt; mso-footer-margin:36.0pt; mso-paper-source:0;} div.Section1 {page:Section1;} --> </style><!--[if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;} </style> <![endif]-->compiler do you have installed and what is the error?

John Lawton
3rd September 2010, 17:47
If you want 4 x 16 bit timers, the 18F45K22 does the job, and is currently supported by Proton and the U2 programmer with the latest PC software.

John