SAMD21 speed with interrupts

I'm at the design outline stage of a project that will control a quad channel trailing edge dimmer (based on the design from Elliott Sound Products)
Rather than generate the reference saw tooth ramp using hardware I want to do this in software using the Zero's builtin DAC, and approximate the smooth ramp with a series of discrete values.
Some relevant info follows:

  • I will synchronise the ramp output to a zero crossing mains signal, so assume an interrupt on a digital input pin is required (the conversion from hazardous AC voltage to a safe low voltage is covered in the original design). At 50Hz mains this will fire every 10mSec - to reset the ramp output value to zero.
  • The spec I'm working with requires a dimming resolution of 2.5% steps so that means 40 discrete steps for each ramp cycle. Consequently the DAC output value will need to change every 25 micro seconds, so I am thinking of using a timer based interrupt to increment the current ramp output value. The spec sheet for the underlying SAMD21 states the built in DAC is capable of outputting 350ksps, so the 4ksps I require should be fine.
  • The rest of the code (in the loop function) will be dealing with receiving signals to control brightness and providing user feedback etc via an SPI interface to a network communications processor.

Now to my questions.

  1. Is the Zero capable of running all of this and not dropping any steps, or slowing the loop excessively ?
  2. How many low level instructions can the processor run between interrupts (48MHz and 25uSec between interrupts would indicate around 1,200 instructions could be processed in that time) ?
  3. What is the correlation between high level language instructions such as for loops, digital pin reading/writing etc and low level processor instructions - so I can get an idea of what features my code can contain ?

I have this

Highly variable. You can look at it by disassembling the .elf file with the objdump utility that is part of the compiler suite. The Cortex M0 is only so-so, code efficiency wise.

What about DMA? I believe you can combine a timer, the "Event System", and DMA to output a DAC sample at user-chosen intervals. (It's far beyond the services provided by the Arduino environment, though.)

Thanks for the suggestions. I've changed the design so will no longer require the DAC, and instead will just output active HIGH for the portion of the wave form where the light should be on.
I'm building myself an evaluation board that will have opto isolated drivers (Si8751) for the output stages so I can write some code and see how many steps I can in the dimming stage. Ideally I will have a min of 40 (which gives a 2.5% change in output for a smooth dimming appearance).
At this rate, a change is required every 25uSec. At 48Mhz that is an interrupt every 12,000 processor cycles. I'm guessing this is achievable.

I'll finish laying out the board today, so should have something to prototype in a few weeks.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.