Remote control by location (PIC in Oshonsoft)

Thread Starter

camerart

Joined Feb 25, 2013
3,835
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.
Hi J,
The Prescaler was changed to 1:2 1uS.
C.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,835
Hi,
As mentioned before The test PCBs we're working on have only 4x SERVO PINS free, but perhaps it's better to work with the final number of 6x SERVO PINs RB0-5.
I'm waiting for a while before finalising the new PCBs
C.
 

jjw

Joined Dec 24, 2013
823
The prescaler is 1:8, I will change it to 1:2
This looks ok.
I added 1000us delay to Led toggle and it is displayed also on oscilloscope
Code:
'servo test 27.07.2018

Define CONFIG1L = 0x00
Define CONFIG1H = 0x08
Define CONFIG2L = 0x1e
Define CONFIG2H = 0x00
Define CONFIG3L = 0x00
Define CONFIG3H = 0x83
Define CONFIG4L = 0x80
Define CONFIG4H = 0x00
Define CONFIG5L = 0x0f
Define CONFIG5H = 0xc0
Define CONFIG6L = 0x0f
Define CONFIG6H = 0xe0
Define CONFIG7L = 0x0f
Define CONFIG7H = 0x40

''''Define SIMULATION_WAITMS_VALUE = 1
AllDigital  'comparators off

Dim t1word As Word
Dim t0 As Word  'servo 0 ontime
Dim t1 As Word  'servo 1 ontime
Dim t2 As Word  '20ms - T0 - T1
Dim servo As Byte

Disable High
Disable Low

T1CON = %00011101  '1:2 -> Timer1 clock = 1MHz
T2CON = 0
T3CON = 0
OSCCON = %01111110  '8MHz

INTCON = %00000000
INTCON2 = %00000000
INTCON3 = %00000000
PIR1 = 0
PIR2 = 0
PIE1 = 0
PIE2 = 0

IPR1 = 0
IPR2 = 0
IPR1.TMR1IP = 1
RCON.IPEN = 1  'this MUST be included

TRISA = 0x2f
TRISB = 0x00
TRISC = %00000000
TRISD = %00001111
LATD = %00001111

TRISE.0 = 0  'TXD LED
TRISE.1 = 1
'TRISE.2 = DHT I/O

PORTB = 0
LATB = 0

ADCON0 = 0x03  'adc
ADCON1 = 0x09
ADCON2 = %10100100

T1CON.TMR1ON = 0

PIE1.TMR1IE = 1
PIE1.RCIE = 1
PIR1.RCIF = 0
'Hseropen 9600
'Hserout "Ready ", CrLf

TMR1L = 0xdc
TMR1H = 0xf0

Enable High
Enable Low

INTCON.GIE = 1
INTCON.PEIE = 1

t0 = 1000
t1 = 2000
t2 = 17000  '20000-t0-t1

servo = 2
t1word = 65534
TMR1H = t1word.HB
TMR1L = t1word.LB

T1CON.TMR1ON = 1

idle_loop:
Toggle PORTA.4  'some thing to do!
WaitUs 1000
Goto idle_loop

End  

On High Interrupt
Save System

PIR1.TMR1IF = 0  'clear the TMR1 IF flag

T1CON.TMR1ON = 0

If servo = 2 Then
servo = 0
PORTB.0 = 1
t1word = 65535 - t0
TMR1H = t1word.HB
TMR1L = t1word.LB
Goto rtn
Endif

If servo = 0 Then
PORTB.0 = 0
PORTB.1 = 1
t1word = 65535 - t1
TMR1H = t1word.HB
TMR1L = t1word.LB
Endif

If servo = 1 Then
PORTB.1 = 0
t1word = 65535 - t2
TMR1H = t1word.HB
TMR1L = t1word.LB
Endif

servo = servo + 1
rtn:
T1CON.TMR1ON = 1
Resume
upload_2018-7-27_17-8-43.png
 

ericgibbs

Joined Jan 29, 2010
21,452
hi C,
As I understand the project these servo's control an aircraft's, control surfaces.? rudder, flaps etc
Which I would say when the surfaces are in the 'neutral' position, the servo pulse ON width has to be at 50% .? ~1.5mSec

Another point that has to be solved, is the parsing and conversion from say, a ASCII msg "1100" to a binary value that has to be subtracted from 65535, before it can be loaded into TMR1.?

E
 

Thread Starter

camerart

Joined Feb 25, 2013
3,835
hi C,
As I understand the project these servo's control an aircraft's, control surfaces.? rudder, flaps etc
Which I would say when the surfaces are in the 'neutral' position, the servo pulse ON width has to be at 50% .? ~1.5mSec

Another point that has to be solved, is the parsing and conversion from say, a ASCII msg "1100" to a binary value that has to be subtracted from 65535, before it can be loaded into TMR1.?

E
Hi E,
Yes, most of the SERVOs control surfaces, but in this case they control motor speed, plus a rudder SERVO. (Tricopter) It's not really important, but SERVO3 is Throttle, which should be LOW.

From memory, I have previously used a modified version of your get_neo (Now get_mess) which arrives at a computer Terminal ok. I think previously, you wrote an ascii section, but I can't remember where. (I'll do a search a bit later)
C.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,835
This looks ok.
I added 1000us delay to Led toggle and it is displayed also on oscilloscope
Code:
'servo test 27.07.2018

Define CONFIG1L = 0x00
Define CONFIG1H = 0x08
Define CONFIG2L = 0x1e
Define CONFIG2H = 0x00
Define CONFIG3L = 0x00
Define CONFIG3H = 0x83
Define CONFIG4L = 0x80
Define CONFIG4H = 0x00
Define CONFIG5L = 0x0f
Define CONFIG5H = 0xc0
Define CONFIG6L = 0x0f
Define CONFIG6H = 0xe0
Define CONFIG7L = 0x0f
Define CONFIG7H = 0x40

''''Define SIMULATION_WAITMS_VALUE = 1
AllDigital  'comparators off

Dim t1word As Word
Dim t0 As Word  'servo 0 ontime
Dim t1 As Word  'servo 1 ontime
Dim t2 As Word  '20ms - T0 - T1
Dim servo As Byte

Disable High
Disable Low

T1CON = %00011101  '1:2 -> Timer1 clock = 1MHz
T2CON = 0
T3CON = 0
OSCCON = %01111110  '8MHz

INTCON = %00000000
INTCON2 = %00000000
INTCON3 = %00000000
PIR1 = 0
PIR2 = 0
PIE1 = 0
PIE2 = 0

IPR1 = 0
IPR2 = 0
IPR1.TMR1IP = 1
RCON.IPEN = 1  'this MUST be included

TRISA = 0x2f
TRISB = 0x00
TRISC = %00000000
TRISD = %00001111
LATD = %00001111

TRISE.0 = 0  'TXD LED
TRISE.1 = 1
'TRISE.2 = DHT I/O

PORTB = 0
LATB = 0

ADCON0 = 0x03  'adc
ADCON1 = 0x09
ADCON2 = %10100100

T1CON.TMR1ON = 0

PIE1.TMR1IE = 1
PIE1.RCIE = 1
PIR1.RCIF = 0
'Hseropen 9600
'Hserout "Ready ", CrLf

TMR1L = 0xdc
TMR1H = 0xf0

Enable High
Enable Low

INTCON.GIE = 1
INTCON.PEIE = 1

t0 = 1000
t1 = 2000
t2 = 17000  '20000-t0-t1

servo = 2
t1word = 65534
TMR1H = t1word.HB
TMR1L = t1word.LB

T1CON.TMR1ON = 1

idle_loop:
Toggle PORTA.4  'some thing to do!
WaitUs 1000
Goto idle_loop

End 

On High Interrupt
Save System

PIR1.TMR1IF = 0  'clear the TMR1 IF flag

T1CON.TMR1ON = 0

If servo = 2 Then
servo = 0
PORTB.0 = 1
t1word = 65535 - t0
TMR1H = t1word.HB
TMR1L = t1word.LB
Goto rtn
Endif

If servo = 0 Then
PORTB.0 = 0
PORTB.1 = 1
t1word = 65535 - t1
TMR1H = t1word.HB
TMR1L = t1word.LB
Endif

If servo = 1 Then
PORTB.1 = 0
t1word = 65535 - t2
TMR1H = t1word.HB
TMR1L = t1word.LB
Endif

servo = servo + 1
rtn:
T1CON.TMR1ON = 1
Resume
View attachment 157007
Hi J,
T1 is working ok. T0 isn't
Thanks,
C.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,835
Or do you mean the servo on times T0 and T1?
They work in #127 as you can see in Oshonsofts oscilloscope.
Hi J,
I'm not sure, but it may be that there is an initial signal that starts the SERVO, which
Or do you mean the servo on times T0 and T1?
They work in #127 as you can see in Oshonsofts oscilloscope.
Hi J,
A bit of a mystery!

This works:
If servo = 2 Then
servo = 0
PORTB.0 = 1
'''''''t1word = 65535 - t0
'''''''TMR1H = t1word.HB
'''''''TMR1L = t1word.LB
WaitUs 1000 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
PORTB.0 = 0 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Goto rtn
Endif

This doesn't:
If servo = 2 Then
servo = 0
PORTB.0 = 1
t1word = 65535 - t0
TMR1H = t1word.HB
TMR1L = t1word.LB
'''''''WaitUs 1000 'XXXXXXXXXXXXXXXXXXXXXXXXXXX
'''''''PORTB.0 = 0 'XXXXXXXXXXXXXXXXXXXXXXXXXXXX
Goto rtn
Endif
(I can move the SERVO by hand, and it stays)
C.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,835
hi C,

Another point that has to be solved, is the parsing and conversion from say, a ASCII msg "1100" to a binary value that has to be subtracted from 65535, before it can be loaded into TMR1.?

E
Hi E,
Here are earlier programs we worked on: https://www.electro-tech-online.com...ps-bmp280-hmc5983.150378/page-15#post-1313781

#287<<<<<<<<<<<<<<<<<<<<<

There are references to ASCII in the 5110 screen Include.
NOTE: MANY THINGS HAVE CHANGED SINCE THEN, PINS ETC. PERHAPS PCB
C.
 

jjw

Joined Dec 24, 2013
823
Hi J,
I'm not sure, but it may be that there is an initial signal that starts the SERVO, which

Hi J,
A bit of a mystery!

This works:
If servo = 2 Then
servo = 0
PORTB.0 = 1
'''''''t1word = 65535 - t0
'''''''TMR1H = t1word.HB
'''''''TMR1L = t1word.LB
WaitUs 1000 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
PORTB.0 = 0 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Goto rtn
Endif

This doesn't:
If servo = 2 Then
servo = 0
PORTB.0 = 1
t1word = 65535 - t0
TMR1H = t1word.HB
TMR1L = t1word.LB
'''''''WaitUs 1000 'XXXXXXXXXXXXXXXXXXXXXXXXXXX
'''''''PORTB.0 = 0 'XXXXXXXXXXXXXXXXXXXXXXXXXXXX
Goto rtn
Endif
(I can move the SERVO by hand, and it stays)
C.
Have you tried #127 ?
It should work.
Don't use any Waitus in the interrupt routine.
They are not needed and they more or less block the processor.
 

ericgibbs

Joined Jan 29, 2010
21,452
hi C.
This is the version I have been using for the demo's, needs extending for 6 timings
As jjw is helping, I will not post as well, it will cause confusion.
E

strbase = "1250,1500,1750,2000"
msg1 = strbase
Call strs2hex2(msg1)
idle_loop:
Goto idle_loop
End

'parse msg string into 4, Tmr1 count Up values
Proc strs2hex2(arg1 As String)

st0 = MidStr(arg1, 1, 4)
st1 = MidStr(arg1, 6, 4)
st2 = MidStr(arg1, 11, 4)
st3 = MidStr(arg1, 16, 4)

wt0 = StrValW(st0)
wt1 = StrValW(st1)
wt2 = StrValW(st2)
wt3 = StrValW(st3)

wt0 = 65535 - wt0 ''' wt0= NOT wt0 is the same as 65535 -wt0
wt1 = 65535 - wt1
wt2 = 65535 - wt2
wt3 = 65535 - wt3

'the wt is the TMR1 load value
Hserout #wt0, ",", #wt1, ",", #wt2, ",", #wt3, CrLf
End Proc
 
Last edited:

jjw

Joined Dec 24, 2013
823
Have you tried #127 ?
It should work.
Don't use any Waitus in the interrupt routine.
They are not needed and they more or less block the processor.
Do you have an initial value for T0 ( 1000- 2000)?
If it is 0, it might explain the behavior.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,835
Test first that #127 works.
Hi J,
All of my replies since #127 have been using that CODE.
After I found T0 didn't work, I added a WAIT only to check the SERVO is still working, and to show you, how near #127 CODE is to working.
When reading about SERVOS, I have seen reference to a 'start' signal for SERVO control I've also tried a WAIT before the T0 TMR1 INTERRUPT (No worky)
C.
 
Top