Announcement

Collapse
No announcement yet.

Issue with DEC modifier and 18F26K83

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

  • Charles Leo
    replied
    That's a surprise to me, but I'll take it.

    When I write code, I use all the best bytes....

    Leave a comment:


  • Andy Wood
    replied
    The latest beta version has fixed this problem http://pbp3.com/downloads/PBP3_312Beta_20190218.exe

    Andy

    Leave a comment:


  • Andy Wood
    replied
    Hi Charles,

    I have changed to the internal oscillator as per your config settings, however the problem persists.

    Interestingly, if I substitute HEX for DEC in my HSEROUT line, the output is as expected (i.e.32)

    hserout ["Testbyte= ",HEX testbyte,10,13]

    I will contact you directly via email and we can go from there.

    Andy

    Leave a comment:


  • Charles Leo
    replied
    I tested your (Andy's) program as-written except for some config changes. The DEC modifier works for me.

    I had to change the #CONFIG to use the internal oscillator because I don't have a crystal. The lines I changed are:
    Code:
     #CONFIG   
        CONFIG FEXTOSC = OFF     ;Oscillator not enabled
        CONFIG RSTOSC = HFINTOSC_64MHZ     ;HFINTOSC with HFFRQ = 64 MHz and CDIV = 1:1
        ....
    I'm receiving with another PIC functioning as a serial-to-USB converter. I measured the bit-length at exactly 104uS for 9600.

    I'm compiling with PBP 3.1.1 and MPASMX 5.81.

    Not sure where to go next. I suppose we could exchange and compare hex files. Might be easier if you contact me via [email protected].

    Leave a comment:


  • mpgmike
    replied
    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.

    Leave a comment:


  • DavidP
    replied
    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

    Leave a comment:


  • mpgmike
    replied
    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)

    Leave a comment:


  • DavidP
    replied
    Good catch Henrik, I forgot all about that problem from the past.

    Leave a comment:


  • Henrik Olsson
    replied
    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.

    Leave a comment:


  • Andy Wood
    replied
    Hi Henrik,

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

    Leave a comment:


  • Andy Wood
    replied
    Hi Henrik,

    I tried your suggestion and hre is the result:

    Testbyte= 11

    Leave a comment:


  • Henrik Olsson
    replied
    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.

    Leave a comment:


  • Andy Wood
    replied
    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

    Leave a comment:


  • DavidP
    replied
    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.

    Leave a comment:


  • Charles Leo
    replied
    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.

    Leave a comment:

Working...
X