Dma pwm


+ Reply to Thread
Results 1 to 3 of 3

Thread: Dma pwm120 days old

Hybrid View

  1. #1
    Junior Member AngryGorilla's Avatar
    Join Date
    Nov 2018
    Posts
    8
    Thumbs Up
    Received: 0
    Given: 9
    Total Downloaded
    569.76 MB

    0 Not allowed!

    Default Dma pwm

    What is the basic form of these lines?

    1. unsigned int BufferA[32] __attribute__((space(dma)))
    2. DMA3PAD = (volatile unsigned int)&OC1RS; // Point DMA to OC1RS
    3. DMA3STA = __builtin_dmaoffset(BufferA)

    or

    1. uint8_t BufferAsendBit[1024];
    2. DMA3STA = KVA_TO_PA(&BufferAsendBit); // DMA source address.
    3. DMA3PAD = KVA_TO_PA(&OC1RS); // DMA destination address

    There is not much information in the translator descriptions of DMA.

    Code:
        Device = 24HJ128GP502
        Declare Xtal = 79.23
        PLL_Setup(43, 2, 2, $0300) ' Configure the Oscillator to operate the device at 79.23MHz
    
    
        'Set up Output Compare 1 module for PWM mode:
        OC1CON = 0;                                           // Reset OC module
        OC1R = 0x60;                                          // Initialize PWM Duty Cycle
        OC1RS = 0x60;                                        // Initialize PWM Duty Cycle Buffer
        OC1CONbits_OCM0 = 0;                            // Configure OC for the PWM mode
        OC1CONbits_OCM1 = 1
        OC1CONbits_OCM2 = 1
        
        'Set up DMA Channel 3 for in Post Increment mode with Timer2 Request Source:
        'unsigned int BufferA[32] __attribute__((space(dma)))
        ;/* Insert code here to initialize BufferA with desired Duty Cycle values */
        DMA3CONbits_AMODE0 = 0;                      // Configure DMA for Register indirect mode 
        DMA3CONbits_AMODE1 = 0;                      // with post-increment
        DMA3CONbits_MODE0_DMA3CON = 0;         // Configure DMA for Continuous mode
        DMA3CONbits_MODE1_DMA3CON = 0
        DMA3CONbits_DIR   = 1;                          // RAM-to-Peripheral data transfers
        DMA3PAD = (volatile unsigned int)&OC1RS; // Point DMA to OC1RS
        DMA3CNT = 31;                                     // 32 DMA request
        DMA3REQ = 7;                                       // Select Timer2 as DMA Request source
    
        DMA3STA = __builtin_dmaoffset(BufferA)
        
        IFS2bits_DMA3IF = 0;                            // Clear the DMA interrupt flag bit
        IEC2bits_DMA3IE = 1;                            // Set the DMA interrupt enable bit
    
        DMA3CONbits_CHEN = 1;                        // Enable DMA
        
        'Set up Timer2 for Output Compare PWM mode:
        PR2 = 0xBF;                                         // Initialize PWM period
        T2CONbits_TON = 1;                             // Start Timer2
    
        'Set up DMA Channel 3 Interrupt Handler:
        Isr DMA3Interrupt
        'void __attribute__((interrupt, no_auto_psv)) _DMA3Interrupt(void)
        
        '{/* Update BufferA with new Duty Cycle values if desired here*/
        
        IFS2bits_DMA3IF = 0;          //Clear the DMA3 Interrupt Flag}
        
        EndIsr

  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
    Fanatical Contributor top204's Avatar
    Join Date
    Feb 2002
    Posts
    3,596
    Thumbs Up
    Received: 339
    Given: 162
    Total Downloaded
    1.99 GB

    1 Not allowed!

    Default Re: Dma pwm

    DMA wasn't fully available with PIC24 devices when I first wrote Proton24, so I only added it to dsPIC33 devies, however, open the "P24HJ128GP502.ppi" file from: "C:\Program Files (x86)\ProtonIDE\PDS\Includes\PPI", but ONLY in notepad, never a wordprocessor or wordpad etc...

    Copy this block of text into the INFOSTART/INFOEND section:

    Code:
    [INFOSTART]
    CORE=24             ; Core Type (24 or 33)
    OSCDIV=2            ; Fosc division
    TYPE=72             ; Device type E(69), F(70), H(72)
    RAMAMOUNT=8192      ; Amount of user available RAM (in bytes)
    CODEAMOUNT=132096   ; Total amount of Code Memory (in bytes)
    DMAAMOUNT=1024      ; Amount of DMA RAM (in bytes)
    XRAMSTART=0x800     ; Starting address of X RAM
    YRAMSTART=0x00      ; Starting address of Y RAM (if any)
    DMARAMSTART=0x1400  ; Starting address of DMA RAM (if any)
    PORTS=2             ; Amount of Ports
    ADC=1               ; ADC available (1 or 0)
    EEPROM=0            ; Amount of On-Board Eeprom (in bytes)
    UART=2              ; Amount of UART peripherals
    USB=0               ; USB available (1 or 0)
    SPI=2               ; Amount of SPI peripherals
    I2C=1               ; Amount of I2C peripherals
    RTCC=1              ; RTCC available (1 or 0)
    PMP=1               ; PMP available (1 or 0)
    HPWM=4              ; Amount of Output Compare channels
    DAC=0               ; Amount of DAC channels
    DMA=1               ; Amount of DMA peripherals
    PPS=1               ; PPS available (1 or 0)
    BLOCK=192           ; Size of the Code Memory Write Segment (in bytes)
    ERASE=0             ; Size of the Code Memory Erase Segment (in bytes)
    [INFOEND]
    This will give DMA to the device with its RAM address set correctly and its size.

    The code above may be changed to:
    Code:
        Device = 24HJ128GP502
        Declare Xtal = 79.23
        PLL_Setup(43, 2, 2, $0300) ' Configure the Oscillator to operate the device at 79.23MHz
    
    $define KVA_TO_PA(v) ((v) & $1FFFFFFF)
        
        Dim BufferA[32] As Word DMA
      
    ' Set up Output Compare 1 module for PWM mode:
        OC1CON = 0                                           ' Reset OC module
        OC1R = $60                                          ' Initialize PWM Duty Cycle
        OC1RS = $60                                        ' Initialize PWM Duty Cycle Buffer
        OC1CONbits_OCM0 = 0                            ' Configure OC for the PWM mode
        OC1CONbits_OCM1 = 1
        OC1CONbits_OCM2 = 1
        
        'Set up DMA Channel 3 for in Post Increment mode with Timer2 Request Source:
        'unsigned int BufferA[32] __attribute__((space(dma)))
    ' Insert code here to initialize BufferA with desired Duty Cycle values
        DMA3CONbits_AMODE0 = 0                          ' Configure DMA for Register indirect mode 
        DMA3CONbits_AMODE1 = 0                          ' with post-increment
        DMA3CONbits_MODE0_DMA3CON = 0                   ' Configure DMA for Continuous mode
        DMA3CONbits_MODE1_DMA3CON = 0
        DMA3CONbits_DIR   = 1                           ' RAM-to-Peripheral data transfers
        DMA3PAD = AddressOf(OC1RS)                      ' Point DMA to OC1RS
        DMA3CNT = 31                                    ' 32 DMA request
        DMA3REQ = 7                                     ' Select Timer2 as DMA Request source
    
        'DMA3STA = __builtin_dmaoffset(BufferA)
        DMA3STA = AddressOf(BufferA)
        
        IFS2bits_DMA3IF = 0                             ' Clear the DMA interrupt flag bit
        IEC2bits_DMA3IE = 1                             ' Set the DMA interrupt enable bit
    
        DMA3CONbits_CHEN = 1                            ' Enable DMA
        
        'Set up Timer2 for Output Compare PWM mode:
        PR2 = $BF                                       ' Initialize PWM period
        T2CONbits_TON = 1                               ' Start Timer2
    
        'Set up DMA Channel 3 Interrupt Handler:
    Isr DMA3Interrupt
        'void __attribute__((interrupt, no_auto_psv)) _DMA3Interrupt(void)
        
        '{/* Update BufferA with new Duty Cycle values if desired here*/
        
        IFS2bits_DMA3IF = 0          'Clear the DMA3 Interrupt Flag}
        
    EndIsr
    But from here, you are on your own, as I've never actually used DMA on a 16-bit device. The DMA text will not highlight because the IDE is expecting it only with dsPIC33 devices. This can be changed in the IDE's "Database.mcd" file, in the block:
    Code:
    KEY ("DMA")
       DeviceCore = [dc12, dc14, dc16, dc33]
       Highlighter = KeywordDeclare
       Hint = "<b>DMA</b><br><i><font color='#008000'>Place the variable in DMA RAM (if available)</font></i>"
    ENDKEY
    Change it to:
    Code:
    KEY ("DMA")
       DeviceCore = [dc12, dc14, dc16, dc24, dc33]
       Highlighter = KeywordDeclare
       Hint = "<b>DMA</b><br><i><font color='#008000'>Place the variable in DMA RAM (if available)</font></i>"
    ENDKEY
    Again, only use notepad for editing, never, ever, ever use a wordprocessor or wordpad because these add underlying format characters in text and will stop things working.

  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
    Junior Member AngryGorilla's Avatar
    Join Date
    Nov 2018
    Posts
    8
    Thumbs Up
    Received: 0
    Given: 9
    Total Downloaded
    569.76 MB

    0 Not allowed!

    Thumbs up Re: Dma pwm

    Thank you very much top204!

  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.

Thread Information

Users Browsing this Thread

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

     

Similar Threads

  1. Peripheral DMA Transfer
    By pic-ignorant in forum Proton 24
    Replies: 1
    Last Post: 10th November 2014, 21:16
  2. Proton 24 DMA problem.
    By pic-ignorant in forum The Lounge
    Replies: 5
    Last Post: 1st October 2014, 17:58
  3. Replies: 0
    Last Post: 30th April 2014, 12:55
  4. [SOLVED !] PWM, dithered PWM and Tmr1 as a (variable bit) PWM source.
    By david in forum The Lounge
    Replies: 8
    Last Post: 2nd August 2013, 12:57

Posting Permissions

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