![]() | ![]() | ![]() |
| | |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
| | LinkBack | Thread Tools | Display Modes |
| | (permalink) | |
| Hi all, Im currently playing around trying to make a device which outputs a certain pulsetrain. The output needs to alternate, being high or low for exactly one or two milliseconds. I have so far tried a PICAXE-18, but the actual pulses from this are more like 1.3ms output for a 1ms pulse in code and 2.5ms pulse output for a 2ms pulse in code. This was due to the timing inaccuracies in the Picaxe. here is a snippet of my code: Quote:
Thankyou Jamie | ||
| |
| | (permalink) |
| Just use any PIC - as long as it has an external crystal oscillator, a 16F628 (which I think is what the PICAXE18 uses) would be fine. Running with a 4MHz crystal would give you accurate timing to within a few uS, running at 20MHz to below 1uS. Depending how stable (and accurate) it needs to be, the 0-50C temperature range will cause the oscillator frequency to vary slightly, if you need very high stability it's common to use a crystal oven to prevent temperature drift. However, it doesn't sound like that degree of accuracy is likely to be needed. | |
| |
| | (permalink) |
| Nigel, Thanks for the reply, Yeah, I did use the PICAXE-18 with an external 4mhz osc, but the timing was off quite a bit. I posted a question on the picaxe forum, and many other people also saw the same inaccuracies in the picaxe timings, when connected to a 'scope. Thats why im looking at alternative micro's that would be more accurate, possibly with uS resolution, so i can fine tune my program to work. The device the pulse train is fed to will only work with the correct pulse train, and when I tested with my Picaxe circuit, it would not function. When re-tested with the correct module (providing the pulsetrain) worked fine. Jamie | |
| |
| | (permalink) | |
| Quote:
Don't use a PICAXE - use a PIC!. Any interpreter isn't going to be fast or accurate enough - your program requirements are extremely simple, and you can always trim your delays to within 1uS (with a 4MHz clock) by simply adding NOP instructions (1uS each). It would be very simple to write in assembler - you can even find a delay code generator on the PICLIST at http://www.piclist.com. | ||
| |
| | (permalink) |
| Thanks Nigel, I've got a handful of 16f84's here so I'll give one a go... I've never programmed in C or ASM before, but i'll try suss out some sample code and go from there. Thanks again Jamie | |
| |
| | (permalink) | |
| Quote:
Looking at your existing code, you could simply do this (which is only a small segment): Code: Start: bcf PORTB, 1 ;set pin low call Delay1 ;delay 1mS bsf PORTB, 1 ;set pin high call Delay2 ;delay 2mS bcf PORTB, 1 ;set pin low call Delay1 ;delay 1mS . . . . goto Start | ||
| |