PDA

View Full Version : Serout/serout2



fowardbias
- 13th January 2006, 23:35
I need to get hex values, such as hex55, hex03,hex40 as a string out to PORTB.4 for a 16F628 using PBP.The communication should be 8N1 true, no parity. What I'm up to is attempting to drive a small serial H bridge driver. I have tried various string code with different DEFINES and INCLUDES and none has worked. At best there is a small hum from the motor. I put the H-bridge back on the BS2 dev. board using Stamp code and it runs perfectly. If someone could post a SEROUT hex string example it would help. The PBP manual seems a bit vague regarding communication strings.Thanks JS

mister_e
- 14th January 2006, 01:27
As far as i'm aware of, Stamp and PBP is not as this different... can you post the Stamp code?

fowardbias
- 14th January 2006, 03:29
Mr. E, I feel like the guy at the piano. Here's the BS2 code
FM CON 14
HIGH FM
Start_Up:
SEROUT FM,396,[$55,$00] '00 is the stop command
PAUSE 5000
SEROUT FM,396,[$55,$03,$40] 'first speed command
PAUSE 5000
SEROUT FM,396,[$55,$03,$80] 'second speed command

This repeats through several speed steps and loops back with GOTO Start_Up: The $55 is the sync, $03 is the set DC speed and the last part of the string is the 00 to FF speed levels. Details of this are from the Solutions Cubed group.
I tried using SEROUT and SEROUT2 with different mode numbers, string precedes, INCLUDES, DEFINES. Since the pinouts are different between the BS2 and 16F628 I could have had the pin path wrong. I tried to work this out with no change. Thanks for any help with this. JS

mister_e
- 14th January 2006, 20:00
mm are you saying that even if you change our code to...


FM VAR PORTB.4
HIGH FM
Start_Up:
SEROUT2 FM,396,[$55,$00] '00 is the stop command
PAUSE 5000
SEROUT2 FM,396,[$55,$03,$40] 'first speed command
PAUSE 5000
SEROUT2 FM,396,[$55,$03,$80] 'second speed command


It doesn't work???

you must use SEROUT2 to be BS2 compatible with the baudrate definition. 396 should be 2400,8,N,1. If you want to use SEROUT you'll write it like..


FM VAR PORTB.4
HIGH FM
Start_Up:
SEROUT FM,0,[$55,$00] '00 is the stop command
PAUSE 5000
SEROUT FM,0,[$55,$03,$40] 'first speed command
PAUSE 5000
SEROUT FM,0,[$55,$03,$80] 'second speed command


HTH

fowardbias
- 15th January 2006, 01:00
I tried both versions with the same result. I added DEFINE CHAR_PACING with different values, no go. I wrote a blink routine for PORTB outputs and they all checked good. The MCS is a little tricky to work with so I have been double checking the parameters before programming. I am using the internal osc. and have DEFINED it so in some programs, again no change. My scope is down with a bad cap and the part won't be in for awhile so there isn't a good way to look at the output. Digital voltmeter and connection checks show nothing unusual. Not a very good day at the keyboard. I seem to have hit the brick wall. Later JS

mister_e
- 15th January 2006, 03:08
If you use MPASM as assembler try...


@ __CONFIG _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _MCLRE_OFF & _LVP_OFF & _BODEN_ON
' Internal Oscillator
' Enable watch dog timer
' Enable power up timer
' Disable MCLR pin
' Disable low voltage programming
' Enable brown out detect


if you use PM as assembler, look and try all the suggestion in the FAQ section. There's a full thread wich discuss of HOW TO.

here it is => http://www.picbasic.co.uk/forum/showthread.php?t=543

fowardbias
- 15th January 2006, 05:23
If the MCS config. options list is correct regarding the device setup, why should it be necessary to add the redundant assembly code? Which has last say, the actual program code or the IDE controlling the up load. Never the less when I try adding the device config lines as they are presented from the site all I get is:
ERROR 16F628~5 ASM 45:[235] opcode expected instead of 'PIC16f628'

If I take the 16f628 out of the line, the error code changes to:
ERROR 16F628~ 5 ASM 45: [235] opcode expected instead of intc_osc_noclkout

The basic questions are:
What am I doing wrong regarding the code? If the program is OK,
Is it a hardware or sofware problem? Other options woulld be to: try another chip or install PBP into the MPLAB. I'm not ready for the latter. I guess my frustration is showing. JS

mister_e
- 15th January 2006, 12:16
O.K. Let's try something first. A very simple test program test to send a text string to your PC via COM port. You'll use the MCS serial communicator (F4 then F9 to connect to the PORT)




'
' Hardware configuration
' ======================
@ __CONFIG _INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_ON & _MCLRE_OFF & _LVP_OFF & _BODEN_ON
' Internal Oscillator
' Disable watch dog timer
' Enable power up timer
' Disable MCLR pin
' Disable low voltage programming
' Enable brown out detect

TRISB=0 ' PORTB : output to all i/o

'
' Hardware connection
' ===================
SerPin var PORTB.4 ' Serial data out connected via 1K resistor
' to PIN 2 of PC DB9 connector
' Don't forget the GND :o)

'
' Serial Communication definition
' ===============================
BAUD con 16780 ' 2400 Baud, Driven inverted, No Parity

'
' Software/Hardware initialisation
' ================================
serpin = 0 ' Set Serial data out to normal state
pause 100 ' safe settle time

'
' ////////////////////////////////|\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
'
' Program Start Here
'
' ////////////////////////////////|\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
'
START:
SEROUT2 SERPIN,BAUD,["PC COMMUNICATION TEST",13,10]
PAUSE 500
GOTO START

if you use PM as assembler, use the following config fuses OR set them manually.


'
' Hardware configuration
' ======================
asm
DEVICE PIC16F628, INTRC_OSC_NOCLKOUT ; Internal Oscillator
DEVICE PIC16F628, WDT_OFF ; Disable watch dog timer
DEVICE PIC16F628, PWRT_ON ; Enable power up timer
DEVICE PIC16F628, MCLR_OFF ; Disable MCLR pin
DEVICE PIC16F628, BOD_ON ; Enable brown out detect
DEVICE PIC16F628, LVP_OFF ; Disable low voltage programming
ENDASM


is the above work?

fowardbias
- 17th January 2006, 03:14
Mr.E,
As you suggested, I ran the communications test program through the serial port via the MCS and everything was right on. It filled up the receive window with the expected text. Without a scope check on RB4 when hooked up to the H-bridge I don't think I can do to much more with this, other than fine tuning the DEFINE CHAR_PACING ? If you have any other ideas on what to try I'll give them a go. Thanks for lifting the bar to the next level. JS

mister_e
- 17th January 2006, 03:44
well hard to say if the CHAR_PACING is the solution to this. It's possible that the internal OSC is not too much accurate for a proper serial comm to your device. mmm, can you try to use an external 4MHZ crystal (not ceramic resonator) first?

How about DEBUG function ?

How about the internal USART (HSERIN/HSEROUT)?

maybe.. maybe...

fowardbias
- 23rd January 2006, 06:48
Quick follow up on the H-bridge. I'm now running an external 14 Pin DIP clock at 4 Mhz.,100ppm. I ran the communications test program by adding the folowing ASM
DEVICE PIC16F628, XT_OSC
DEVICE PIC16F628, CPD_OFF
DEVICE PIC16F628, PROTECT_OFF
This makes the MCS come up right on without double checking everything.
The comm. test ran perfectly. The motor did the same routine....a little hum. I ran the motor supply volts up some to the bridge and one time it picked up one of the speeds, ? go figure? ,nothing after this one time event. I added character pacing of 1000, no change. I think I'll experiment with some different pacing values before moving into the USART. For those out there having unusal wierd problems with compiler errors when their code is exactly the same as a previous good program, I have found that there may be a glitch between going from one computer to another (different operating systems) with files on a 3 1/2 floppy. Maybe I have some bad disks although the formats were clean. Is the latest version of MCS OK or does the BETA need a little more BETTER? Later JS