PDA

View Full Version : Need help, high speed D/A converter, see code



rpatel
- 19th December 2004, 04:14
I can't get the HSERIN to work on simple PIC asynchronous transmit and recieve

*Running at 115200bps
(using 22.1184MHz xstal, for 0%error baud rate)
*transmitter is a PIC18F252
*reciever is a PIC18F252

Transmitter:

'HARDWARE DECLARATIONS (defines and port settings)
Define OSC 20 '0% baud error with 22.1184Mhz xstal
Define HSER_RCSTA 90h 'PIC Hardware Serial Port Receiver define
Define HSER_TXSTA 24h 'PIC Hardware Serial Port Transmit
define HSER_SPBRG 11 'Zero error SPBRG integer value
define ADC_BITS 8 '8 bit sampling ADC define
define ADC_SAMPLEUS 5 'Analog data sample time
TRISA = 255 'Set PORTA to all input
ADCON1 = 0 'PORTA set to analog use for ADC
'VARIABLES
wilma var byte '[3] 'Variable for Accelerometer data
I var byte 'Variable for counter label
'PROGRAM
i = 0
wilma = 0
Pause 5000
'************************
Start:
ADCIN 0, wilma'
wilma=(wilma*3)-50
hserout [wilma]
pause 10
goto Start
End
'************

Reciever:
'HARDWARE DECLARATIONS (defines and port settings)
Define OSC 20
Define HSER_RCSTA 90h 'PIC Hardware Serial Port Receiver
Define HSER_TXSTA 24h 'PIC Hardware Serial Port Transmit using "20h"
define HSER_SPBRG 11 'Zero error SPBRG integer value
'VARIABLES
Fred Var byte
'PROGRAM
'**********************
Start:
hserin [bin Fred] 'Hardware Rx Pin C.7 (pin #18) on PIC18F252
hpwm 1, Fred, 20000 'Hardware HPWM Pin CCP1 (pin #13) on PIC18F252
goto start
End
'**************************

mister_e
- 19th December 2004, 13:02
i'm not sure how PBP will handle this baudrate crystal with a define osc of 20MHZ... i guess everything will run 22.1184/20 time faster SO, SPBRG must be 22.1184/20 = 1.10592 slow

SPBRG=10 'should be 9.946...

Or maybe i'm totally wrong there...

BUT, can you try 20MHZ one with a simple

DEFINE HSER_BAUD 115200

instead of setting SPBRG to test only! if nothing is different try at a slower baudrate, let's say 2400.

suggest to include this line in your receiver too to avoid buffer overrun...
DEFINE HSER_CLROERR 1


BUT, what happen when you connect via MAX232 to your PC. Can you receive/transmitt correctly???

P.S wilma=(wilma*3)-50.... and wilma is a BYTE ?!? Should be word IMO.

rpatel
- 19th December 2004, 16:54
I simply used the equation sets given in the picbasic pro manual for figuring xstal and spbrg for a needed baud rate.
See attached Excel spreadsheet.
I found another similar calculator(Excel) at this forum.
(don't fret that variable wilma has some math to it, its a byte)
..
Also, I have successfully communicated to a PC, and verified input data thru VB6 coding (at 115200 bps).
..
And, verified bit timing and logic level voltages on a O-scope.
..
SEE ATTACHED FILES.
..
It seems as if there are other issues with HSERIN in the forum, and some are solved by watching the RCIF flag and then loading the RCREG into a byte variable., this didn't work for me.
..
IS there anyplace that explains the HSERIN command completely?..
..
I don't understand a few things about the command:
my interpretation of Pic basic pro manual:
HSERIN (parity) , (timeout goto label), [variable to load into]
..
but from what I have seen in the forum, its actually:
HSERIN (time in ms for timeout), (timeout goto lable), [variable to load into]
..
Much appreciated thanks for anyone's help!!
..

mister_e
- 19th December 2004, 22:34
what about if you remove *bin* modifier in HSERIN?
hserin [Fred] 'Hardware Rx Pin C.7 (pin #18) on PIC18F252

rpatel
- 19th December 2004, 23:06
tried:
hserin [fred]
hserin [dec fred]
hserin [dec3 fred]
hserin [bin fred]
hserin 100, Nope, [fred]
...
etc....
I must have reprogrammed the PIC over 100 times.
..
regards,

mister_e
- 19th December 2004, 23:22
Your settings are O.k.

How do you interface your PIC to PC, PC to PIC ???

rpatel
- 20th December 2004, 01:33
I have done several things, with respect to this project, I have serial HSEROUT(0-5v) to a rs232 transciever-6 to +6v) to a pc.