HW 8 channel SERVO/MOTOR output on 18F4431 (Oshonsoft)

jjw

Joined Dec 24, 2013
823
They wrote CCP1 = 2000, which the C- compiler might make to two instructions or use a pointer, but Oshonsoft can't do directly.
Is there some problem, if the word variable is written with high- and low byte to CCPR1H and CCPR1L
I Googled some examples in C.
CCPR1H and CCPR1L is always used.
I asked in ETO if CCPR1 = 2000 is a valid statement.
 

sagor

Joined Mar 10, 2019
903
I Googled some examples in C.
CCPR1H and CCPR1L is always used.
I asked in ETO if CCPR1 = 2000 is a valid statement.
Nope, CCPR1 is defined as a byte by Oshonsoft. You have to use the .HB and .LB method to write a word value to CCPR1 via the CCPR1H and CCPR1L registers.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,724
I Googled some examples in C.
CCPR1H and CCPR1L is always used.
I asked in ETO if CCPR1 = 2000 is a valid statement.
Hi J,
Osh doesn't compile [ if CCPR1 = 2000 ], this is why I changed it to the FRAME variable, which does compile.
C
 

Thread Starter

camerart

Joined Feb 25, 2013
3,724
I meant if it is possible in C as they had in ETO.
Hi J,
As they have it in ETO, was written for me to test, but it may not have worked actually in C.
EDIT: the 4000 didn't compile in OSH as it isn't a BYTE, so has to be split in 2x.
C.
 

ericgibbs

Joined Jan 29, 2010
18,766
hi C,
A simple WORD compare basic program.
Try it.
E
Code:
Dim frame As Word
Dim cntr As Word
Dim cntrh As Byte
Dim cntrl As Byte

Dim cmp1 As Byte

cntr = 2000  'value 1
frame = 2000  'value 2

CCPR1H = frame.HB
CCPR1L = frame.LB


cntrh = cntr.HB
cntrl = cntr.LB


Gosub compare  'test  CCPR1 WORD  with a Cntr value, return with cmp1=1 if equal, else cmp1=0

lp1: Goto lp1  'dummy to stop the simulation

End                                               


compare:
Dim temp1 As Byte
cmp1 = 0
temp1 = CCPR1L - cntrl
ASM:        btfss STATUS,Z
Goto notcompare
temp1 = CCPR1H - cntrh
ASM:        btfss STATUS,Z
Goto notcompare
cmp1 = 1
Return                                           

notcompare:
cmp1 = 0
Return
 

Attachments

Thread Starter

camerart

Joined Feb 25, 2013
3,724
hi C,
A simple WORD compare basic program.
Try it.
E
Code:
Dim frame As Word
Dim cntr As Word
Dim cntrh As Byte
Dim cntrl As Byte

Dim cmp1 As Byte

cntr = 2000  'value 1
frame = 2000  'value 2

CCPR1H = frame.HB
CCPR1L = frame.LB


cntrh = cntr.HB
cntrl = cntr.LB


Gosub compare  'test  CCPR1 WORD  with a Cntr value, return with cmp1=1 if equal, else cmp1=0

lp1: Goto lp1  'dummy to stop the simulation

End                                              


compare:
Dim temp1 As Byte
cmp1 = 0
temp1 = CCPR1L - cntrl
ASM:        btfss STATUS,Z
Goto notcompare
temp1 = CCPR1H - cntrh
ASM:        btfss STATUS,Z
Goto notcompare
cmp1 = 1
Return                                          

notcompare:
cmp1 = 0
Return
Hi E,
I get the same result, but I'm puzzled by the ASM.
The program, I'm trying to get going compares a TIMER with CCPR1, and I can see the CCPR1 register TIMER running, but the setup isn't all there, so quite difficult.
Thanks.
C
 

ericgibbs

Joined Jan 29, 2010
18,766
hi,
The ASM line is just a simple way of testing that the previous subtraction gave a Zero result.
So the Z flag is Set when the result is zero, so the program jumps over the next line of code.
Then the program repeats the test for the other Byte.

If not zero, it means the two values being compared are not equal.
The code then exits the subroutine.
 

ericgibbs

Joined Jan 29, 2010
18,766
hi C,
Tidied up the example program code, can you follow it OK.
E
Code:
Dim frame As Word

frame = 2000  'test value

Dim cmp1 As Byte  'equal flag

Hseropen 9600

main:
'test data
CCPR1L = 0xcf  '1999
CCPR1H = 0x07
Gosub chk_equal
CCPR1L = 0xd0  '2000
CCPR1H = 0x07
Gosub chk_equal
CCPR1L = 0xd0  '2000
CCPR1H = 0x07
Gosub chk_equal
CCPR1L = 0xd1  '2001
CCPR1H = 0x07
Gosub chk_equal

Goto main

End                                               

'test  CCPR1 or Frame  WORD  with a frame value, return with cmp1=1 if equal, else cmp1=0
chk_equal:

If CCPR1L - frame.LB > 0 Then
Goto not_equal
Endif
If CCPR1H - frame.HB > 0 Then
Goto not_equal
Endif

'else equal
cmp1 = 1  'return flag
Hserout "Y", "  ", HexStr(CCPR1H), " ", HexStr(CCPR1L), CrLf  'test only
Return                                           

not_equal:
cmp1 = 0  'return flag
Hserout "N", "    ", HexStr(CCPR1H), " ", HexStr(CCPR1L), CrLf  'test only


Return
 

Attachments

Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
3,724
hi C,
Tidied up the example program code, can you follow it OK.
E
Code:
Dim frame As Word

frame = 2000  'test value

Dim cmp1 As Byte  'equal flag

Hseropen 9600

main:
'test data
CCPR1L = 0xcf  '1999
CCPR1H = 0x07
Gosub chk_equal
CCPR1L = 0xd0  '2000
CCPR1H = 0x07
Gosub chk_equal
CCPR1L = 0xd0  '2000
CCPR1H = 0x07
Gosub chk_equal
CCPR1L = 0xd1  '2001
CCPR1H = 0x07
Gosub chk_equal

Goto main

End                                             

'test  CCPR1 or Frame  WORD  with a frame value, return with cmp1=1 if equal, else cmp1=0
chk_equal:

If CCPR1L - frame.LB > 0 Then
Goto not_equal
Endif
If CCPR1H - frame.HB > 0 Then
Goto not_equal
Endif

'else equal
cmp1 = 1  'return flag
Hserout "Y", "  ", HexStr(CCPR1H), " ", HexStr(CCPR1L), CrLf  'test only
Return                                         

not_equal:
cmp1 = 0  'return flag
Hserout "N", "    ", HexStr(CCPR1H), " ", HexStr(CCPR1L), CrLf  'test only


Return
Hi E,
After watching it in the sim, and wondering where all the necessery settings are, I realised that this is software all through (is this correct?). If so, then this is similar to the software SERVO controller, of last week in ETO, that jitters. We are trying H/W as a test to eliminate jitter.

The program that I'm struggling with is software but compares the PIC hardware CCPR1 with a timer, and controls an added 'shift register', that I'm also learning.

It needs settings chosen e,g, PIE1, PIR1, T1CON, OSCCON etc, and for me it is difficult getting the correct combination (at my skill level).

Thanks for your comparison INTERRUPT program, I just about understand it. I appreciate the time spent, and it will be put in my examples folder.
Cheers, C.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,724
Hi,
I'm trying to visualise a program, that controls 8CH SERVO/MOTOR outputs, using a 'shift register'
I'm new to 'shift registers' and I've been looking at videos, so I've now got a pretty good understanding.
The 18F4431 program has 2x HW outputs that control the 'shift register' CLK and DATA.
At first I thought I could print out a strip of paper with CLK square wave, and mark how I think the CODE is switching, but of course now I know the paper would be miles long.
Using the OSH sim, with a break point at the INTERRUPT, I wrote down the CLKs and noted as much as I can, to get a picture.
I'll be hopefully clearer once I have a better understaning of what's going on.
C
 

Thread Starter

camerart

Joined Feb 25, 2013
3,724
Hi,
I've been on ETO, and have been developing a program, here is the latest, it's firing in the OSH SIM, but not correctly, can someone run it through a SIM please?
It uses an external 'shift' register, connected to 8xSERVOS, which is switched in H/W, so hopefully shouldn't jitter.

It was written in 'C' CODE, which with help, has been translated into OSH BASIC.

Here are both programs:

I've had difficulty understanding the speed, and CLK use of the INTERRUPTs, but slowly getting it.

I've been running the OSH program in the SIM, and it is almost working, but it's not easy to see quite what's going on.
Is there a LOG output in the OSH SIM?
C.
 

Attachments

Last edited:
Top