Announcement

Collapse
No announcement yet.

Issue with DEC modifier and 18F26K83

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Issue with DEC modifier and 18F26K83

    Hi,

    When using the DEC modifier with HSEROUT on this MCU I am having some issues. If I run the code below, the serial output is:

    Testbyte=

  • #2
    I'll try again... something went wrong with the post formatting..

    Hi,

    When using the DEC modifier with HSEROUT on this MCU I am having some issues. If I run the code below, the serial output is (without the quotes):

    "Testbyte=

    Comment


    • #3
      My post keeps getting truncated... not sure what is going on..


      When using the DEC modifier with HSEROUT on this MCU I am having some issues. If I run the code below, the serial output is:

      Testbyte=

      Comment


      • #4
        There must be something in the text that is upsetting the forum formatting.... Let's try again....

        When using the DEC modifier with HSEROUT on this MCU I am having some issues. If I run the code below, the serial output is:

        See attached image

        If the HSEROUT line is changed to hserout ["Testbyte= ",testbyte,10,13] the serial output is:

        Testbyte= 2

        which is expected.

        Not sure what is going on.

        Code has been copied and pasted directly from MicroCode Studio Plus and some of the formatting has been lost (i.e. capitalization of directives). Compiler version is PBPX 3.1.1.4


        DEFINE OSC 64

        DEFINE HSER_RXREG PORTC
        DEFINE HSER_RXBIT 7
        DEFINE HSER_TXREG PORTC
        DEFINE HSER_TXBIT 6
        DEFINE HSER_BAUD 115200

        clear
        Testbyte var byte

        TRISA = %00000000 '
        TRISB = %00001000 '
        TRISC = %10000000 '

        testbyte = 50

        main:

        hserout ["Testbyte= ",testbyte,10,13]
        pause 200
        goto main

        Comment


        • #5
          Do I understand correctly that with the DEC modifier, it doesn't output "50"?

          You aren't using defines for RCSTA and TXSTA. Have you checked the bit-timing with an oscilloscope?

          What is in play on the receiving side? (Serial Communicator, HyperTerminal, TeraTerm, etc.) Have you tried something different there?

          I have the chip for testing, but it will take me a while to set it up.
          Charles Leo
          ME Labs, Inc.
          http://melabs.com

          Comment


          • #6
            Andy, Try this:
            hserout ["Testbyte= ",DEC testbyte,10,13]

            I also notice that you are sending a "50" value to the serial port and it is un-formatted. If the receiving side was working correctly it would print a character "2".

            Also judging by the remainder of the received message I would suspect a baud rate issue. Possibly on the receiving side.

            Try lowering the baud rate and give it another try.
            Dave Purola,
            N8NTA
            EN82fn

            Comment


            • #7
              Thank for the replies so far.

              Charles - you are correct. When using the DEC modifier it does not output "50". If I remove the DEC modifier the output is ASCII "2", which of course is 50 decimal.

              I have added defines for RCSTA and TXSTA - no change.

              I have reduced the baud rate to 9600 - no change.

              Initially I was using Serial Communicator to receive the data. I have also checked the output using RealTerm and it is the same.

              By way of background, I have been using this exact hardware to transmit and receive CAN packets at 250 kBit/s with no issue. As part of this setup, HSEROUT was used as below with the HEX2 modifier at 115200 baud and it works as expected:

              HSEROUT [HEX2 PGN1,HEX2 PGN2," ",HEX2 RXB0D0," ",HEX2 RXB0D1," ",HEX2 RXB0D2," ",HEX2 RXB0D3," ",HEX2 RXB0D4," ",HEX2 RXB0D5," ",HEX2 RXB0D6," ",HEX2 RXB0D7,10,13]

              Because of the above, I do not believe there is a problem with the hardware or bit timings etc.

              I had to post the output from Serial Communicator as an image - one of the control codes in the string must upsetting the online forum formatting as it kept truncating my posts at that point.

              My full test code is below:


              Code:
               #CONFIG
                  CONFIG FEXTOSC = HS        ;HS (crystal oscillator) above 8 MHz; PFM set to high power
                  CONFIG RSTOSC = EXTOSC_4PLL        ;EXTOSC with 4x PLL, with EXTOSC operating per FEXTOSC bits
                  CONFIG CLKOUTEN = OFF        ;CLKOUT function is disabled
                  CONFIG PR1WAY = OFF        ;PRLOCK bit can be set and cleared repeatedly
                  CONFIG CSWEN = ON        ;Writing to NOSC and NDIV is allowed
                  CONFIG FCMEN = OFF        ;Fail-Safe Clock Monitor disabled
                  CONFIG MCLRE = EXTMCLR        ;If LVP = 0, MCLR pin is MCLR; If LVP = 1, RE3 pin function is MCLR
                  CONFIG PWRTS = PWRT_64        ;PWRT set at 64ms
                  CONFIG MVECEN = OFF        ;Interrupt contoller does not use vector table to prioritze interrupts
                  CONFIG IVT1WAY = OFF        ;IVTLOCK bit can be cleared and set repeatedly
                  CONFIG LPBOREN = OFF        ;ULPBOR disabled
                  CONFIG BOREN = ON        ;Brown-out Reset enabled according to SBOREN
                  CONFIG BORV = VBOR_245        ;Brown-out Reset Voltage (VBOR) set to 2.45V
                  CONFIG ZCD = OFF        ;ZCD disabled. ZCD can be enabled by setting the ZCDSEN bit of ZCDCON
                  CONFIG PPS1WAY = OFF        ;PPSLOCK bit can be set and cleared repeatedly (subject to the unlock sequence)
                  CONFIG STVREN = ON        ;Stack full/underflow will cause Reset
                  CONFIG DEBUG = OFF        ;Background debugger disabled
                  CONFIG XINST = OFF        ;Extended Instruction Set and Indexed Addressing Mode disabled
                  CONFIG WDTCPS = WDTCPS_31        ;Divider ratio 1:65536; software control of WDTPS
                  CONFIG WDTE = OFF        ;WDT Disabled; SWDTEN is ignored
                  CONFIG WDTCWS = WDTCWS_7        ;window always open (100%); software control; keyed access not required
                  CONFIG WDTCCS = LFINTOSC        ;WDT reference clock is the 31.0 kHz LFINTOSC
                  CONFIG BBSIZE = BBSIZE_512        ;Boot Block size is 512 words
                  CONFIG BBEN = OFF        ;Boot block disabled
                  CONFIG SAFEN = OFF        ;SAF disabled
                  CONFIG WRTAPP = OFF        ;Application Block not write protected
                  CONFIG WRTB = OFF        ;Configuration registers (300000-30000Bh) not write-protected
                  CONFIG WRTC = OFF        ;Boot Block (000000-0007FFh) not write-protected
                  CONFIG WRTD = OFF        ;Data EEPROM not write-protected
                  CONFIG WRTSAF = OFF        ;SAF not Write Protected
                  CONFIG LVP = OFF        ;HV on MCLR/VPP must be used for programming
                  CONFIG CP = OFF        ;PFM and Data EEPROM code protection disabled
                #ENDCONFIG
              
              
              DEFINE OSC 64
              
              DEFINE HSER_RXREG PORTC
              DEFINE HSER_RXBIT 7
              DEFINE HSER_TXREG PORTC
              DEFINE HSER_TXBIT 6
              DEFINE HSER_BAUD 9600 
              
              DEFINE HSER_RCSTA 90h
              DEFINE HSER_TXSTA 20h
              
                  clear
                  Testbyte  var byte
              
                  TRISA =  %00000000    '
                  TRISB =  %00001000    '
                  TRISC =  %10000000  '
              
                  testbyte = 50
              
              main:    
              
                  hserout ["Testbyte= ",dec testbyte,10,13]
                  pause 200
                  goto main

              Comment


              • #8
                Andy,
                Instead of using DEC, can you try:
                Code:
                hserout ["Testbyte= ", #testbyte,10,13]
                I seem to remember an issue with DEC vs # but I could've sworn it was # that didn't work while DEC did. I don't know what the internal differences are compiling your code for a 18F26K80* produces significantly smaller .hex when using # so SOMETHING is different and perhaps # works for your current needs while Charles figures out why DEC doesn't.

                Or I'm just way off target :-)

                * I'm still on 3.1.0.4 here so can't compile for K83 devices.

                /Henrik.

                Comment


                • #9
                  Hi Henrik,

                  I tried your suggestion and hre is the result:

                  Testbyte= 11

                  Comment


                  • #10
                    Hi Henrik,

                    Some of the extended characters have been stripped from my previous reply. I have attached the result as an image.

                    Comment


                    • #11
                      Strange, but OK, it was worth a try I guess.
                      I'm afraid I'll have to leave this one to Charles then. I'd be interested in knowing what the problem turns out to be.

                      /Henrik.

                      Comment


                      • #12
                        Good catch Henrik, I forgot all about that problem from the past.
                        Dave Purola,
                        N8NTA
                        EN82fn

                        Comment


                        • #13
                          To use the "#" method you must first create a place to put the result. I use the ARRAYWRITE command that parses the individual digits of the value ("5" and "0" in this case) into the array:
                          Code:
                          ARRAYWRITE HhDcA, [#HhDc]
                          where my variable ("50" for example) is in HhDc and my array is HhDcA[3]. Then I can send out the ASCii digits one at a time:
                          Code:
                          DO
                                  LOOP UNTIL U1FIFO.5 = 1             ;Wait until TXREG is empty
                              U1TXB = HhDcA[0]
                              DO
                                  LOOP UNTIL U1FIFO.5 = 1             ;Wait until TXREG is empty
                              U1TXB = HhDcA[1]
                              DO
                                  LOOP UNTIL U1FIFO.5 = 1             ;Wait until TXREG is empty
                              U1TXB = HhDcA[2]
                              DO
                                  LOOP UNTIL U1FIFO.5 = 1             ;Wait until TXREG is empty
                          (The above code is for a PIC18F47K42)
                          We can crack this cotton PIC'n thang!

                          Comment


                          • #14
                            Wow Mike, One byte at a time? That will for sure slow down the program flow. Why not use interrupts to do the USART function? Then you can do something like this:

                            '*********************************************************************
                            SNDCHAR: 'INCREMENT BUFFER POINTERS
                            '*********************************************************************
                            TX_OUTPUT = TX_OUTPUT + 1
                            TX_OUTPUT = TX_OUTPUT & OUTSIZE
                            TX_DAVAIL = TX_DAVAIL + 1
                            IF PIE1.4 = OFF_ THEN
                            @ INT_ENABLE TX_INT ; ENable TX UART Interrupts
                            ENDIF
                            IF TX_DAVAIL > FIVESIXTH THEN 'if buffer is more than 5/6th full allow buffer to empty (I usually use 64 for the buffer size)
                            WHILE TX_DAVAIL > ONESIXTH 'allow buffer to empty to 1/6th then continue.
                            PATDOG = ON_ 'FEED THE DOG
                            WEND
                            ENDIF
                            RETURN

                            '*********************************************************************
                            SERIALOUT: 'OUTPUT SERIAL STRING TO PORT 1
                            '*********************************************************************
                            BYTEIN = 0
                            WHILE OUTARRAY [BYTEIN]
                            TX_BYTES(TX_OUTPUT) = OUTARRAY(BYTEIN)
                            BYTEIN = BYTEIN + 1
                            GOSUB SNDCHAR 'INCREMENT BUFFER POINTERS
                            WEND
                            RETURN
                            '*********************************************************************

                            And in the main program loop you do something like this: It makes sending formatted strings extremely easy.

                            ARRAYWRITE OUTARRAY,["CALCULATED GAIN & OFFSET:",DEC5 SLOPE,",",DEC5 OFFSET,10,13,0]:GOSUB SERIALOUT
                            Dave Purola,
                            N8NTA
                            EN82fn

                            Comment


                            • #15
                              That works also. Sometimes the code has the luxury of spending time with a function, and other times too much is happening at any given time. I wanted to show the mechanics of a process more than the most efficient method.
                              We can crack this cotton PIC'n thang!

                              Comment

                              Working...
                              X