18f46k20 USART&ADC Problems


+ Reply to Thread
Results 1 to 6 of 6

Thread: 18f46k20 USART&ADC Problems2429 days old

  1. #1
    bugi
    Guest bugi's Avatar

    0 Not allowed!

    Default 18f46k20 USART&ADC Problems

    Hi Les and Friends,

    I want to use lower baudrates 300-2400 with USART (with hserin-hserout commands)
    But when I tried, It did not work with pic 18f46k20 and 64 Mhz. I looked into the datasheet and I learned something. I think, Proton does not support automaticly with own general declares for these lower baudrates. I compiled like these and it didn't work.

    Declare Hserial_Baud = 2400' Set baud rate to 2400
    Declare Hserial_RCSTA = %10010000 ' Enable continuous receive
    Declare Hserial_TXSTA = %00100000 ' Enable transmit and asynchronous mode
    Declare Hserial_Clear = On ' Clear the buffer before receiving

    If I cancel the first line about Baudrate and add these configs and change third line, It works well:

    BAUDCON=%00001000
    SPBRGH=%00011010
    SPBRG=%00001010

    Declare Hserial_RCSTA = %10010000 ' Enable continuous receive
    Declare Hserial_TXSTA = %00100100 ' Enable transmit and asynchronous mode
    Declare Hserial_Clear = On ' Clear the buffer before receiving

    Is it a trusted method? Or, are there any other suggestions? Is Declare Hserial_RCSTA only set these configs : Baudcon, spbrgh-spbrg? Or, are there any other functions?

    By the way, I can not set the ADC with proton declares for 18f46k20. It doesn't support, does it?
    I looked at the datasheet and registers are different. Are there any suggestions?


    Many Thanks

    Regards
    Bugra

  2. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  3. #2
    Member Jezsmith's Avatar
    Join Date
    Sep 2004
    Posts
    211
    Thumbs Up
    Received: 7
    Given: 2
    Total Downloaded
    930.95 MB

    0 Not allowed!

    Default Re: 18f46k20 USART&ADC Problems

    bugra,
    Not sure about HSERIN but I use the 18f46k20 ADC for touch screen and its OK.
    Code:
        Device = 18F46K20
        Xtal=8
        Declare PLL_Req = True
        OSCCON  = 100000         'Internal 8 MHz clock select
        OSCTUNE.6 = 1 ' Frequency Multiplier PLL for INTOSC Enable bit
        All_Digital = True 
        Float_Display_Type = LARGE
        Declare Watchdog = True
        Declare Reminders = Off
        Declare Warnings = Off
        Declare Optimiser_Level = 2
        Declare Dead_Code_Remove = On
        Declare Float_Display_Type = Fast       ' More accurate Floating point output
     
        ' Device Fuse configuration
        Config_Start
        FOSC = INTIO67 'type of main oscilator used(INTIO67 is internal 16MHz oscilator 
        FCMEN = OFF 'fail-safe clock monitor
        IESO = OFF 'internal/external oscilator switchover enable
        PWRT = On 'powerup timer enable(keep in reset until power is good)
        BOREN = OFF 'brown out reset enable
        BORV = 27 'brown out voltage(2.7v)
        WDTEN = OFF 'watchdog timer enable(can be disable in software if enabled here)
        WDTPS = 128 'watchdog timer postscale value
        PBADEN = OFF 'PORTB.0 to 4 digital on power up
        STVREN = OFF 'no reset on stack full
        LVP = OFF 'low voltage programming
        XINST = OFF 'extended instruction set
        Debug = OFF 'hardware debug module
        CCP2MX=PORTC 'alternative pin(RB3) for HPWM2
        MCLRE= off 'enable MCLRE pin as RE3(digital input pin only)
        HFOFST=On 'allow core to run before oscilator has stabilised on frequency
        LPT1OSC=OFF 'unused
        CP0=OFF 'code protection bits, all unused
        CP1=OFF
        CP2=OFF
        CP3=OFF
        CPB=OFF
        CPD=OFF
        WRT0=OFF
        WRT1=OFF
        WRT2=OFF
        WRT3=OFF
        WRTB=OFF
        WRTC=OFF
        WRTD=OFF
        EBTR0=OFF
        EBTR1=OFF
        EBTR2=OFF
        EBTR3=OFF
        EBTRB=OFF            
        Config_End 
    
    
         '************************************* ADC port A set up ********************************                               
        Adin_Res = 10                                ' Set the resolution to 10
        Adin_Tad = 8_FOSC                            ' Fosc:8
        Adin_Stime = 10                              ' Allow 10us for charge time
        ADCON0 = 11000001
        ADCON2 = 10100001 
        
       Dim result As Word
        
       start:
        result = ADIn 1
        DelayMS 10
        Print At ,1,1,Dec result
       GoTo start
    jez

  4. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  5. #3
    TEEGEE
    Guest TEEGEE's Avatar

    0 Not allowed!

    Default Re: 18f46k20 USART&ADC Problems

    all speed tested !

    U = ERead 9
    If U=1 Then 'HRSOut "2400"
    RCSTA = $90 ' Enable serial port & continuous receive
    TXSTA = $20 ' Enable transmit, BRGH = 0
    SPBRG = 130 ' 2400 Baud @ 64MHz, 0.0%
    SPBRGH = 6
    BAUDCON.3 = 1 ' Enable 16 bit baudrate generator
    EndIf


    If U=2 Then 'HRSOut "4800"
    RCSTA = $90 ' Enable serial port & continuous receive
    TXSTA = $24 ' Enable transmit, BRGH = 1
    SPBRG = 4 ' 4800 Baud @ 64MHz, 0.0%
    SPBRGH = 13
    BAUDCON.3 = 1 ' Enable 16 bit baudrate generator
    EndIf


    If U=3 Then 'HRSOut "9600"
    RCSTA = $90 ' Enable serial port & continuous receive
    TXSTA = $24 ' Enable transmit, BRGH = 1
    SPBRG = 130 ' 9600 Baud @ 64MHz, -0.02%
    SPBRGH = 6
    BAUDCON.3 = 1 ' Enable 16 bit baudrate generator
    EndIf


    If U=4 Then 'HRSOut "19200"
    RCSTA = $90 ' Enable serial port & continuous receive
    TXSTA = $24 ' Enable transmit, BRGH = 1
    SPBRG = 64 ' 19200 Baud @ 64MHz, 0.04%
    SPBRGH = 3
    BAUDCON.3 = 1 ' Enable 16 bit baudrate generator
    EndIf


    If U=5 Then 'HRSOut "38400"
    RCSTA = $90 ' Enable serial port & continuous receive
    TXSTA = $24 ' Enable transmit, BRGH = 1
    SPBRG = 160 ' 38400 Baud @ 64MHz, -0.08%
    SPBRGH = 1
    BAUDCON.3 = 1 ' Enable 16 bit baudrate generator
    EndIf


    If U=6 Then 'HRSOut "56000"
    RCSTA = $90 ' Enable serial port & continuous receive
    TXSTA = $24 ' Enable transmit, BRGH = 1
    SPBRG = 29 ' 56000 Baud @ 64MHz, -0.1%
    SPBRGH = 1
    BAUDCON.3 = 1 ' Enable 16 bit baudrate generator
    EndIf


    If U=7 Then 'HRSOut "57600"
    RCSTA = $90 ' Enable serial port & continuous receive
    TXSTA = $24 ' Enable transmit, BRGH = 1
    SPBRG = 21 ' 57600 Baud @ 64MHz, -0.08%
    SPBRGH = 1
    BAUDCON.3 = 1 ' Enable 16 bit baudrate generator
    EndIf


    If U=8 Then 'HRSOut "115200"
    RCSTA = $90 ' Enable serial port & continuous receive
    TXSTA = $24 ' Enable transmit, BRGH = 1
    SPBRG = 138 ' 115200 Baud @ 64MHz, -0.08%
    SPBRGH = 0
    BAUDCON.3 = 1 ' Enable 16 bit baudrate generator
    EndIf

  6. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  7. #4
    TEEGEE
    Guest TEEGEE's Avatar

    0 Not allowed!

    Default Re: 18f46k20 USART&ADC Problems

    Declare Adin_Res 10 ' 10-bit result required
    Declare Adin_Tad 32_FOSC ' OSC DIV 32 chosen
    Declare Adin_Stime 50 ' Allow 50us sample time

    '.........


    LECTA:


    Symbol GO_DONE = ADCON0.1


    Select LECP
    Case 0
    ADCON0 = %00000001 ; Channel AN0 selected Go/Don off, ADC On
    Case 1
    ADCON0 = %00000101 ; Channel AN0 selected Go/Don off, ADC On
    Case 2
    ADCON0 = %00001001 ; Channel AN0 selected Go/Don off, ADC On
    Case 3
    ADCON0 = %00001101 ; Channel AN0 selected Go/Don off, ADC On
    Case 4
    ADCON0 = %00010001 ; Channel AN0 selected Go/Don off, ADC On
    EndSelect


    ADCON1 = %00000000 ; Vref = VDD V- = VSS
    ADCON2 = %10111110

    DelayUS 5 ; Delay to let stuff settle
    tempb1 = 0
    GO_DONE = 1 ; Start the conversion
    While GO_DONE = 1 ; This coded is needed due to shity Microchip silicon bugs
    If tempb1 > 250 Then
    GO_DONE = 0
    Break
    EndIf
    Inc tempb1
    Wend
    ADCResult.LowByte = ADRESL
    ADCResult.HighByte = ADRESH
    raw = ADCResult


    If RAW >0 Then
    Volts = (RAW * QUANTA) ' Convert the value into volts
    Else
    Volts = 0
    EndIf
    GoSub STARTTIMER
    Return

  8. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  9. #5
    bugi
    Guest bugi's Avatar

    0 Not allowed!

    Default Re: 18f46k20 USART&ADC Problems

    Jez,

    Thank you very much for your reply.

    Regards
    Bugra

  10. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  11. #6
    bugi
    Guest bugi's Avatar

    0 Not allowed!

    Default Re: 18f46k20 USART&ADC Problems

    TeeGee,

    Thank you very much for your informations.

    I see that my methhod is right. We have to use these registers. This is the only way.

    Regards
    Bugra

  12. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Simultaneous reading of 6 ADC channels and USART
    By RSteve in forum Absolute Beginners Section
    Replies: 4
    Last Post: 16th March 2014, 20:38
  2. [SOLVED !] Difference Between USART(16Fxxx) & EUSART(18Fxxx)
    By Roshan in forum Proton Plus Compiler v3
    Replies: 3
    Last Post: 12th August 2013, 13:46
  3. [SOLVED !] 12F683 ADC problems.
    By david in forum The Lounge
    Replies: 11
    Last Post: 28th November 2009, 11:27
  4. Problems with usart and interrupts
    By cahbtexhuk in forum Proton Plus Compiler v3
    Replies: 5
    Last Post: 30th June 2008, 08:58

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts