Menu

DAC pic18F56

Boguslaw
2023-12-20
2023-12-27
1 2 > >> (Page 1 of 2)
  • Boguslaw

    Boguslaw - 2023-12-20

    Hi
    I want to generate two different signals on DAC1 and DAC2 , but I have problem, because always I have identical signal on DACs, why ?
    For example I have as below, but always I have voltage from DAC1DATL on DAC2 :

    DAC2CON =  0b10100000 ' RA2 port
    DAC1CON =  0b10010000 ' RB7 port
    
    do
    
    DAC1DATL = 127
    DAC2DATL = 50
    
    loop
    

    Thanks
    Boguslaw

     

    Last edit: Boguslaw 2023-12-20
  • Anobium

    Anobium - 2023-12-20

    Welcome,

    Not sure you have the chip correct. a 18F56 ?

    Without the chip type it is hard to help.

     
  • Boguslaw

    Boguslaw - 2023-12-20

    I have board PIC18F56Q71 Curiosity Nano
    and I use: #chip PIC18F56Q71,64

     
  • Anobium

    Anobium - 2023-12-20

    Well that is a new chip. And, it may have support issues. When I release support I did write 30 demos but I did not test/try the DAC.


    But, looking at PICINFO. I see that DAC1 has two registers DAC1DATH:DAC1DATL and DAC2 as DAC2DAT. So, these two DACs ( of three ) are not the same. What is the diiference?

    So, for DAC1 you need to see two registers, and, for DAC2 one registers.

     
  • Boguslaw

    Boguslaw - 2023-12-20

    DAC1DATH=0 and DAC2DATH=0 because I use 8bit values 0-255

    DACxDATH: Accesses the upper 2 bits of DACR
    DACxDATL: Accesses the lower 8 bits of DACR

     

    Last edit: Boguslaw 2023-12-20
  • Anobium

    Anobium - 2023-12-20

    DAC1DATL=0 and DAC2DATL=0 surely?


    #chip PIC18F56Q71 
    #option Explicit
    
    
    DAC1DATH=0
    DAC2DATH=0
    

    Gives...
    "message": "Variable DAC2DATH was not explicitly declared",

     
  • Boguslaw

    Boguslaw - 2023-12-20

    I use SYNWRITE, this compiler not report any error, should I use another compiler?
    Probably 8bit DAC use DAC2 DAC3 names (according to datasheet)

     

    Last edit: Boguslaw 2023-12-20
  • Anobium

    Anobium - 2023-12-20

    I am not sure.
    Show me the top line of the ASM file being produced, please.

     
  • Boguslaw

    Boguslaw - 2023-12-20
    ;Program compiled by GCBASIC (1.01.00 2023-11-23 (Windows 64 bit) : Build 1308) for Microchip MPASM/MPLAB-X Assembler using FreeBASIC 1.07.1/2023-11-25 CRC29
    ;Need help? 
    ;  See the GCBASIC forums at http://sourceforge.net/projects/gcbasic/forums,
    ;  Check the documentation and Help at http://gcbasic.sourceforge.net/help/,
    ;or, email us:
    ;   w_cholmondeley at users dot sourceforge dot net
    ;   evanvennn at users dot sourceforge dot net
    ;********************************************************************************
    ;   Source file    : C:\Temp\Sinusy_tcr8000.gcb
    ;   Setting file   : D:\GCstudio\GCBASIC\use.ini
    ;   Preserve mode  : 0
    ;   Assembler      : GCASM
    ;   Programmer     : 
    ;   Output file    : C:\Temp\Sinusy_tcr8000.asm
    ;********************************************************************************
    
    ;Set up the assembler options (Chip type, clock source, other bits and pieces)
     LIST p=18F56Q71, r=DEC
    #include <P18F56Q71.inc>
     CONFIG  CP = OFF
     CONFIG  CPD = OFF
     CONFIG  WRTSAF = OFF
     CONFIG  WRTD = OFF
     CONFIG  WRTB = OFF
     CONFIG  WDTE = OFF
     CONFIG  XINST = OFF
     CONFIG  LVP = OFF
     CONFIG  MVECEN = OFF
     CONFIG  MCLRE = INTMCLR
     CONFIG  FCMEN = ON
     CONFIG  CLKOUTEN = OFF
     CONFIG  RSTOSC = HFINTOSC_1MHZ
     CONFIG  FEXTOSC = OFF
    
    ;********************************************************************************
    
    ;Vectors
        ORG 0
        goto    BASPROGRAMSTART
        ORG 8
        retfie
    
    ;********************************************************************************
    
    ;Start of program memory page 0
        ORG 12
    BASPROGRAMSTART
    ;Call initialisation routines
        rcall   INITSYS
    
    ;Start of the main program
        movlw   160
        movwf   DAC1CON,BANKED
        movlw   144
        movwf   DAC2CON,BANKED
    SysDoLoop_S1
        movlw   127
        movwf   DAC1DATL,BANKED
        movlw   50
        movwf   DAC2DATL,BANKED
        bra SysDoLoop_S1
    SysDoLoop_E1
    BASPROGRAMEND
        sleep
        bra BASPROGRAMEND
    
    ;********************************************************************************
    
    INITSYS
        movlb   0
    ;asm showdebug This code block sets the internal oscillator to ChipMHz
    ;asm showdebug Default settings for microcontrollers with _OSCCON1_
        movlw   96
        movwf   OSCCON1,BANKED
        clrf    OSCCON3,BANKED
        clrf    OSCEN,BANKED
        clrf    OSCTUNE,BANKED
    ;asm showdebug The MCU is a chip family ChipFamily
    ;asm showdebug OSCCON type is 101
        movlw   96
        movwf   OSCCON1,BANKED
        bcf OSCCON1,NDIV3,BANKED
        bcf OSCCON1,NDIV2,BANKED
        bcf OSCCON1,NDIV1,BANKED
        bcf OSCCON1,NDIV0,BANKED
        movlw   8
        movwf   OSCFRQ,BANKED
    ;asm showdebug _Complete_the_chip_setup_of_BSR_ADCs_ANSEL_and_other_key_setup_registers_or_register_bits
        clrf    TBLPTRU,ACCESS
        banksel ADCON0
        bcf ADCON0,ADFM0,BANKED
        bcf ADCON0,ADON,BANKED
        banksel ANSELA
        clrf    ANSELA,BANKED
        clrf    ANSELB,BANKED
        clrf    ANSELC,BANKED
        clrf    ANSELD,BANKED
        clrf    ANSELE,BANKED
        clrf    ANSELF,BANKED
        banksel CM2CON0
        bcf CM2CON0,C2EN,BANKED
        bcf CM1CON0,C1EN,BANKED
        banksel PORTA
        clrf    PORTA,BANKED
        clrf    PORTB,BANKED
        clrf    PORTC,BANKED
        clrf    PORTD,BANKED
        clrf    PORTE,BANKED
        clrf    PORTF,BANKED
        banksel 0
        return
    
    ;********************************************************************************
    
    
     END
    
     

    Last edit: Boguslaw 2023-12-20
  • Anobium

    Anobium - 2023-12-20

    One line...

    OK you are on one of the latest builds.

    You have #option explicit missing from your program. Add please. You will get the error.

    DAC2DATH is being created as a RAM variables. I am not sure what the others are.

    DAC2DATH                         EQU    1280          ; 0x500
    SINUS1                           EQU    5343          ; 0x14DF
    SINUS2                           EQU    5310          ; 0x14BE
    X1                               EQU    1281          ; 0x501
    

    Try using GCODE as your IDE. It is a lot better and that is where all our development is happening.

     
  • Boguslaw

    Boguslaw - 2023-12-20

    Sorry , I pasted wrong listing ,now is corrected,
    Yes now I have error with #option explicit but now I test with 8 bit values

     

    Last edit: Boguslaw 2023-12-20
  • Boguslaw

    Boguslaw - 2023-12-20

    I don't know how use GCODE I'm a beginner in GCBasic

     
  • Anobium

    Anobium - 2023-12-20

    :-)

    So, you are now setting the L registers. My assumption.

    So, I think you have to study the datasheet to figure the registers.

    But, a thought. You are allowing the chip to go to sleep. Put this at the end of your code. This will prevent sleep.

    do
    loop
    
     
  • Boguslaw

    Boguslaw - 2023-12-20

    I have below listing with do loop

    #chip PIC18F56Q71,64
    #option explicit
    DAC1CON = 0b10100000'0b10100000 '160  RA2 port
    DAC2CON = 0b10010000'0b10010000 '144  RB7
    
    do
    
    DAC1DATL = 127'sinus1(x1)
    DAC2DATL = 50'sinus2(x1)
    
    loop
    
     

    Last edit: Boguslaw 2023-12-20
  • Boguslaw

    Boguslaw - 2023-12-20

    I also tried with DAC2 and DAC3, according to the datasheet for 8bit DAC and it still generates the same voltages on the two DACs.
    You could test it on your hardware.

     

    Last edit: Boguslaw 2023-12-20
  • Anobium

    Anobium - 2023-12-20

    I think that you can only enable one at a time, see page 831.

    I may be wrong but this looks like one DAC on multiple selectable outputs.


    And, I can tell you are no beginners to microcontrollers. :-)

     
  • Jerry Messina

    Jerry Messina - 2023-12-20

    There are 3 DACs on the Q71... DAC1 (10-bit) and DAC2, DAC3 (both 8-bit).

    They all share the same 2 output pins (RA2 or RB7), selectable via the OE bits of the DACxCON registers. The datasheet has this note:

    This device has multiple DACs that share the same output pin. If more than one DAC is enabled
    simultaneously, the priority for the DACOUT pin is DAC1>DAC2...>DACn.

    If you want to use all three DACs you could route one of them through one of the OPAMPs to get the output on OPA1OUT (RA1) or OPA2OUT (RB1) instead of enabling its output pin.

     
    👍
    2
  • Jerry Messina

    Jerry Messina - 2023-12-20

    If you're using the Q71 Curiosity Nano you may have a problem using the output on RB7 since that pin is also the builtin debugger/programmer ICSPDAT.

    Try routing DAC1 through the OPA instead.

     
  • Jerry Messina

    Jerry Messina - 2023-12-20

    quoting myself...

    using the output on RB7 since that pin is also the builtin debugger/programmer ICSPDAT.

    [RANT]
    They do this on a lot of the new chips... mixing the analog functions with the ICSP pins. Since you can't move the analog pins this makes the analog functions unusable while you have the programmer/debugger connected! Why they choose to do this is beyond me.
    [/RANT]

    @Evan - next time you talk to your contacts @mchip you might ask them why they do this instead of using some of the digital pins for the ICSP connection. At least those you can route with PPS.

     
  • Anobium

    Anobium - 2023-12-20

    @Jerry.

    I agree! I understand and I will.

     
  • Boguslaw

    Boguslaw - 2023-12-20

    "Try routing DAC1 through the OPA instead." this is hard for implementation for me now.
    I'll try to experiment.

     

    Last edit: Boguslaw 2023-12-20
  • Jerry Messina

    Jerry Messina - 2023-12-21

    Using the 18F56Q71 Curiosity Nano I get the same results as you... can't use RB7 as an output.

    You can route DAC1 through OPA1 (output on RA1) using

    // OPA1 output RA1
    OPA1CON0 = 0xA8 // UNITY GAIN
    OPA1CON1 = 0x00
    OPA1CON2 = 0x04 // DAC1
    
    // DAC1CON (ena, no output pin)
    DAC1CON = 0x80
    
     
  • Anobium

    Anobium - 2023-12-21

    Jerry,

    Can the Q71 do that same with the DAC as the LGT?

    The program generates a Sine Wave ( works on the LGT).

    I have ported this but I am not sure what we would set on the Q71. The LGT used the DALR register. The readtable command sets the DALR.

    Are you able to get this working?

    Evan

    #chip 18F56Q71
    #option explicit
    
    // ------ Start of main Program
    
        Dim DACCounter as Byte
    
        #define SAMPLES 33
        #define DACPORT PORTA.1
    
        DIR DACPORT OUT
    
        // OPA1 output RA1
        OPA1CON0 = 0xA8 // UNITY GAIN
        OPA1CON1 = 0x00
        OPA1CON2 = 0x04 // DAC1
    
        // DAC1CON (ena, no output pin)
        DAC1CON = 0x80
    
        Do
    
                /* Ramp up and down by reading the table data and setting the DAC register
                    DAC data register, setting output voltage in DAC mode
                    Relationship between DAC output voltage and DALR:
                    VDAO = VREF*(DALR + 1)/256
                    VDAO indicates DAC output analog voltage
                    VREF indicates reference voltagesource, which is set by DAVS of DACON register
                */
                for DACCounter = 1 to 33
                    ReadTable SineWaveDAta, DACCounter, DALR
                next
    
        Loop
    
        // Sine wave sample DAC setting values
        Table SineWaveData
                0x80, 0x98, 0xb0, 0xc6, 0xda, 0xea, 0xf5, 0xfd, 0xff 
                0xfd, 0xf5, 0xea, 0xda, 0xc6, 0xb0, 0x98, 0x80, 0x67 
                0x4f, 0x39, 0x25, 0x15, 0x0a, 0x02, 0x00, 0x02, 0x0a 
                0x15, 0x25, 0x39, 0x4f, 0x67, 0x80
            End Table
    
     
  • Jerry Messina

    Jerry Messina - 2023-12-21

    Evan,
    I'll check that out when I get a chance... sort of busy at the moment.

    I take back come of what I said in my previous post. While I can route DAC1 out the OPA1OUT, there's still some sort of funny interaction between the DACs... I can't get more than 1 DAC working at a time.

    I don't know if it has to do with using the 18F56Q71 Curiosity Nano and its builtin debugger or not.
    I have some 26Q71 around here somewhere... I'll try the same thing using it standalone and see if it's a debugger limitation or what. Different chip, but that's all I got atm.

     

    Last edit: Jerry Messina 2023-12-21
    • Anobium

      Anobium - 2023-12-21

      OK. Understand.

      It would be good to get that demo working.

       
1 2 > >> (Page 1 of 2)

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.