News:

;) This forum is the property of Proton software developers

Main Menu

Proton & Positron USART Difference!

Started by bjkrs, Jun 29, 2023, 06:05 PM

Previous topic - Next topic

bjkrs

hi everyone,

I was using the proton basic 3.5.2.7 and I have this code, the code is working with proton basic.

'****************************************************************
'*  Name    : UNTITLED.BAS                                      *
'*  Author  : [S.Y]                                             *
'*  Notice  : Copyright (c) 2023 [S.Y]                          *
'*          : All Rights Reserved                               *
'*  Date    : 28.06.2023                                        *
'*  Version : 1.0                                               *
'*  Notes   :                                                   *
'*          :                                                   *
'****************************************************************
Device = 18F46K22
Declare Xtal = 10 ' I have 9.216 OSC
Declare PLL_Req = On

On_Hardware_Interrupt  GoTo usart_int

Declare Adin_Res 10       
Declare Adin_Tad FRC       
Declare Adin_Stime 50

Declare HSerin_Pin = PORTC.7
Declare HSerout_Pin = PORTC.6
Declare Hserial_RCSTA = %10010000 ' Enable serial port and continuous receive
Declare Hserial_TXSTA = %00100000 ' Enable transmit and asynchronous mode
Declare Hserial_Clear On
 
Declare LCD_DTPin = PORTD.4
Declare LCD_RSPin = PORTD.0
Declare LCD_ENPin = PORTD.1
Declare LCD_Interface = 4    
Declare LCD_Lines = 2  
Declare LCD_Type = Alphanumeric
Declare All_Digital = True
Clear

TRISC = %10111111

INTCON2.7 = 0  'pullups

INTCON.7 = 1   'all interrupts
INTCON.6 = 1   'peripheralinterrupt

PIE1.5 = 1     'USART Recive interrupt enable bit
PIR1.5 = 0     'USART Receive interrupt flag bit

BAUDCON.3 = 1
SPBRGH = 0
SPBRG = 19 ' because PLL is open, 9.216 x 4 = 36.864.. it means spbrg = 19

DelayMS 50

Dim Mxx As String * 8

GoTo mainfront

mainfront:

Print At 1,1, "   PIC <-> PC   "

GoTo main

main:

    Print At 2,1, "["
    Print At 2,6, "]      "
    Print At 2,2, Str Mxx\4
   
    If PORTB.0 = 0 Then GoTo butpress

GoTo main

butpress:

If PORTB.0 = 1 Then GoTo butpress2

GoTo butpress

butpress2:

HSerOut ["ok!",$13,$10]

GoTo main

usart_int:

Context Save
HSerIn 10,loope1,[Str Mxx]
loope1:
PIR1.5 = 0
Context Restore

End

then I get Positron Studio and now my code is not working with positron, it send and recieve irregular datas.

I was try change something but I can't fix it, Where I am doing wrong?


TimB


IMHO you need to rewrite your interrupt routine. If it worked before you are lucky but it was never right

Some tips

Do not use commands like HRSIN in an interrupt routine

I looks like you have a timeout. You are better to have an independent timer and set a flag once a period has elapsed from the last char.

Tomorrow I will post code I use
 


RGV250

Hi,
You have not declared the baud rate, I am assuming you are manipulating BAUDCON & SPBRGH etc, this could cause errors if you get it slightly wrong.
Why make life difficult for yourself when Les has done all the hard work for you.
From the manual.
QuoteDeclare Hserial_Baud = 9600 ' Set Baud rate to 9600 for HRsin and HRsout

Bob

tumbleweed

I think the OP is stuck manually setting up the registers since he appears to be using a 9.216MHz osc w/4x PLL (36.864MHz).

With those settings (BRG16=1, BRGH=0, SPBRGH=0, SPBRG=19) I get exactly 115200 baud.



bjkrs

Quote from: RGV250 on Jun 29, 2023, 09:05 PMHi,
You have not declared the baud rate, I am assuming you are manipulating BAUDCON & SPBRGH etc, this could cause errors if you get it slightly wrong.
Why make life difficult for yourself when Les has done all the hard work for you.
From the manual.
QuoteDeclare Hserial_Baud = 9600 ' Set Baud rate to 9600 for HRsin and HRsout

Bob

Hi Bob, actually I declared the baudrate,

baudcon.3=1
SPRG = 19

it means baudrate is 115.200 (we can calculate with the help of "spbrgcalculator.exe")

bjkrs

Quote from: TimB on Jun 29, 2023, 08:36 PMIMHO you need to rewrite your interrupt routine. If it worked before you are lucky but it was never right

Some tips

Do not use commands like HRSIN in an interrupt routine

I looks like you have a timeout. You are better to have an independent timer and set a flag once a period has elapsed from the last char.

Tomorrow I will post code I use
 



hi Tim,

Actually I was use this code many years for PIC-PC communication, and this code have %0 error.

And I was use this code in my industrial projects too.

I think I have to use HSERIN command inside of my interrupt routine, because I need PC-PIC communication every moment, every line of my code. I think only interrupts can do this but if you know any other method for this, I am open for every solutions.

thanks..

bjkrs

Quote from: tumbleweed on Jun 29, 2023, 10:35 PMI think the OP is stuck manually setting up the registers since he appears to be using a 9.216MHz osc w/4x PLL (36.864MHz).

With those settings (BRG16=1, BRGH=0, SPBRGH=0, SPBRG=19) I get exactly 115200 baud.




hi tumbleweed,

Yes I want to use 115200 baud, as you say

bjkrs

hi Tim, Bob and tubleweed;

thanks for your answers and supports

I think I understand my problem,

I think positron studio not accepts this code

"Declare PLL_Req = On"

because when I delete this code and convert my spbrg value for 9.216 (not with pll) my code works perfect with positron.

ok I have a new problem, How can I make active the PLL in my code  ;D  ;D

tumbleweed

You can enable it with a config setting
Config_Start
  PLLCFG = On
Config_End

or by setting OSCTUNE.6 = 1 (PLLEN) in your code

bjkrs

Quote from: tumbleweed on Jun 30, 2023, 10:31 AMYou can enable it with a config setting
Config_Start
  PLLCFG = On
Config_End

or by setting OSCTUNE.6 = 1 (PLLEN) in your code

thanks for your support

Stephen Moss

I took a look back the the old document I wrote on the different ways of using PLL with devices and I had Declare PLL_Req = True, not Declare PLL_Req = On so you could try that, although upon trying to double check the comments I made from the Manual...
Quotemanual states that the PLL_Req declare sets the PLL config fuse. It achieves this by changing the PDS default fuse setting (as specified in the PPI files) of either the OSC fuses to HSPLL or the PLL Enable fuse to ON (device dependant) however; it only has that effect if no fuse configuration data has been entered. If any fuse configuration data has been entered the PLL_Req declares only effect is to tell the compiler to base its timing calculations on a frequency four times greater than that specified in the Xtal declare.
However, I could not find the PLL_Req Declare anywhere in the manual, not sure if that is an error or inidcates it has been rendered obsolete due to the difficulties of maintianing it as a result of the constantly changing ways devices handle enabling the PLL.

@bjkrs, generally a Goto would be used to jump a section of code and continue from the new location.
If you want to jump to a section code and then return back to where you jumed from you would generally use a Subrouteine instead of multiple GoTo's that jump around all over the place as the resulting code can look rather clunky and be difficult to follow not only for yourself but for those trying to help you. Particualry in larger program as it can then be difficulty to keep track of where you have jumped from/to, so rather than...
    If PORTB.0 = 0 Then GoTo butpress
GoTo main

butpress:

If PORTB.0 = 1 Then GoTo butpress2

GoTo butpress

butpress2:

HSerOut ["ok!",$13,$10]

GoTo main

You could use something like
If PORTB.0 = 0 Then GoSub butpress  'Jump To Subrroutine
GoTo main

butpress:  'Start of Subroutine
While PORTB.0 = 0  'Wait for button to be released
Wend

HSerOut ["ok!",$13,$10]  'Send serial Data

Return  'Go back to Main loop

 or alternatively the more recently added alternative way of writing subroutine...
If PORTB.0 = 0 Then butpress()  'Jump To Subrroutine
GoTo main

Sub butpress()  'Start of Subroutine
Repeat
Until PORTB.0 = 1  'Alternative method to wait for button to be released

HSerOut ["ok!",$13,$10]  'Send serial Data

EndSub  'Go back to Main loop
Just something you may want to condsider in future, but I would suggest getting used to the second method as its structure is similar to that of Proceedures so becomming familar with that may make using Proceedure easier when the time comes.

bjkrs

Quote from: Stephen Moss on Jul 01, 2023, 12:15 PMI took a look back the the old document I wrote on the different ways of using PLL with devices and I had Declare PLL_Req = True, not Declare PLL_Req = On so you could try that, although upon trying to double check the comments I made from the Manual...
Quotemanual states that the PLL_Req declare sets the PLL config fuse. It achieves this by changing the PDS default fuse setting (as specified in the PPI files) of either the OSC fuses to HSPLL or the PLL Enable fuse to ON (device dependant) however; it only has that effect if no fuse configuration data has been entered. If any fuse configuration data has been entered the PLL_Req declares only effect is to tell the compiler to base its timing calculations on a frequency four times greater than that specified in the Xtal declare.
However, I could not find the PLL_Req Declare anywhere in the manual, not sure if that is an error or inidcates it has been rendered obsolete due to the difficulties of maintianing it as a result of the constantly changing ways devices handle enabling the PLL.

@bjkrs, generally a Goto would be used to jump a section of code and continue from the new location.
If you want to jump to a section code and then return back to where you jumed from you would generally use a Subrouteine instead of multiple GoTo's that jump around all over the place as the resulting code can look rather clunky and be difficult to follow not only for yourself but for those trying to help you. Particualry in larger program as it can then be difficulty to keep track of where you have jumped from/to, so rather than...
    If PORTB.0 = 0 Then GoTo butpress
GoTo main

butpress:

If PORTB.0 = 1 Then GoTo butpress2

GoTo butpress

butpress2:

HSerOut ["ok!",$13,$10]

GoTo main

You could use something like
If PORTB.0 = 0 Then GoSub butpress  'Jump To Subrroutine
GoTo main

butpress:  'Start of Subroutine
While PORTB.0 = 0  'Wait for button to be released
Wend

HSerOut ["ok!",$13,$10]  'Send serial Data

Return  'Go back to Main loop

 or alternatively the more recently added alternative way of writing subroutine...
If PORTB.0 = 0 Then butpress()  'Jump To Subrroutine
GoTo main

Sub butpress()  'Start of Subroutine
Repeat
Until PORTB.0 = 1  'Alternative method to wait for button to be released

HSerOut ["ok!",$13,$10]  'Send serial Data

EndSub  'Go back to Main loop
Just something you may want to condsider in future, but I would suggest getting used to the second method as its structure is similar to that of Proceedures so becomming familar with that may make using Proceedure easier when the time comes.
Hi Stephen,

Thanks for your Subroutine advice, I will try to get use to it.

As for the PLL_REG thing

I am using positron now, I think its accept both of them (true or on)