Remote control by location (PIC in Oshonsoft)

Thread Starter

camerart

Joined Feb 25, 2013
3,836
Hi,
There are still some glitches to sort out with the peripherals, which we'll work on as we go.

Next try spinning a motor with the REMOTE. For this SERVO motor control is needed.
Can someone scan these 3x examples of CODE and recommend which would is best for me to start with please?
The bottom one was kindly written by 'E'
C.

Code:
2.3.8 Using internal PWM modules

Internal PWM modules (more precisely: PWM modes of CCP modules) are turned on using

PWMON statement.

This statement has two arguments.

The first argument is module number and it must be a constant in the range 1-3.

The second argument is used for mode selection.

Internal PWM module can be used on three different output frequencies

for each of four duty cycle resolutions supported by PWMON statement (10-bit, 9-bit, 8-bit and 7-

bit).

So, PWM module can be turned on with PWMON statement in 12 modes.

Here is the list of all modes at 4MHz clock frequency

(for other clock frequencies, the values should be proportionally adjusted):

mode 1: 10-bit, 244Hz

mode 2: 10-bit, 977Hz

mode 3: 10-bit, 3906Hz

mode 4: 9-bit, 488Hz

mode 5: 9-bit, 1953Hz

mode 6: 9-bit, 7813Hz

mode 7: 8-bit, 977Hz

mode 8: 8-bit, 3906Hz

40

mode 9: 8-bit, 15625Hz

mode 10: 7-bit, 1953Hz

mode 11: 7-bit, 7813Hz

mode 12: 7-bit, 31250Hz

The PWM module is initially started with 0 duty cycle,

so the output will stay low until the duty cycle is changed.

PWM module can be turned off with PWMOFF statement.

It has only one argument - module number.

The duty cycle of PWM signal can be changed with PWMDUTY statement.

Its first argument is module number.

The second argument is duty cycle and it can be a constant in the range 0-1023 or byte

or word data type variable.

User must take care to use the proper value ranges for all PWM modes (0-1023 for 10-bit

resolution,

0-511 for 9-bit resolution, 0-255 for 8-bit resolution and 0-127 for 7-bit resolution).

Here is one example example:

DIM duty AS BYTE

PWMON 1, 9

loop:

ADCIN 0, duty

PWMDUTY 1, duty

GOTO loop
Code:
2.3.9 Interfacing Radio Control (R/C) servos.

For writing applications to interface R/C servos there are two statements available

SERVOIN and SERVOOUT.

R/C servo is controlled by a train of pulses (15-20 pulses per second)

whose length define the position of the servo arm.

The valid length of pulses is in the range 1-2ms.

These two statements have two arguments.

The first argument of both statements is the microcontroller pin where the servo

signal is received or transmitted.

41

For SERVOIN statement that pin should be previously setup as an input pin

and for SERVOOUT statement the pin should be setup for output.

The second argument of SERVOIN statement must be a Byte variable where the length

of the pulse will be saved.

The pulses are measured in 10us units, so it is possible to measure pulses in the

range 0.01-2.55ms.

The value stored in the variable for normal servos should be in the range 100-200.

The second argument of the SERVOOUT statement should be a Byte variable or constant

that determines the length of the generated pulse.

For proper operation of the target servo SERVOOUT statement should be executed

15-20 times during one second.

Here is an example of the servo reverse operation:

DIM length AS BYTE

TRISB.0 = 1

TRISB.1 = 0

loop:

SERVOIN PORTB.0, length

IF length < 100 THEN length = 100

IF length > 200 THEN length = 200

length = length - 100

length = 100 - length

length = length + 100

SERVOOUT PORTB.1, length

GOTO loop
Code:
'18F2431 RX DATA to PWM 160218 1200

fine CONFIG1L = 0x00

Define CONFIG1H = 0x02

Define CONFIG2L = 0x0e

Define CONFIG2H = 0x20

Define CONFIG3L = 0x18  'PWMPIN outputs active on RESET

Define CONFIG3H = 0x80

Define CONFIG4L = 0x80

Define CONFIG4H = 0x00

Define CONFIG5L = 0x0f

Define CONFIG5H = 0xc0

Define CONFIG6L = 0x0f

Define CONFIG6H = 0xe0

Define CONFIG7L = 0x0f

Define CONFIG7H = 0x40


'Connect to PC UART, 9600 Baud

'PORTA.0 n/u

'PORTA.1 =

'PORTA.2

'PORTA.3

'PORTA.4

'PORTA.5

'PORTA.6

'PORTA.7

Define SIMULATION_WAITMS_VALUE = 1  'else 0 for PIC

'PORTC.0 n/u

'PORTC.1

'PORTC.2

'PORTC.3 n/u

'PORTC.4

'PORTC.5

'PORTC.6 n/u

'PORTC.7 n/u


AllDigital

ADCON0 = %00000000  'A_D

ADCON1 = %00000000

ADCON2 = %10000000

ADCON3 = %00000000

ADCHS = %00000000  'A_D

ANSEL0 = %00000000  'A_D

OSCCON = %01110010  'internal 8Mhz clock

OSCTUNE = %00000000  'Oscillator tuning register for EUSART

'PCPWM MODULE SEE AN899 PAGE 5 ALSO SECTION 22.0 D/S

'PWMCON0 = %01010100

PWMCON0 = %01000100  'ptmod    '%01010100 turns them all

PWMCON1 = %00000000

DTCON = %00000000  'Power control

FLTCONFIG = %00000000

OVDCOND = %00000000

OVDCONS = %00000000

PTPERL = 0xff  'register

PTPERH = 0xff  'register

PTMRL = %00000000

PTMRH = %00000000

PTCON0 = %00000000  'ptckps'

PTCON1 = %00000000  'PTEN

IPR3 = %00000000  'TMR


PTMRL = %0000000

PTMRH = %0000000


TRISA = %00000000

TRISB = %00000000

TRISC = %00000000

'assign PWM pins

PWMon 1, 8  'RC1 CCP1, Mode at 8MHz at 7812Hz, to change this look at the Manual Tables

PWMon 2, 8  'RC2 CCP2

DFLTCON = 0

PWMduty 1, 0

PWMduty 2, 0

Hseropen 9600

verify_uart:

Hserout "PWM", CrLf

WaitMs 200

Enable High

Dim duty1 As Byte

Dim x As Word

x = 0


'pwm0 And   pwm1   are   controlled   by   the   PDC0H:PDC0L

'PWM2  and  PWM3  are controlled  by  PDC1H:PDC1L


main:

duty1 = 128


If x <= 10 Then Gosub fwd

If x >= 10 Then Gosub rev

x = x + 1

If x = 20 Then x = 0

Goto main


End                                          

fwd:

ASM:        bcf CCP2CON,DC2B0

ASM:        bcf ccp2con,dc2b1

ASM:        movlw 0x00

ASM:        movwf ccpr2l

PWMduty 1, duty1

Return                                      

rev:

ASM:        bcf CCP1CON,DC1B0

ASM:        bcf ccp1con,dc1b1

ASM:        movlw 0x00

ASM:        movwf ccpr1l

PWMduty 2, duty1

Return                                      


On High Interrupt

Save System


Resume
 
Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
3,836
Hi,
As there are no suggestions:
I have chosen the first method as example '2' to in #1221 uses simple % ON/OFF, and '3' only has '1' output (I think).

EDIT: It looks as though I can't use any of the suggestions in #1221, 1 and 3 both use the CCP of the PIC where there are only 2x. I need 5x.
C
 
Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
3,836
Hi,
Years ago E Gibbs plus others did a lot work getting Nokia 5110 screens to work with this project. These kept failing due to Zebra strip problems, so I shelved them and sent monitoring messages via UART. As there are now many of them flying about they are clashing, and causing problems, so I now have to get the screen working again.
The 5110 screens, may be a little small, so I will look into the larger screens available. I only need text, and touch screen is not necessary.
If anybody has experience with 'say' 2.2" or similar SPI screens, please let me know.
C
 

Thread Starter

camerart

Joined Feb 25, 2013
3,836
I don't have experience on this, but it seems to be quite popular.
SSD 1306 0.96" oled display.
https://www.ebay.com/itm/255283295122
https://simple-circuit.com/pic18f46k22-ssd1306-oled-spi-mode-ccs-c/
Hi J,
I don't have experience on this, but it seems to be quite popular.
SSD 1306 0.96" oled display.
https://www.ebay.com/itm/255283295122
https://simple-circuit.com/pic18f46k22-ssd1306-oled-spi-mode-ccs-c/
Hi J,
I think the ones I have Nokia 5110 are the best bet, as they have been programmed with SPI unlike the ones you posted which are I2C. I need to get them to be more reliable though, then later I'll look into larger ones, over 2" long.
Thanks, C
 

Thread Starter

camerart

Joined Feb 25, 2013
3,836
Hi,
I'm integrating 2x programs into 1x.
1/ has an INCLUDE
2/ has 2x INCLUDES
Both work separately, with all 3x INCLUDES in the same folder, but I'm now getting this error as I integrate.
Any ideas?
C
 

Attachments

Thread Starter

camerart

Joined Feb 25, 2013
3,836
hi C,
Do the 3 Includes have Unique names, and what are they.

E
Hi E,
"fontsml.bas"
"Main MCU config.bas"
"Perpherals setup.bas"
EDIT: I'm integrating fontsml.bas into the FULL program, and in the FULL program, if I comment out fontsml.bas, it compiles.
EDIT-EDIT: I added both programs into one, and commented out the 5110 section, that needs the 'fontsml.bas' and as I slowly uncomment the 5110, it looks like this will show me where the error lies. I'll let you know
C
 
Last edited:

ericgibbs

Joined Jan 29, 2010
21,452
hi C,
Do you have two commands/operations in the Includes with the same name.?

Also, have you tried the Includes in the Main program, in a different order?
E
 

Thread Starter

camerart

Joined Feb 25, 2013
3,836
hi C,
Do you have two commands/operations in the Includes with the same name.?

Also, have you tried the Includes in the Main program, in a different order?
E
Hi E,
I'm pretty sure you're correct.
One program is from 5 years ago, and one recent, Lots of things have changed, including PCB tracks.
You can see the combinations, like a needle in a haystack.
C
-------------------------------------------------------------------------------
'*******************************************************
'* *
'* 5110 SCREEN set up *
'* *
'*******************************************************
'Symbol lcd_reset = LATC.0 'LATC.1 'LCD_RESET PIN 0=Reset
Symbol lcd_datacommand = LATC.1 'LATC.0 '1=DATA, 0=COMMAND
'Symbol lcd_cs = LATD.0 'LATD.4 '5110 LCD C/S
Symbol lcd_cs = LATC.2 'LATD.4 '5110 LCD C/S

Symbol lcd_rst = LATC.0 '5110 LCD_RST
'Symbol lcd_dc = LATC.1 '5110 LCD_DC
'Symbol lcd_cs = LATC.2 '5110 LCD_CS
--------------------------------------------------------------------------------
 

Thread Starter

camerart

Joined Feb 25, 2013
3,836
Hi,
I've cornered the the problem to the SPI settings.
The 2017 program was written with Oshonsoft SPI settings and the recent FULL program was written with SSPBUF exchange, so no SPIPREPARE, SPICSON etc.
C
 

Thread Starter

camerart

Joined Feb 25, 2013
3,836
Hi,
I'm now trying to get the BASE and REMOTE to talk to each other.
So far I've got each to respond to a transmitted MACRO simulating each other, which is woking.

One of the last problems was the TX/RX was getting confused as there were to many to cope with. Now there is a 5110 screen to possible get the signals to only BASE to REMOTE and reverse.

It's quite complicated chaning the programs to reflect messages while PARSING, the sense out of them, and I've just thought of a possible problem.

Here is the TX from BASE: Hserout "$BORI", ",", #ud, ",", #rot, ",", #fr, ",", #lr, ",", strcmd, ",", strprs, ",", strspr, ",", strqeideg, ",", "W", CrLf
It can be seen that there are some VARIABLES starting with # and some with STR. I now think that the # ones are maybe not STRINGS, where the STR ones are STRINGS.
Does this make a difference? Should I convert all #VARIABLES to STRINGS before TXing?
C
 

ericgibbs

Joined Jan 29, 2010
21,452
hi C.
Usually the $ prefix's an ASCII String and the # prefix's a numeric value, which can be in either ASCII or some other numeric format.

Your message appears to have extra ',' Comma characters, before the parameter value, which are normally used in a CSV type message as parameter separators.??

BTW: I assume the double quotes are for just typing out the message string.???

"$BORI", "," , #ud, "," , #rot,

E

$BORI,#ud,#ror ..................
 

Thread Starter

camerart

Joined Feb 25, 2013
3,836
hi C.
Usually the $ prefix's an ASCII String and the # prefix's a numeric value, which can be in either ASCII or some other numeric format.

Your message appears to have extra ',' Comma characters, before the parameter value, which are normally used in a CSV type message as parameter separators.??

BTW: I assume the double quotes are for just typing out the message string.???

"$BORI", "," , #ud, "," , #rot,

E

$BORI,#ud,#ror ..................
Hi E,
The message must be in the same format as the GPS NMEA STRING, i,e, $X,X,X,----,W, so an exact length with each VASIABLE separated by a ',' asyou say CSV. The VARIABLES are PARSED out at the receiving end.

My question is: I've been using both #VARIABLE and STR (=STRING) VARIABLE, does it matter, or do they all need to be STRINGS to be useful?
C
 

ericgibbs

Joined Jan 29, 2010
21,452
My question is: I've been using both #VARIABLE and STR (=STRING) VARIABLE, does it matter, or do they all need to be STRINGS to be useful?
Hi C,
I don't know what you mean by useful.???

Who or what is creating the message is setting either the $ or # prefix and the Data Type.

E
 

Thread Starter

camerart

Joined Feb 25, 2013
3,836
Hi C,
I don't know what you mean by useful.???

Who or what is creating the message is setting either the $ or # prefix and the Data Type.

E
Hi E,
The HSEROUT message is sent between BASE and REMOTE to control things or for information, i,e, battery voltage. My term USEFUL means being able to be used at the RECEIVING end to 'say' control something.

I have to match the GPS message format, for PARSING, which looks like $NAME, XXX, XXXXX, XX,W, so I add a $ at the beginning and a W at the end of my messages.
C
 

ericgibbs

Joined Jan 29, 2010
21,452
Hi C,
Those parameters can be used if the sending end, is sending Valid data from whatever the sending device type is.?
You will have to determine the Data Type from the documentation of the sender device/unit.

For example, what is the Data Type and Format, of the device sending #rot. ???


E
 

Thread Starter

camerart

Joined Feb 25, 2013
3,836
Hi C,
Those parameters can be used if the sending end, is sending Valid data from whatever the sending device type is.?
You will have to determine the Data Type from the documentation of the sender device/unit.

For example, what is the Data Type and Format, of the device sending #rot. ???


E
Hi E,
From the $BORI in #1234: The first 5x are from the joysticks to analogues into the PIC, the 6th is from the Altimeter and is digital, 7 is Spare and is a WORD, and Number 8 is fromt the Digital encoder into the QEI PINS of the PIC.
C
 
Top