Remote control by location (PIC in Oshonsoft)

Thread Starter

camerart

Joined Feb 25, 2013
3,724
hi,
There is a Real Time Duration display on the IDE.
Just before the block of code you want to time measure, insert a BREAK cmd.
Just after the block of code you want to time measure, insert a BREAK cmd.

Run the sim until the Break point stops it, Note the Real time value in uSecs. [ sim will be STEP mode]
Click on Rate then Ultimate and the program will run onto the next BREAK point, Note the Real Time.

Subtract the first value from the last and thats the Execution time for that block of code.

To try a rerun Stop the sim and then restart

E

EDIT:
To avoid doing the maths, use the Reset Sim Statistics, at the Break
Hi E,
Thanks, very useful.
C.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,724
hi,
There is a Real Time Duration display on the IDE.
Just before the block of code you want to time measure, insert a BREAK cmd.
Just after the block of code you want to time measure, insert a BREAK cmd.

Run the sim until the Break point stops it, Note the Real time value in uSecs. [ sim will be STEP mode]
Click on Rate then Ultimate and the program will run onto the next BREAK point, Note the Real Time.

Subtract the first value from the last and thats the Execution time for that block of code.

To try a rerun Stop the sim and then restart

E

EDIT:
To avoid doing the maths, use the Reset Sim Statistics, at the Break
Hi E,
Here are some readings from this CODE using 4x 0 and 4x 1000:
C.


mainloop:
Toggle PORTA.4 'some thing to do!

tim1 = 1000 '1100
tim2 = 1000 '1200
tim3 = 1000 '1300
tim4 = 1000 '1400

If servo = 0 Then
PORTB.servo = 1
t1word = 65535 - tim1
TMR1H = t1word.HB
TMR1L = t1word.LB
PORTB.servo = 0
Hserout "Servo 1=", #t1word, CrLf
Else
If servo = 1 Then
PORTB.servo = 1
t1word = 65535 - tim2
TMR1H = t1word.HB
TMR1L = t1word.LB
PORTB.servo = 0
Hserout "servo 2=", #t1word, CrLf
Else
If servo = 2 Then
PORTB.servo = 1
t1word = 65535 - tim3
TMR1H = t1word.HB
TMR1L = t1word.LB
PORTB.servo = 0
Hserout "servo 3=", #t1word, CrLf
Else
If servo = 3 Then
PORTB.servo = 1
t1word = 65535 - tim4
TMR1H = t1word.HB
TMR1L = t1word.LB
PORTB.servo = 0
Hserout "servo 4=", #t1word, CrLf
Endif
Endif
Endif
Endif

If servo > 3 Then servo = 0

Goto mainloop

End

On High Interrupt
Save System

PIR1.TMR1IF = 0 'clear the TMR1 IF flag

T1CON.TMR1ON = 0
servo = servo + 1
Break ''''''''''''''''''''''''''''''''''''''''''''

T1CON.TMR1ON = 1

Resume
 

Attachments

ericgibbs

Joined Jan 29, 2010
18,766
hi C,
Looked thru your code, what were your conclusions on the results that you observed.?
Could you explain how you intend to service all 6 servos in a 20mSec period and also maintain the 20mSec interval.
Also consider how you are going to capture the asynchronous serial message input without disrupting the servo operation.

I have been working on some problems/solutions for you in the past few days, but I want to be sure we are seeing the problems in the same way.
Eric

BTW:
Have you considered using Case Select rather than IF ELSE.... situations.

Seclect Case Servo
Case 0
PORTB.servo = 1
t1word = 65535 - tim1
TMR1H = t1word.HB
TMR1L = t1word.LB
PORTB.servo = 0
Hserout "Servo 1=", #t1word, CrLf

Case 1
PORTB.servo = 1
t1word = 65535 - tim2
TMR1H = t1word.HB
TMR1L = t1word.LB
PORTB.servo = 0
Hserout "servo 2=", #t1word, CrLf

etc ..................

Case Else
'do nothing
EndSelect
 

Thread Starter

camerart

Joined Feb 25, 2013
3,724
hi C,
Looked thru your code, what were your conclusions on the results that you observed.?
Could you explain how you intend to service all 6 servos in a 20mSec period and also maintain the 20mSec interval.
Also consider how you are going to capture the asynchronous serial message input without disrupting the servo operation.

I have been working on some problems/solutions for you in the past few days, but I want to be sure we are seeing the problems in the same way.
Eric

BTW:
Have you considered using Case Select rather than IF ELSE.... situations.

Seclect Case Servo
Case 0
PORTB.servo = 1
t1word = 65535 - tim1
TMR1H = t1word.HB
TMR1L = t1word.LB
PORTB.servo = 0
Hserout "Servo 1=", #t1word, CrLf

Case 1
PORTB.servo = 1
t1word = 65535 - tim2
TMR1H = t1word.HB
TMR1L = t1word.LB
PORTB.servo = 0
Hserout "servo 2=", #t1word, CrLf

etc ..................

Case Else
'do nothing
EndSelect
Hi E,
I would have thought that as all of the inputs are the same, then all of the results would be too, but they aren't.

How I see it:
There is a 20mS INTERRUPT
RB0 ON XmS INTERRUPT (X= 1-2mS) OFF
RB1 ON XmS INTERRUPT (X= 1-2mS) OFF
RB2 ON XmS INTERRUPT (X= 1-2mS) OFF
RB3 ON XmS INTERRUPT (X= 1-2mS) OFF
RB4 ON XmS INTERRUPT (X= 1-2mS) OFF
RB5 ON XmS INTERRUPT (X= 1-2mS) OFF

6x 1-2 mS = 6-12 mS
20mS - 12mS = 8mS For receiving the asynchronous serial message input.

We've used CASE before, but I have difficulty programming it.

C.
 

ericgibbs

Joined Jan 29, 2010
18,766
20mS - 12mS = 8mS For receiving the asynchronous serial message input.
hi C,
This one of the problems with that method.
How can you be sure that the asynchronous message will arrive during that 8mSec period, remember the serial input buffer is only 2 bytes long.?

E
 

Thread Starter

camerart

Joined Feb 25, 2013
3,724
hi C,
This one of the problems with that method.
How can you be sure that the asynchronous message will arrive during that 8mSec period, remember the serial input buffer is only 2 bytes long.?

E
Hi E,
Note: There are two messages. 1/From the GPS and 2/From BASE.

I was living in hope!
From what you imply, I presume I need another PIC, for admin, with connections to the SERVO PIC. Will this work? There are SERVO driver PICS.

EDIT: I could send individual SERVOs each withing 20mS so there would be 18mS space?

C.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,724
Hi E,
Looking again at my CODE, I think that by accident each SERVO is addressed individually, so if each SERVO interrupt 1-2mS time was subtracted from 20mS, and a second INTERRUPT followed the SERVO RBX OUT. then I think this would work.

So:
RB0 ON INTERRUPT time OFF (1-2mS)
Gap approx 18mS
RB1 ON INTERRUPT time OFF (1-2mS)
Gap approx 18mS
and so on
C.
 

ericgibbs

Joined Jan 29, 2010
18,766
I was living in hope!
hi C,

RB0 ON INTERRUPT time OFF (1-2mS)
Gap approx 18mS 'total run time 20mS
RB1 ON INTERRUPT time OFF (1-2mS)
Gap approx 18mS' total run = 40mS
RB2 ON INTERRUPT time OFF (1-2mS)
Gap approx 18mS 'total run time 60mS
RB3 ON INTERRUPT time OFF (1-2mS)
Gap approx 18mS' total run = 80mS
RB4 ON INTERRUPT time OFF (1-2mS)
Gap approx 18mS 'total run time 100mS
RB5 ON INTERRUPT time OFF (1-2mS)
Gap approx 18mS' total run = 120mS


'then next RB0

Woops its now 120mS since the last RB0 servo command, result expensive repair to air plane.!!!
Please post a d/s for the servo mechanism.

Sorry to sound so negative, but in order to succeed,
You really have to sit down and sketch out a program flowchart, with timings.

E
 

jpanhalt

Joined Jan 18, 2008
11,087
Buried in my files is this annotated list of posts collected over the past several years for driving servos. Some of them drive several (see comments). NB: Mike McLaren's (#5) used an additional piece of hardware.

1) Most servos http://www.electro-tech-online.com/micro-controllers/34390-drive-33-servos-one-pic-usart.html
(Commercial version of above: http://www.circuit-ed.com/30-Servo-HardwareSoftware-KIT-by-JVM-BOTS-P117C10.aspx
NOTE: Warren Schroeder -- wschroeder-- took down the code link from electrotech)
2) 8 SERVOS (Pommie)
http://www.electro-tech-online.com/micro-controllers/36127-junebug-servo-c18-code.html (drives 8 servos)
3) GREAT THREAD (Pommie)
http://www.electro-tech-online.com/micro-controllers/34329-18-servo-controller.html
Comment by Harvey42: I don't know how useful this will be for you, but might get some ideas from what they did. I pick it up on AVRFreaks yesterday. It controls 20 servos, the source is in 'C', and uses 2 x 4017. I think they used a ATmega16, a 40 pin chip, but only 3 pins go to the 4017s. Just took a brief look, don't know 'C'. (Note he provides this ink to site with code: (au= jheissjr): http://www.avrfreaks.net/index.php?module=Freaks Files&func=viewFile&id=3238&showinfo=1 )
4) Pommie's servo control with interrupt, not multiple servos
http://www.electro-tech-online.com/...54-firefly-manual-very-rough-first-draft.html
5) MIKE,K8LH:
http://www.electro-tech-online.com/micro-controllers/29837-8-16-servos-using-pwm-module.html

Warning: I have not updated it recently and some of the links may be dead.

John
 

Thread Starter

camerart

Joined Feb 25, 2013
3,724
Buried in my files is this annotated list of posts collected over the past several years for driving servos. Some of them drive several (see comments). NB: Mike McLaren's (#5) used an additional piece of hardware.

1) Most servos http://www.electro-tech-online.com/micro-controllers/34390-drive-33-servos-one-pic-usart.html
(Commercial version of above: http://www.circuit-ed.com/30-Servo-HardwareSoftware-KIT-by-JVM-BOTS-P117C10.aspx
NOTE: Warren Schroeder -- wschroeder-- took down the code link from electrotech)
2) 8 SERVOS (Pommie)
http://www.electro-tech-online.com/micro-controllers/36127-junebug-servo-c18-code.html (drives 8 servos)
3) GREAT THREAD (Pommie)
http://www.electro-tech-online.com/micro-controllers/34329-18-servo-controller.html
Comment by Harvey42: I don't know how useful this will be for you, but might get some ideas from what they did. I pick it up on AVRFreaks yesterday. It controls 20 servos, the source is in 'C', and uses 2 x 4017. I think they used a ATmega16, a 40 pin chip, but only 3 pins go to the 4017s. Just took a brief look, don't know 'C'. (Note he provides this ink to site with code: (au= jheissjr): http://www.avrfreaks.net/index.php?module=Freaks Files&func=viewFile&id=3238&showinfo=1 )
4) Pommie's servo control with interrupt, not multiple servos
http://www.electro-tech-online.com/...54-firefly-manual-very-rough-first-draft.html
5) MIKE,K8LH:
http://www.electro-tech-online.com/micro-controllers/29837-8-16-servos-using-pwm-module.html

Warning: I have not updated it recently and some of the links may be dead.

John
Hi J,
Thanks, I'll look through them.
C.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,724
hi C,

RB0 ON INTERRUPT time OFF (1-2mS)
Gap approx 18mS 'total run time 20mS
RB1 ON INTERRUPT time OFF (1-2mS)
Gap approx 18mS' total run = 40mS
RB2 ON INTERRUPT time OFF (1-2mS)
Gap approx 18mS 'total run time 60mS
RB3 ON INTERRUPT time OFF (1-2mS)
Gap approx 18mS' total run = 80mS
RB4 ON INTERRUPT time OFF (1-2mS)
Gap approx 18mS 'total run time 100mS
RB5 ON INTERRUPT time OFF (1-2mS)
Gap approx 18mS' total run = 120mS


'then next RB0

Woops its now 120mS since the last RB0 servo command, result expensive repair to air plane.!!!
Please post a d/s for the servo mechanism.

Sorry to sound so negative, but in order to succeed,
You really have to sit down and sketch out a program flowchart, with timings.

E
Hi E,
Each of my line pairs is a complete 'LOOP' so the time doesn't accumulate. Each INTERRUPT LOOP is 20Ms with only one ON/OFF of 1x RBx SERVO PIN which changes on each LOOP.
So there will be 18mS within each LOOP for the rest of the program.

I have a second PCB, and will connect a couple of SERVOs for testing.
C.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,724
Hi,
I now have two SERVOs connected to RB0 and RB1

Here is the MAIN LOOP:
Dim time As Word
time = 2000

mainloop:
Toggle PORTA.4 'some thing to do!

RB0 = 1
WaitUs time
RB0 = 0
WaitUs 1850

RB1 = 1
WaitUs time
RB1 = 0
WaitUs 1850

Goto mainloop
-----------------------------------------------------------------------
If I change TIME between 1000 and 2000, the SERVOs move as expected. (The timings are not accurate)
C.
 

jjw

Joined Dec 24, 2013
823
I made the following test outline for interrupts.
Not tested yet.
Might have errors.
It is for two servos, 0 and 1
Interrupt overhead should be less than 1% with 8Mhz oscillator
Timr1 should be written as two bytes

Code:
' Initialisation code here

' test values for servo on times
T0=...
T1= ...
T2=...  ' test value for time from last servo to 20ms

servo =  2  
Timr1 = 65534 ' trigger the interrupt first time, then it runs on  timer1 interrupts

Main:            ' main program here
goto main
End

On high interrupt
Save system

If servo=2 then ' 20ms passed
   servo=0
   portb.0 = 1
   Timr1= 65535-T0  '  first servo on
   resume
Endif

If servo=0 then  ' interrupt after first servo ontime
  portb.0 =0
  portb.1=1
  Timr1= 65535-T1 ' second servo on
Endif

If servo=1 then
  Portb.1 =0
  Timr1=65535-T2   '  time to 20ms
Endif

servo=servo+1
Resume
 

Thread Starter

camerart

Joined Feb 25, 2013
3,724
I made the following test outline for interrupts.
Not tested yet.
Might have errors.
It is for two servos, 0 and 1
Interrupt overhead should be less than 1% with 8Mhz oscillator
Timr1 should be written as two bytes

Code:
' Initialisation code here

' test values for servo on times
T0=...
T1= ...
T2=...  ' test value for time from last servo to 20ms

servo =  2
Timr1 = 65534 ' trigger the interrupt first time, then it runs on  timer1 interrupts

Main:            ' main program here
goto main
End

On high interrupt
Save system

If servo=2 then ' 20ms passed
   servo=0
   portb.0 = 1
   Timr1= 65535-T0  '  first servo on
   resume
Endif

If servo=0 then  ' interrupt after first servo ontime
  portb.0 =0
  portb.1=1
  Timr1= 65535-T1 ' second servo on
Endif

If servo=1 then
  Portb.1 =0
  Timr1=65535-T2   '  time to 20ms
Endif

servo=servo+1
Resume
Hi J,
Thanks for your CODE.
I'm not sure how to subtr
It now compiles on OSH, but doesn't move the 2x SERVOs
The YLED is toggling, but the RLED isn't.
C.
I made the following test outline for interrupts.
Not tested yet.
Might have errors.
It is for two servos, 0 and 1
Interrupt overhead should be less than 1% with 8Mhz oscillator
Timr1 should be written as two bytes

Code:
' Initialisation code here

' test values for servo on times
T0=...
T1= ...
T2=...  ' test value for time from last servo to 20ms

servo =  2 
Timr1 = 65534 ' trigger the interrupt first time, then it runs on  timer1 interrupts

Main:            ' main program here
goto main
End

On high interrupt
Save system

If servo=2 then ' 20ms passed
   servo=0
   portb.0 = 1
   Timr1= 65535-T0  '  first servo on
   resume
Endif

If servo=0 then  ' interrupt after first servo ontime
  portb.0 =0
  portb.1=1
  Timr1= 65535-T1 ' second servo on
Endif

If servo=1 then
  Portb.1 =0
  Timr1=65535-T2   '  time to 20ms
Endif

servo=servo+1
Resume
Hi J,
Thanks for your CODE. I've tried to edit it, so again there may be errors.
The SERVOs move, but they move to one end, even though I've tried changing T0 and T1 settings.
C.
 

Attachments

Thread Starter

camerart

Joined Feb 25, 2013
3,724
Buried in my files is this annotated list of posts collected over the past several years for driving servos. Some of them drive several (see comments). NB: Mike McLaren's (#5) used an additional piece of hardware.

1) Most servos http://www.electro-tech-online.com/micro-controllers/34390-drive-33-servos-one-pic-usart.html
(Commercial version of above: http://www.circuit-ed.com/30-Servo-HardwareSoftware-KIT-by-JVM-BOTS-P117C10.aspx
NOTE: Warren Schroeder -- wschroeder-- took down the code link from electrotech)
2) 8 SERVOS (Pommie)
http://www.electro-tech-online.com/micro-controllers/36127-junebug-servo-c18-code.html (drives 8 servos)
3) GREAT THREAD (Pommie)
http://www.electro-tech-online.com/micro-controllers/34329-18-servo-controller.html
Comment by Harvey42: I don't know how useful this will be for you, but might get some ideas from what they did. I pick it up on AVRFreaks yesterday. It controls 20 servos, the source is in 'C', and uses 2 x 4017. I think they used a ATmega16, a 40 pin chip, but only 3 pins go to the 4017s. Just took a brief look, don't know 'C'. (Note he provides this ink to site with code: (au= jheissjr): http://www.avrfreaks.net/index.php?module=Freaks Files&func=viewFile&id=3238&showinfo=1 )
4) Pommie's servo control with interrupt, not multiple servos
http://www.electro-tech-online.com/...54-firefly-manual-very-rough-first-draft.html
5) MIKE,K8LH:
http://www.electro-tech-online.com/micro-controllers/29837-8-16-servos-using-pwm-module.html

Warning: I have not updated it recently and some of the links may be dead.

John
Hi J,
Some interesting stuff there, although it is a bit beyond my skills. I also have reservations, that Oshonsoft may not like some of it, and I'm afraid I can only use Oshonsoft.
I'm sure the best solution will filter through.
C.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,724
hi C,

RB0 ON INTERRUPT time OFF (1-2mS)
Gap approx 18mS 'total run time 20mS
RB1 ON INTERRUPT time OFF (1-2mS)
Gap approx 18mS' total run = 40mS
RB2 ON INTERRUPT time OFF (1-2mS)
Gap approx 18mS 'total run time 60mS
RB3 ON INTERRUPT time OFF (1-2mS)
Gap approx 18mS' total run = 80mS
RB4 ON INTERRUPT time OFF (1-2mS)
Gap approx 18mS 'total run time 100mS
RB5 ON INTERRUPT time OFF (1-2mS)
Gap approx 18mS' total run = 120mS


'then next RB0

Woops its now 120mS since the last RB0 servo command, result expensive repair to air plane.!!!
Please post a d/s for the servo mechanism.

Sorry to sound so negative, but in order to succeed,
You really have to sit down and sketch out a program flowchart, with timings.

E
Hi E,
Re-thinking what you said, of course it does accumulate the time!!
I've never been able to write flowcharts, all I end up with is a bag of spaghetti, that even I can't follow.

Regarding the SERVOs I now think that it may go like this:
RBO ON (e,g, 1000uS)
RB1 ON (e,g, 2000uS)
RB2 ON (e,g, 1500uS)
RB3 ON (e,g, 1800uS)
RB4 ON (e,g, 1100uS)
RB5 ON (e,g, 1600uS)

After 1000uS RB0 OFF
After 1100uS RB4 OFF
After 1500uS RB2 OFF
After 1600uS RB5 OFF
After 1800uS RB3 OFF
After 2000uS RB1 OFF

This gap is where the MAIN program works.

After 18000uS Start again (I'm not sure if this time needs calculating or simply 18000uS is ok?)

Here is a photo of an ORANGE radio SERVO controller, which somehow works, and is doing a similar thing to this section of the project.

From earlier comments, there may not be enough time for the MAIN program, so perhaps an external SERVO chip is needed?

C.
 

Attachments

jjw

Joined Dec 24, 2013
823
Hi J,
Thanks for your CODE.
I'm not sure how to subtr
It now compiles on OSH, but doesn't move the 2x SERVOs
The YLED is toggling, but the RLED isn't.
C.

Hi J,
Thanks for your CODE. I've tried to edit it, so again there may be errors.
The SERVOs move, but they move to one end, even though I've tried changing T0 and T1 settings.
C.
I combined it with modified #74 and after some corrections it compiles ok but the timings dont look right. Is the timer1 prescaler correct?
I have assumed timer1 runs at 1Mhz
I will test it and post later today.
 

jjw

Joined Dec 24, 2013
823
Hi E,
Re-thinking what you said, of course it does accumulate the time!!
I've never been able to write flowcharts, all I end up with is a bag of spaghetti, that even I can't follow.

Regarding the SERVOs I now think that it may go like this:
RBO ON (e,g, 1000uS)
RB1 ON (e,g, 2000uS)
RB2 ON (e,g, 1500uS)
RB3 ON (e,g, 1800uS)
RB4 ON (e,g, 1100uS)
RB5 ON (e,g, 1600uS)

After 1000uS RB0 OFF
After 1100uS RB4 OFF
After 1500uS RB2 OFF
After 1600uS RB5 OFF
After 1800uS RB3 OFF
After 2000uS RB1 OFF

This gap is where the MAIN program works.

After 18000uS Start again (I'm not sure if this time needs calculating or simply 18000uS is ok?)

Here is a photo of an ORANGE radio SERVO controller, which somehow works, and is doing a similar thing to this section of the project.

From earlier comments, there may not be enough time for the MAIN program, so perhaps an external SERVO chip is needed?

C.
If the interrupts run correctly they take at most 1% of cpu time, so no need for an external servo chip.
 

jjw

Joined Dec 24, 2013
823
I combined it with modified #74 and after some corrections it compiles ok but the timings dont look right. Is the timer1 prescaler correct?
I have assumed timer1 runs at 1Mhz
I will test it and post later today.
The prescaler is 1:8, I will change it to 1:2
 

Thread Starter

camerart

Joined Feb 25, 2013
3,724
If the interrupts run correctly they take at most 1% of cpu time, so no need for an external servo chip.
Hi J,
I have found it difficult to differentiate between WAIT and INTERRUPTs. I think the penny has just dropped, and I now understand that INTERRUPTs take little time, so my routine at #116 should work.

Now I'm trying to figure out how to calculate and implement the 4x (will be 6)SERVO OFF times, with the ever changing incoming ON times.
C.
 
Last edited:
Top