Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Thread Tools Display Modes
Old 6th December 2007, 04:04 AM   (permalink)
Default

Mike,

Your idea actually borders on "genius". I'm not familiar with MikroBASIC but in Swordfish BASIC it's very easy to setup one of the FSR registers to point directly at an array so you could deposit incoming characters directly into the array. Pretty cool, huh?

Code:
'  Swordfish BASIC
'
  DIM RxBuffer(256) As Byte

  FSR0 = @RxBuffer
Mike, K8LH is offline   Reply With Quote
Old 6th December 2007, 04:09 AM   (permalink)
Default

I prefer SF over mB for a lot of reasons. I started PIC's with mB and ASM, so I still run my code off some of my original stuff in mB. I am having some problems with inline ASM in SF and that's why I chose mB, because I can debug it quicker in case of problems.
wschroeder is offline   Reply With Quote
Old 6th December 2007, 04:09 AM   (permalink)
Default

Warren,

Perfect 5 cycle timing, true or false. Well done.
Mike, K8LH is offline   Reply With Quote
Old 6th December 2007, 04:19 AM   (permalink)
Default

Quote:
Originally Posted by wschroeder
This is untested right now, but it should allow simple USART RX source at any baudrate (maybe 115K should be the upper limit). The only stipulation is that the PC starts communication after the PIC has been started.

It's written presently in mikroBasic and will compile with the free version:

Code:
  While true

     While FSR2ptr < lastservobufaddr      ' FSR2 is RX servobuffer
        Do
        Loop Until PIR1.RCIF = 1           ' wait for new RX byte
;if an interrupt occurs here then the data ends up in the wrong order
        POSTINC2 = RCREG                   ' load RX byte.. when 30 bytes move on
     Wend
You have the same problem I tried to find a work around. I can't see how to solve this without disableing interrupts.

Mike.
Pommie is online now   Reply With Quote
Old 6th December 2007, 04:26 AM   (permalink)
Default

Forget the last post. The problem only occurs when you don't have file to file transfer and auto resetting of RCIF. Actually, can't a related problem occur. The interrupt reading the byte and clearing the flag, making RXREG invalid.

Mike.
Pommie is online now   Reply With Quote
Old 6th December 2007, 04:29 AM   (permalink)
Default

I was troubled by the same thoughts when I realized that the interrupt could occur at any point. The saving part is that the RCIF flag will not clear until the RX buffer is read and empty. Just in case, the ISR will finish the job....
wschroeder is offline   Reply With Quote
Old 6th December 2007, 04:37 AM   (permalink)
Default

Quote:
Originally Posted by Mike, K8LH
Warren,

Perfect 5 cycle timing, true or false. Well done.
Fortunately, hobby servos don't need the type of precisions we apply to the code. When I realize what some champion RC flyer does with a handful of parts and a 555 timer, I know I'm living in another world.

Oh.. and the stop timer thing is a Bob Ammerman trick I think.
wschroeder is offline   Reply With Quote
Old 6th December 2007, 04:43 AM   (permalink)
Default

Quote:
Originally Posted by wschroeder
I was troubled by the same thoughts when I realized that the interrupt could occur at any point. The saving part is that the RCIF flag will not clear until the RX buffer is read and empty. Just in case, the ISR will finish the job....
However, if the interrupt occus where I indicated then a byte may get inserted twice, once by the ISR and later by the following statement. The only way to stop this (I can think of) is do disable interrupts.

Mike.
Pommie is online now   Reply With Quote
Old 6th December 2007, 04:49 AM   (permalink)
Default

Quote:
Originally Posted by Pommie
However, if the interrupt occus where I indicated then a byte may get inserted twice, once by the ISR and later by the following statement. The only way to stop this (I can think of) is do disable interrupts.

Mike.
It can't. The instruction to pass the USART RXBuffer to the RX Array is a single instruction "MOVFF" and there is also a POSTINC are part of that instruction. The stored Program Counter is either at or after this instrucion when jumping to the ISR. At least I hope so...

Edit:
I took a look again.... you have a point I think... interesting.

Last edited by wschroeder; 6th December 2007 at 04:59 AM.
wschroeder is offline   Reply With Quote
Old 6th December 2007, 05:13 AM   (permalink)
Default

BTW, when you originally posted the link I assumed someone else had written the code. As it's now clear that you wrote it, can I congratulate you on a very clever and elegant solution.

Mike.
Pommie is online now   Reply With Quote
Old 6th December 2007, 05:25 AM   (permalink)
Default

Thank you. It's getting late here and I play too late and too much. If you think of a solution please post something... I'll pick it up in the morn. Amazing how a simple interrupt can throw a wrench into a good thing....

Edit:
Before I go... how about deducting a couple TMR1L cycles right before doing that instruction. You would get an error of 30 - 60 or more cycles at 100ns each out of the whole 20ms. That wouldn't hurt anybody. But it could prevent an interrupt at the wrong time. It would require a little change in how the RCIF test is done and acted upon. Just a tired thought and maybe the same problem.

Last edited by wschroeder; 6th December 2007 at 05:39 AM.
wschroeder is offline   Reply With Quote
Old 6th December 2007, 06:52 AM   (permalink)
Default

So it looks like by using the decade counter we can get away with 10 servos per pin? Damn!

Servos seem to be getting a lot posts around here lately, it's nice to have all these ideas being discussed, I was having a hard time locating a comprehensive tutorial.

Last edited by Ambient; 6th December 2007 at 06:57 AM.
Ambient is offline   Reply With Quote
Old 6th December 2007, 07:01 AM   (permalink)
Default

Quote:
Originally Posted by wschroeder
Thank you. It's getting late here and I play too late and too much. If you think of a solution please post something... I'll pick it up in the morn. Amazing how a simple interrupt can throw a wrench into a good thing....

Edit:
Before I go... how about deducting a couple TMR1L cycles right before doing that instruction. You would get an error of 30 - 60 or more cycles at 100ns each out of the whole 20ms. That wouldn't hurt anybody. But it could prevent an interrupt at the wrong time. It would require a little change in how the RCIF test is done and acted upon. Just a tired thought and maybe the same problem.
That almost works. If instead of deducting, you only read the UART if the timer has more than 20 cycles remaining. That is, you can tell if a interrupt is imminent and wait for it.

Mike.
Pommie is online now   Reply With Quote
Old 6th December 2007, 07:39 AM   (permalink)
Default

Actually, now that I think about it a little more, I can control the amount of time each servo receives a pulse from the 4017, but after the decade counter resets and I start the 1st servos pulse again, I can end up changing the carrier frequency of each servo. But can I fix this by simply using the tenth decade pin and hold it to keep the total refresh rate the same? The problem is, if the first 5 servos with the lowest PWM values, then the sixth servo will have a higher carrier freq. So will a changing carrier frequency screw up the servos?

I could fix this by just using every other channel, so 5 per 4017. That way I could control the time between each servo even being pulsed. Or I could just use two demux's might be less work that way.

Last edited by Ambient; 6th December 2007 at 07:43 AM.
Ambient is offline   Reply With Quote
Old 6th December 2007, 07:53 AM   (permalink)
Default

Ambient,

There is a more fundamental problem with the 4017 solution and that is that the total time frame will be minimum 18*1mS and maximum 18*2mS. You could use just 5 outputs per 4017 but then your frame time will be roughly 18*2.5mS.

Unless you need better than 8 bit accuracy then I think the software solution may be more suited.

Alternatively, 2 16F88 could be configured to do 9 servos each with much higher resolution. Using the internal clock, you could get a resolution of 500nS. I could help with the code if you choose this route.

Mike.
Pommie is online now   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Latest
555 servo controller? can get them working lompa General Electronics Chat 9 31st May 2007 06:24 AM
Help required with servo motor controller mayhem Robotics Chat 3 26th May 2006 04:21 PM
Auto servo controller, need help with the 555 linuxglobal General Electronics Chat 2 20th April 2006 03:52 PM
looking for servo controller circuit diagram using switch ? calico Micro Controllers 49 27th February 2006 01:35 AM
Help me start, making a servo controller for motorcycle use. motoracer General Electronics Chat 4 11th November 2003 10:29 PM



All times are GMT. The time now is 11:36 AM.


Electronic Circuits  |  Electronics Wiki
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.