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

Thread Starter

camerart

Joined Feb 25, 2013
3,853
hi C,
His binary value is 0x55AA, so it cannot be used with CCPR1
It should be
CCPR1L = 0xAA.
CCPR1H =0x55

E
Hi E,
He wrote his CODE in 'C' so I used AI and whatever skill I have to translate it to OSH BASIC.

I was looking at this in the program:
=================================================
CCP1CON = %00001000 '& h8 'CCP1 pin low and high on match - will be first pulse
CCPR1 = frame '2000 'start pulse in 0.25mS (2000 clock cycles) [ FRAME compiles 2000 doesn't!!!!!!!!
PIE1.CCP1IE = 1 'enable CCP1 interrupts
====================================================
So should it be this:?
==========================================================
CCP1CON = %00001000 '& h8 'CCP1 pin low and high on match - will be first pulse
CCPR1L = frame.LB '2000 'start pulse in 0.25mS (2000 clock cycles) [ FRAME compiles 2000 doesn't!!!!!!!!
CCPR1H = frame.HB '2000
'start pulse in 0.25mS (2000 clock cycles)
PIE1.CCP1IE = 1 'enable CCP1 interrupts
=============================================
C
 

ericgibbs

Joined Jan 29, 2010
21,621
hi C.
In the following Code, I assume you have defined Frame as a WORD
Dim Frame as Word
Frame = 2000' I prefer 0x07D0

CCP1CON = %00001000 '& h8 'CCP1 pin low and high on match - will be first pulse
CCPR1L = frame.LB '2000 ' loads Low Byte 0xD0 into Lo
CCPR1H = frame.HB '2000 'loads High Byte 0x07 into Hi
PIE1.CCP1IE = 1 'enable CCP1 interrupts


Example of compile and run with this Code section in your earlier Program.
Note the 2000 decimal in in the Frame register.

EG57_ 502.png
 
Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
3,853
hi C.
In the following Code, I assume you have defined Frame as a WORD
Dim Frame as Word
Frame = 2000' I prefer 0x07D0

CCP1CON = %00001000 '& h8 'CCP1 pin low and high on match - will be first pulse
CCPR1L = frame.LB '2000 ' loads Low Byte 0xD0 into Lo
CCPR1H = frame.HB '2000 'loads High Byte 0x07 into Hi
PIE1.CCP1IE = 1 'enable CCP1 interrupts
Hi E,
Ok, thanks.
Dim frame as word. Y
It worked :)

I notice that programmers prefer e,g, 0x07D0 than the easily readable DEC number, why? My guess, is that it saves a calculation?

Here is a similar line to the one above, how should this be?
[ CCPR1 = CCPR1 + 4000 ]
C.
 
Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
3,853
hi
CCPR1 = CCPR1 + 4000
This dummy run suggests it is ignored by OSH.
E

View attachment 286078
Hi E,
I tried a similar test and it showed that it write LB only.
As above, I am now trying to get the HB to write too

Reminder, the AA's were changed to aa's at compile.
C.
======================
Main_loop:


'CCPR1H = 0x55
'CCPR1L = 0xaa
Dim test As Word
test = 0x55aa

CCPR1 = test


Goto Main_loop
===================================
 

Thread Starter

camerart

Joined Feb 25, 2013
3,853
hi
CCPR1 = CCPR1 + 4000
This dummy run suggests it is ignored by OSH.
E

View attachment 286078
Hi E,
This works.
C.
==========================================
Dim frame As Word
frame = 0x07d0 '2000

Dim framehb As Byte
framehb = frame.HB
Dim framelb As Byte
framelb = frame.LB

Main_loop:

CCPR1H = framehb
CCPR1L = framelb

Goto Main_loop
 

Attachments

sagor

Joined Mar 10, 2019
1,056
I notice in data sheet an example something like:
CCPR1H:CCPR1L = 0x0465

does that work in Oshonsoft
If not, then you have to work with bytes and/or mapping HB and LB
 

Thread Starter

camerart

Joined Feb 25, 2013
3,853
I notice in data sheet an example something like:
CCPR1H:CCPR1L = 0x0465

does that work in Oshonsoft
If not, then you have to work with bytes and/or mapping HB and LB
Hi S,
So far I haven't been able to get 16BIT compare working!
The D/S is a bit spaghetti around this.
I tried the RD16 bit and the Compare mode; Special Event Trigger
C.
 

jjw

Joined Dec 24, 2013
823
Hi E,
This works.
C.
==========================================
Dim frame As Word
frame = 0x07d0 '2000

Dim framehb As Byte
framehb = frame.HB
Dim framelb As Byte
framelb = frame.LB

Main_loop:

CCPR1H = framehb
CCPR1L = framelb

Goto Main_loop
Why the extra steps?
framehb = frame.HB
CCPR1H = framehb

when can be written: CCPR1H = frame.HB
 

Thread Starter

camerart

Joined Feb 25, 2013
3,853
Why the extra steps?
framehb = frame.HB
CCPR1 = framehb,
when CCPR1 = frame.HB is the same
Hi J,
I'm not sure I follow what you mean.

If you can post the same as I posted, but with your idea instead, I'll test and post the result.
Thanks.
C
 

Thread Starter

camerart

Joined Feb 25, 2013
3,853
hi C.
Why not just

CCPR1H = 0x07
CCPR1L = 0xD0
or
CCPR1H = Frame.HB
CCPR1L = Frame.LB
Hi E,
I suppose this is ok, but I'm trying to edit a program that was written in 'C' and translated by AI, which has 2000. This didn't work, so I ded a variable FRAME which is = to 2000.
As someone else wrote it for me, I try to keep is as near to what they wrote as I can.
C
 

Thread Starter

camerart

Joined Feb 25, 2013
3,853
hi C<
My advice would be to forget about AI, use techniques you understand.
E
Hi E,
Only yesterday I was adviced (again) to learn 'C' I've been programming in BASIC since 1982, and still have to look up many things, that would seem ridiculous, I have to accept my failings, and move forward.
As for AI, it reshaped the 'C' CODE in BASIC shape that I can almost read, and this is the best I can do.
C
 

jjw

Joined Dec 24, 2013
823
Hi E,
I suppose this is ok, but I'm trying to edit a program that was written in 'C' and translated by AI, which has 2000. This didn't work, so I ded a variable FRAME which is = to 2000.
As someone else wrote it for me, I try to keep is as near to what they wrote as I can.
C
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
 

Thread Starter

camerart

Joined Feb 25, 2013
3,853
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
Hi J,
I'm sure there are differences between the 'C' comiler and after all of the translations up to the OSH program, I'm testing.
All I can do is try to post results and see if can be made to work.

There may be problems with timing, as the 2x BYTES are written in sequence, but that's beyond my understanding.
C.
 
Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
3,853
Hi,
It has been impossible to get SERVOs to run without slight jitter.

I've been on ETO and the latest is using the HW, and an extra shift register, to use the CCP1 COMPARE.

I haven't finished the electronics yet, also as can be seen the latest program isn't compiling properly yet.
C
 
Top