SAM3S4B DACC problem

Discussion around product based on ARM Cortex M3 core.

Moderators: nferre, ncollot

frame
Posts: 17
Joined: Mon Apr 23, 2012 10:32 am

SAM3S4B DACC problem

Mon Apr 23, 2012 11:42 am

Hi all,

I have some trouble getting a simple DAC test application running on the SAM3S4B.
Basically, it is a modified and cut-down version of the evaluation board example.

First, I configure the SysTick timer to generate an interrupt every 10us.
Then I initialize the PMC and the DAC in free-running mode basically as seen below.
The PIOA code is inserted for debugging, and not essential.

In the SysTick interrupt, I get the next value to convert and write it to the
DACC_CDR register, as seen in the code.

When debugging, I see the following register contents:
DACC_MR = 0x10000810 (config)
DACC_CHSR = 0x00000001 (CH0 selected)
DACC_ACR = 0x000001AA (default ?)
PMC_PCSR0 = 0x40000800 (PIOA & DACC on)

All the code is executed as expected, as are the peripheral register contents during debugging. If probed with a scope, I can measure the
PIO debug signal, which is exactly 10us in this setting. However, I do not see
anything on the DAC0 pin (PB13), only noise.

Do I miss something ?


I have appended some cut-outs from the source, which seem relevant.

Code: Select all

#define DAC_TRGEN       0
#define DAC_TRGSEL      0
#define DAC_WORD_XF     0
#define DAC_SLEEP       0
#define DAC_FASTWKUP    0
#define DAC_REFRESH     (8 << 8)
#define DAC_USER_SEL    0
#define DAC_TAG_SEL     0
#define DAC_MAXS        0
#define DAC_STARTUP     (16 << 24)

in main ():

Code: Select all

/* 10 us timer */
SysTick_Config (640); // 64MHz / 10us

/* enable and configure PIO A.0 (board pin EXT1.1) */
PMC_EnablePeripheral (PMC_PIOA_ID);

/* Initialize DACC;
PMC_PCER0 = 1 << ID_DACC;                    /* Enable peripheral clock */
DACC_CR   = DACC_CR_SWRST;                   /* Reset the controller    */
DACC_MR   = DAC_TRGEN | DAC_TRGSEL | DAC_WORD_XF | DAC_SLEEP | DAC_FASTWKUP | DAC_REFRESH | DAC_USER_SEL | DAC_TAG_SEL | DAC_MAXS | DAC_STARTUP;
In the SysTick timer interrupt:

Code: Select all

void  SysTick_Handler(void)
{
    uint32_t         status;
    static uint32_t  toggle = 0;    // debug

    status = DACC_GetStatus(DACC);

    if ((status & DACC_ISR_TXRDY) == DACC_ISR_TXRDY)
    {
        if ((toggle++) % 2)        /* debug - toggle EXT1.1 */
            PIOA_SODR = 1;
        else
            PIOA_CODR = 1;

        index_sample++;
        if (index_sample >= SAMPLES)
            index_sample = 0;

        // output pin of CH0 is PB13...
        DACC_SetConversionData (sine_data[index_sample] * amplitude / (MAX_DIGITAL/2) + MAX_DIGITAL/2);
    }
}

void  DACC_SetConversionData (uint32_t dwData)
{
    uint32_t  dwMR;

    dwMR = DACC_MR;
    if (dwMR & DACC_MR_WORD)
        DACC_CDR = dwData;
    else
        DACC_CDR = (dwData & 0xFFFF);
}
frame
Posts: 17
Joined: Mon Apr 23, 2012 10:32 am

Re: SAM3S4B DACC problem

Mon Apr 23, 2012 1:58 pm

Could this be the problem ?
Excerpt from datasheet:

29.5.2 I/O Line or Peripheral Function Selection
When a pin is multiplexed with one or two peripheral functions, the selection is controlled with
the registers PIO_PER (PIO Enable Register) and PIO_PDR (PIO Disable Register). ...
. A value of 0 indicates that the pin is controlled by the corresponding on-chip peripheral selected in the
PIO_ABCDSR1 and PIO_ABCDSR2 (ABCD Select Registers). A value of 1 indicates the pin is
controlled by the PIO controller.
If a pin is used as a general purpose I/O line (not multiplexed with an on-chip peripheral),
PIO_PER and PIO_PDR have no effect and PIO_PSR returns 1 for the corresponding bit.
After reset, most generally, the I/O lines are controlled by the PIO controller, i.e.
PIO_PSR resets at 1.

That would mean I explicitly need to set PIOB_PDR to 0 for those pin(s).
I'm going to try as soon as possible.
I can't remember that I have seen something like this in the example code I took it from...
frame
Posts: 17
Joined: Mon Apr 23, 2012 10:32 am

Re: SAM3S4B DACC problem

Mon Apr 23, 2012 9:42 pm

Well, would have been nice.

It turned out that I'm unable to write to the configuration registers ABCDSR2 of PIOB. Following the disassembled sequence to write to ABCDSR1 and ABCDSR2, to select peripheral D for PB13:

Code: Select all

PIOB_ABCDSR1 = 0x00002000;      // set peripheral function
    F2410370    movw r3, #0x1070
    F2C4030E    movt r3, #0x400E
    F44F5200    mov.w r2, #0x2000
    601A        str r2, [r3]
--- main.c -- 105 --------------------------------------
PIOB_ABCDSR2 = 0x00002000;
    F2410374    movw r3, #0x1074
    F2C4030E    movt r3, #0x400E
    F44F5200    mov.w r2, #0x2000
    601A        str r2, [r3]
While PIOB_ABCDSR1 is successfully set, an identical write sequence to PIOB_ABCDSR2 has no effect. The PIOB_LOCKSR and PIOB_WPMR registers are zero at this time.

The board is a Olimex SAM3-H256 with a SAM3S4BA-AU, where PB4..7 is used for JTAG, PB8..9 for XIN/XOUT and PB10..11 is connected to an USB interface.

I don't understand what blocks the writes to PIOB_ABCDSR2. Can anybody give me a hint, or am I alone here ?
CptTitanic
Posts: 871
Joined: Sat Oct 30, 2010 6:04 pm

Re: SAM3S4B DACC problem

Mon Apr 23, 2012 11:59 pm

You have the GPIO bank's clock enabled?

PMC_EnablePeripheral (PMC_PIOB_ID);

And those of any peripheral you're touching.
frame
Posts: 17
Joined: Mon Apr 23, 2012 10:32 am

Re: SAM3S4B DACC problem

Tue Apr 24, 2012 8:49 am

Yes, I tried with and without enabling the clock for PIOB, PIOA and DACC clock is enabled anyway.

Despite this (SAM3S datasheet "6500D–ATARM–29-Feb-12", p.441):
29.4.2 Power Management
The Power Management Controller controls the PIO Controller clock in order to save power.
Writing any of the registers of the user interface does not require the PIO Controller clock to be
enabled. This means that the configuration of the I/O lines does not require the PIO Controller
clock to be enabled.


I'm concerned of that non-effective write access to the PIOB_ABCDSR2 register. Write to other bits (0..3) had also no effect, neither from the program code nor directly from the debug GUI. The other bits, as mentioned, are tied to JTAG and USB, so I avoided experimenting with.
I use Crossworks for ARM - maybe there is something in the debug interface, that tries to prevent me from accidently killing the JTAG connection.
I'm going to ask these guys, too.
wasif
Posts: 2
Joined: Fri Oct 03, 2014 3:47 pm

Re: SAM3S4B DACC problem

Wed Oct 22, 2014 8:30 pm

As SAM3S4B has only two peripherals A & B , there is no C or D peripheral so it doesn't allow writing ABCDSR2 as in ABCDSR1 is enough to control two SAM3s4B peripehrals A and B.
However , i'm in same kind of trouble and can't get the DACC to work , did you find out the problem and please share the solution? 

Return to “SAM3 Cortex-M3 MCU”

Who is online

Users browsing this forum: No registered users and 1 guest