Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of Impedance_Fast_Circuitry by
Diff: pdb.cpp
- Revision:
- 45:d591d138cdeb
- Parent:
- 39:82dc3daecf32
- Child:
- 46:a015ebf4663b
--- a/pdb.cpp Fri Jan 30 14:56:58 2015 +0000 +++ b/pdb.cpp Sat Jan 31 07:25:52 2015 +0000 @@ -1,59 +1,65 @@ #include "pdb.h" -void pdb_init(Serial &pc) { +Serial debug2(USBTX,USBRX); + +void pdb_init() { // initialize the Programmable Delay Block - SIM->SCGC6 |= SIM_SCGC6_PDB_MASK; // turn on the clock to the PDB + + // turn on the clock to the PDB + SIM->SCGC6 |= SIM_SCGC6_PDB_MASK; + + // set ADC trigger to PDB0 + SIM_SOPT7 = SIM_SOPT7_ADC0TRGSEL(0); // Configure the Peripheral Delay Block (PDB): PDB0_IDLY = 0x05; // need to trigger interrupt every counter reset which happens when modulus reached - PDB0_MOD = 0xd2; // largest period possible with the slections above, so slow you can see each conversion. - PDB0_CH0DLY0 = 0x00; - PDB0_CH0DLY1 = 0x00; + PDB0_MOD = 0xd2; + PDB0_CH0DLY0 = 0xa0; + PDB0_CH0DLY1 = 0xa0; PDB0_CH1DLY0 = 0x00; PDB0_CH1DLY1 = 0x00; PDB0_CH0C1 = PDB_C1_EN(0x01) | PDB_C1_TOS(0x01) | PDB_C1_EN(0x02) | PDB_C1_TOS(0x02) ; // channel 0 pretrigger 0 and 1 enabled and delayed PDB0_CH1C1 = PDB_C1_EN(0x01) | PDB_C1_TOS(0x01) | PDB_C1_EN(0x02) | PDB_C1_TOS(0x02) ; // channel 1 pretrigger 0 and 1 enabled and delayed - PDB0_SC = PDB_SC_CONT_MASK // Contintuous, rather than one-shot, mode - | PDB_SC_PDBEN_MASK // PDB enabled - //| PDB_SC_PDBIE_MASK // PDB Interrupt Enable - | PDB_SC_PRESCALER(0) // Slow down the period of the PDB for testing - | PDB_SC_TRGSEL(0xf) // Trigger source is Software Trigger to be invoked in this file - | PDB_SC_MULT(0) // Multiplication factor 20 for the prescale divider for the counter clock - | PDB_SC_LDOK_MASK; // Need to ok the loading or it will not load certain regsiters! - - - - SIM_SOPT7 = SIM_SOPT7_ADC0TRGSEL(0); // set ADC trigger to PDB0 + // Setup Staus and Control Register + PDB0_SC = 0; // clear register + PDB0_SC = PDB_SC_PRESCALER(0) // Slow down the period of the PDB for testing + | PDB_SC_TRGSEL(0xf) // Trigger source is Software Trigger to be invoked in this file + | PDB_SC_PDBEN_MASK // PDB enabled + | PDB_SC_PDBIE_MASK // PDB Interrupt Enable + | PDB_SC_MULT(0) // Multiplication factor 20 for the prescale divider for the counter clock + | PDB_SC_CONT_MASK // Contintuous, rather than one-shot, mode + | PDB_SC_LDOK_MASK; // Need to ok the loading or it will not load certain regsiters! - pc.printf("PDB0_SC: %08x\r\n",PDB0_SC); - pc.printf("PDB0_MOD: %08x\r\n",PDB0_MOD); - pc.printf("PDB0_CNT: %08x\r\n",PDB0_CNT); - pc.printf("PDB0_IDLY: %08x\r\n",PDB0_IDLY); - pc.printf("PDB0_CH0C1: %08x\r\n",PDB0_CH0C1); - pc.printf("PDB0_CH0S: %08x\r\n",PDB0_CH0S); - pc.printf("PDB0_CH0DLY0: %08x\r\n",PDB0_CH0DLY0); - pc.printf("PDB0_CH0DLY1: %08x\r\n",PDB0_CH0DLY1); - pc.printf("PDB0_CH1C1: %08x\r\n",PDB0_CH1C1); - pc.printf("PDB0_CH1S: %08x\r\n",PDB0_CH1S); - pc.printf("PDB0_CH1DLY0: %08x\r\n",PDB0_CH1DLY0); - pc.printf("PDB0_CH1DLY1: %08x\r\n",PDB0_CH1DLY1); - pc.printf("PDB0_DACINTC0: %08x\r\n",PDB0_DACINTC0); - pc.printf("PDB0_DACINT0: %08x\r\n",PDB0_DACINT0); - pc.printf("PDB0_DACINTC1: %08x\r\n",PDB0_DACINTC1); - pc.printf("PDB0_DACINT1: %08x\r\n",PDB0_DACINT1); - pc.printf("PDB0_POEN: %08x\r\n",PDB0_POEN); - pc.printf("PDB0_PO0DLY: %08x\r\n",PDB0_PO0DLY); - pc.printf("PDB0_PO1DLY: %08x\r\n",PDB0_PO1DLY); - pc.printf("PDB0_PO2DLY: %08x\r\n\n",PDB0_PO2DLY); + debug2.printf("PDB0_SC: %08x\r\n",PDB0_SC); + debug2.printf("PDB0_MOD: %08x\r\n",PDB0_MOD); + debug2.printf("PDB0_CNT: %08x\r\n",PDB0_CNT); + debug2.printf("PDB0_IDLY: %08x\r\n",PDB0_IDLY); + debug2.printf("PDB0_CH0C1: %08x\r\n",PDB0_CH0C1); + debug2.printf("PDB0_CH0S: %08x\r\n",PDB0_CH0S); + debug2.printf("PDB0_CH0DLY0: %08x\r\n",PDB0_CH0DLY0); + debug2.printf("PDB0_CH0DLY1: %08x\r\n",PDB0_CH0DLY1); + debug2.printf("PDB0_CH1C1: %08x\r\n",PDB0_CH1C1); + debug2.printf("PDB0_CH1S: %08x\r\n",PDB0_CH1S); + debug2.printf("PDB0_CH1DLY0: %08x\r\n",PDB0_CH1DLY0); + debug2.printf("PDB0_CH1DLY1: %08x\r\n",PDB0_CH1DLY1); + debug2.printf("PDB0_DACINTC0: %08x\r\n",PDB0_DACINTC0); + debug2.printf("PDB0_DACINT0: %08x\r\n",PDB0_DACINT0); + debug2.printf("PDB0_DACINTC1: %08x\r\n",PDB0_DACINTC1); + debug2.printf("PDB0_DACINT1: %08x\r\n",PDB0_DACINT1); + debug2.printf("PDB0_POEN: %08x\r\n",PDB0_POEN); + debug2.printf("PDB0_PO0DLY: %08x\r\n",PDB0_PO0DLY); + debug2.printf("PDB0_PO1DLY: %08x\r\n",PDB0_PO1DLY); + debug2.printf("PDB0_PO2DLY: %08x\r\n\n",PDB0_PO2DLY); } void pdb_start() { - PDB0->SC |= PDB_SC_SWTRIG_MASK; // enable software trigger (start the PDB) + PDB0_SC |= PDB_SC_PDBEN_MASK; // PDB enabled + PDB0_SC |= PDB_SC_SWTRIG_MASK; // enable software trigger (start the PDB) } void pdb_stop() { - + PDB0_SC &= ~PDB_SC_PDBEN_MASK; // PDB disabled } \ No newline at end of file