Generate sine waves with 2 mbeds synchronised. Configurable amplitude and phase. Built for 50 Hz mains simulations.

Dependencies:   MODDMA mbed

Description

Small program based on the MODDMA buffered sine wave example.

This programs reads pin 22 to operate in Master (low) or Slave mode. Then configures pin 21 as output (master) or input (slave), in master mode led2 is on. Use a resistor (100 ohm) between the pin21's of master to slave.

The program then calculates a buffer of sine waves for the DMA with parameters given. And starts the DMA and DAC to generate the sine.

On the callbacks of the dma complete (there are 2) slave waits for a sync and master gives a sync, p21. Master waits a few extra clocks to make sure slave is ready.

Commands can be given over Serial port to modify the parameters on the run. Frequency can be changed for master and slave, but it is better to keep the same. Use "f xx.xx". Phase can be changed for master and slave Amplitude can be changed for master and slave.

Hookup

  • Wire p22 high or low.
  • Serial sr(p9,p10) from master to slave.
  • Wire trigger p21 to p21.
  • Output p18 (analogout)

Information

Do not forget a small RC filter on the DAC output.

Master Commands

<master/slave/frequency> <frequency/phase/amplitude> <space> <number> <line feed>

Example commands for serial:

  • master frequency 50.1 hz
    • mf 50.1\n
  • frequency 50.1 Hz
    • f 50.1\n
  • master phase 3.1415 (or 1.0)
    • mp 1\n
  • slave phase 1.5 pi
    • sp 1.5\n

Or use this GUI

https://dl.dropboxusercontent.com/s/uvwsroyu41vzkwg/2013-06-19%2010_35_52-WaveSim.png

Download, or Download C# Code (Visual Studio 2010)

Committer:
jeroen3
Date:
Fri May 31 14:45:27 2013 +0000
Revision:
2:edd6401d9aa0
Fixed sine generator bug.; Added command line over USB uart

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jeroen3 2:edd6401d9aa0 1 // Simon's Watchdog code from
jeroen3 2:edd6401d9aa0 2 // http://mbed.org/forum/mbed/topic/508/
jeroen3 2:edd6401d9aa0 3 class Watchdog {
jeroen3 2:edd6401d9aa0 4 public:
jeroen3 2:edd6401d9aa0 5 // Load timeout value in watchdog timer and enable
jeroen3 2:edd6401d9aa0 6 void kick(float s) {
jeroen3 2:edd6401d9aa0 7 LPC_WDT->WDCLKSEL = 0x1; // Set CLK src to PCLK
jeroen3 2:edd6401d9aa0 8 uint32_t clk = SystemCoreClock / 16; // WD has a fixed /4 prescaler, PCLK default is /4
jeroen3 2:edd6401d9aa0 9 LPC_WDT->WDTC = s * (float)clk;
jeroen3 2:edd6401d9aa0 10 LPC_WDT->WDMOD = 0x3; // Enabled and Reset
jeroen3 2:edd6401d9aa0 11 kick();
jeroen3 2:edd6401d9aa0 12 }
jeroen3 2:edd6401d9aa0 13 // "kick" or "feed" the dog - reset the watchdog timer
jeroen3 2:edd6401d9aa0 14 // by writing this required bit pattern
jeroen3 2:edd6401d9aa0 15 void kick() {
jeroen3 2:edd6401d9aa0 16 LPC_WDT->WDFEED = 0xAA;
jeroen3 2:edd6401d9aa0 17 LPC_WDT->WDFEED = 0x55;
jeroen3 2:edd6401d9aa0 18 }
jeroen3 2:edd6401d9aa0 19 };