Oshonsoft programs with INTERRUPTS and PARSE

jjw

Joined Dec 24, 2013
823
If you have an oscilloscope then use it. It gives better information than an LED at high frequencies.

Write a main loop to toggle an LED without using delay.
Show your code and report back.
The program in #54 is for the simulator.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,730
If you have an oscilloscope then use it. It gives better information than an LED at high frequencies.

Write a main loop to toggle an LED without using delay.
Show your code and report back.
Hi Mr C,
I have an oscilloscope, but I also have a simulator, shown here, which is good for this sort of thing.
Here it shows the Program and result:
C
 

Attachments

jjw

Joined Dec 24, 2013
823
This is a barebones Oshonsoft simulator demo to receive a message by interrupts.
No checking of errors, overflows, message start characters etc.
You have to do the hard work.

Code:
'**** Oshonsoft Basic Simulation for USART Rx with interrupts
'PIC8LF4620 8MHz

Define SIMULATION_WAITMS_VALUE = 1 
Define CLOCK_FREQUENCY = 8

'*** Setup interrupts ***

RCON.IPEN = 1  'IPEN: Int Priority Enable bit 'This MUST be included when using Interrupts (Priority HIGH/LOW)[#189 hserin blocking]
PIE1 = %00100000  'RCIE: EUSART Receive Interrupt Enable bit [ 1=en ]
INTCON.PEIE = 1  'PEIE/GIEL: Peripheral Interrupt Enable bit
INTCON.GIE = 1  'GIE/GIEH: Global Interrupt Enable bit *** s

' **** Setup Hw USART ****
Hseropen 9600  

Dim char As Byte
Dim str1(20) As Byte ' *** received message comes to str1
Dim rxi As Byte    ïndex to Str1
Dim msg_rdy As Bit

rxi = 0
msg_rdy = 0
Enable High

Main:
Break  '***stop and put a short msg ending with "!" in to Simulator Rx window

While not msg_rdy // **** the real program can run here and check msg_rdy as needed
Wend

Break  '**** stop, now the Str1 can be looked at the variable window

End                                              

On High Interrupt
Save System

If PIR1.RCIF = 1 Then
  char = RCREG
  str1(rxi) = char
  rxi = rxi + 1
Endif

If char = "!" Then  ' ***  ends the message ****
  msg_rdy = 1
Endif
Resume
 
Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
3,730
This is a barebones Oshonsoft simulator demo to receive a message by interrupts.
No checking of errors, overflows, message start characters etc.
You have to do the hard work.

Code:
'**** Oshonsoft Basic Simulation for USART Rx with interrupts
'PIC8LF4620 8MHz

Define SIMULATION_WAITMS_VALUE = 1
Define CLOCK_FREQUENCY = 8

'*** Setup interrupts ***

RCON.IPEN = 1  'IPEN: Int Priority Enable bit 'This MUST be included when using Interrupts (Priority HIGH/LOW)[#189 hserin blocking]
PIE1 = %00100000  'RCIE: EUSART Receive Interrupt Enable bit [ 1=en ]
INTCON.PEIE = 1  'PEIE/GIEL: Peripheral Interrupt Enable bit
INTCON.GIE = 1  'GIE/GIEH: Global Interrupt Enable bit *** s

' **** Setup Hw USART ****
Hseropen 9600 

Dim char As Byte
Dim str1(20) As Byte ' *** received message comes to str1
Dim rxi As Byte    ïndex to Str1
Dim msg_rdy As Bit

rxi = 0
msg_rdy = 0
Enable High

Main:
Break  '***stop and put a short msg ending with "!" in to Simulator Rx window

While not msg_rdy // **** the real program can run here and check msg_rdy as needed
Wend

Break  '**** stop, now the Str1 can be looked at the variable window

End                                             

On High Interrupt
Save System

If PIR1.RCIF = 1 Then
  char = RCREG
  str1(rxi) = char
  rxi = rxi + 1
Endif

If char = "!" Then  ' ***  ends the message ****
  msg_rdy = 1
Endif
Resume
Hi J,
And I was looking forward to doing this myself ;)

Thanks very much, I'll put the Aspirin away, much appreciated.

Regarding the 8BIT 16 BIT choice: [ RCSTA.RX9 = 0 '0 = Selects 8-bit reception ] and This routine uses 8BIT, but later there are H and L BYTES, should this be set for 8 or 16BIT?

Regarding the BAUD rate: How do I select [ BAUDCON.BRG16 = 1 '1 = 16-bit Baud Rate Generator – SPBRGH and SPBRG ] ?
Thanks, C.
 

jjw

Joined Dec 24, 2013
823
Hi J,
And I was looking forward to doing this myself ;)

Thanks very much, I'll put the Aspirin away, much appreciated.

Regarding the 8BIT 16 BIT choice: [ RCSTA.RX9 = 0 '0 = Selects 8-bit reception ] and This routine uses 8BIT, but later there are H and L BYTES, should this be set for 8 or 16BIT?

Regarding the BAUD rate: How do I select [ BAUDCON.BRG16 = 1 '1 = 16-bit Baud Rate Generator – SPBRGH and SPBRG ] ?
Thanks, C.
I think Hseropen 9600 takes care of it. It is command for HW Usart
 

jjw

Joined Dec 24, 2013
823
Hi E,
My question was more to do with setting up UART or PIC.
The UART uses 8BIT, but the MAIN LOOP uses Two's compliment H and L.
As I'm setting up the UART, I assme that I should set that setting to 8BIT, but for the SPI H an L BYTEs they will need 16BIT.
Thanks, C.
Can't you just send 16bit as two 8bit bytes, when you know where they are in the message?
 

Thread Starter

camerart

Joined Feb 25, 2013
3,730
Can't you just send 16bit as two 8bit bytes, when you know where they are in the message?
Hi J,
I just checked on one of the peripheral D/S and it appears that one SENDs 3x BYTEs. I'll leave this till later, and leave the UART [ RCSTA.RX9 ] set to 8BIT, for now. thanks.
C.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,730
hi,
'While msg_rdy = 0 'the real program can run here and check msg_rdy as needed

When is msg_rdy NOT = 0. ?

E
Hi E,
This is a temporary LOOP, that is broken by the INTERRUPT, and will not be there once the MAIN program comes back.

I haven't checked the actual timing, but just watching the SIM, I'm surprised by the time the processor has to go back to the MAIN LOOP in between $ Sentence digits, coming in.

If you're testing with the SIM, here are some sentences:
$GPRMC,123519,A,4807.038,N,01131.000,W,022.4,084.4,230394,003.1,W*6A?

$GPRMC,123519,A,4807.038,N,01131.000,W,W*6A? ['C' = HEX 0X43 DEC 67]
$QEIDEG,123,W [ 'D' = HEX 0X47 DEC 71]

$REMOTE,12,20,50,W [remvolt,remalt,remdist],? [ 'R' = HEX 0X52 DEC 82]
C
 
Last edited:

jjw

Joined Dec 24, 2013
823
Hi E,
This is a temporary LOOP, that is broken by the INTERRUPT, and will not be there once the MAIN program comes back.

I haven't checked the actual timing, but just watching the SIM, I'm surprised by the time the processor has to go back to the MAIN LOOP in between $ Sentence digits, coming in.

If you're testing with the SIM, here are some sentences:
$GPRMC,123519,A,4807.038,N,01131.000,W,022.4,084.4,230394,003.1,W*6A?

$GPRMC,123519,A,4807.038,N,01131.000,W,W*6A? 'C' = HEX 0X43 DEC 67

$QEIDEG,123,W 'D' = HEX 0X47 DEC 71

$REMOTE,12,20,50,W [remvolt,remalt,remdist],? 'R' = HEX 0X52 DEC 82
C
In the ISR when at the end of the message set msg_rdy = 1
 

jjw

Joined Dec 24, 2013
823
Hi E,
This is a temporary LOOP, that is broken by the INTERRUPT, and will not be there once the MAIN program comes back.

I haven't checked the actual timing, but just watching the SIM, I'm surprised by the time the processor has to go back to the MAIN LOOP in between $ Sentence digits, coming in.

If you're testing with the SIM, here are some sentences:
$GPRMC,123519,A,4807.038,N,01131.000,W,022.4,084.4,230394,003.1,W*6A?

$GPRMC,123519,A,4807.038,N,01131.000,W,W*6A? 'C' = HEX 0X43 DEC 67

$QEIDEG,123,W 'D' = HEX 0X47 DEC 71

$REMOTE,12,20,50,W [remvolt,remalt,remdist],? 'R' = HEX 0X52 DEC 82
C
The simulator is really slow when receiving characters.
A message ~5 charactes took tens of seconds in the original demo.
Real time execution of the ISR is about 40us at 8MHz.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,730
The simulator is really slow when receiving characters.
A message ~5 charactes took tens of seconds in the original demo.
Real time execution of the ISR is about 40us at 8MHz.
Hi J,
The simulator is really slow when receiving characters.
I know, from the hours, I've sat watching it :)

A message ~5 charactes took tens of seconds in the original demo.
Real time execution of the ISR is about 40us at 8MHz.

I'm not used to these speeds, so take some comprehending, but my thought was that there appears to be some time in between the $Sentence digits, for the processor to work on the MAIN LOOP, until the next digit.
C
 

ericgibbs

Joined Jan 29, 2010
18,849
hi C,
This is a simple working bit of code, you should be able to add to it.
Every incoming RX char generates an Interrupt.

Run it,
Type in
$1234? or any other String starting with $ and ending with ? [ ==crlf], it should display the full string.
then type in a test string without the starting $, it should print Error.

Do you follow OK.?
E
 

Attachments

jjw

Joined Dec 24, 2013
823
Hi J,
The simulator is really slow when receiving characters.
I know, from the hours, I've sat watching it :)

A message ~5 charactes took tens of seconds in the original demo.
Real time execution of the ISR is about 40us at 8MHz.

I'm not used to these speeds, so take some comprehending, but my thought was that there appears to be some time in between the $Sentence digits, for the processor to work on the MAIN LOOP, until the next digit.
C
The ISR slows the processor less than 4% at 8MHz. How critical it is to detect fast the end of the message ?
 
Top