本帖最后由 youzizhile 于 2014-9-16 10:57 编辑
LPC1500体验+开发环境的构建
LPC1500体验+驱动步进电机设计
LPC1500体验+led闪烁
LPC1500体验+之四_串口调试接收数据成功
LPC1500体验+之五_LCD1602驱动电路设计
LPC1500体验+之六_步进电机驱动设计
一直说要使用LPC1549的AD做些东西,但是总是忙于其他事情而一直拖延。之前答应了管理员要发布使用心得的,但是总是被其他事情耽搁了。今天要先发一个初步的使用总结。
一直想使用ad和da做一套dds数字信号发生器,接下来要好好的设计下了。
先说下LPC1549的AD吧。
配置方法如下:
•
使用SYSAHBCLKCTRL0 寄存器使能ADC0/1的寄存器和ad时钟。
• 使用
PRESETCTRL0清除 ADC0/1复位状态;
•每一个ADC时钟产生4个中断,分别连接到中断向量 slot #31/35
(ADC0/1_SEQA), slot #32/36 (ADC0/1_SEQB), slot #33/37 (ADC0/1_THCMP), and
slot #34/38 (ADC0/1_OVR). 中断还可以配置为通过INPUT MUXDMA触发和作为SCTs的输入;
•使用转换矩阵使能ADC的模拟量输入;
• 使用
PDRUNCFG寄存器使能ADC0/1的电源;
•每一次上电或者从深度睡眠状态唤醒后需要校准ADC
;
•还可以选择两种时钟来源:
– 使用系统同步时钟,这种配置允许外部触发但需要50Mhz的时钟
– 使用IRC或者PLL输出的异步时钟,这种配置所需要的时钟是独立的,为了同步ADC的输入触发需要额外的时间。
•通过TRM寄存器 配置ADC到合适的电源供电电源。
系统使用一个电位器连接在VCC5V和地之间来实现0到5V的转变,下面是硬件连接图:
下面为程序片段
/* Setup ADC for 12-bit mode and normal power */
Chip_ADC_Init(LPC_ADC0, 0);
Chip_ADC_Init(LPC_ADC1, 0);
/* Setup for maximum ADC clock rate */
Chip_ADC_SetClockRate(LPC_ADC0, ADC_MAX_SAMPLE_RATE);
Chip_ADC_SetClockRate(LPC_ADC1, ADC_MAX_SAMPLE_RATE);
/* For ADC0, seqeucner A will be used without threshold events.
It will be triggered manually by the sysTick interrupt and
only monitor the internal temperature sensor. */
Chip_ADC_SetupSequencer(LPC_ADC0, ADC_SEQA_IDX, (ADC_SEQ_CTRL_CHANSEL(0) |
ADC_SEQ_CTRL_MODE_EOS));
/* Power up the internal temperature sensor */
Chip_SYSCTL_PowerUp(SYSCTL_POWERDOWN_TS_PD);
/* For ADC0, select temperature sensor for channel 0 on ADC0 */
Chip_ADC_SetADC0Input(LPC_ADC0, ADC_INSEL_TS);
#if defined(BOARD_NXP_LPCXPRESSO_1549)
/* Use higher voltage trim for both ADCs */
Chip_ADC_SetTrim(LPC_ADC0, ADC_TRIM_VRANGE_HIGHV);
Chip_ADC_SetTrim(LPC_ADC1, ADC_TRIM_VRANGE_HIGHV);
/* For ADC1, seqeucner A will be used with threshold events.
It will be triggered manually by the sysTick interrupt and
only monitors the ADC1 input. */
Chip_ADC_SetupSequencer(LPC_ADC1, ADC_SEQA_IDX,
(ADC_SEQ_CTRL_CHANSEL(BOARD_ADC_CH) | ADC_SEQ_CTRL_MODE_EOS));
/* Disables pullups/pulldowns and disable digital mode */
Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 9, (IOCON_MODE_INACT | IOCON_DIGMODE_EN));
/* Assign ADC1_1 to PIO0_9 via SWM (fixed pin) */
Chip_SWM_EnableFixedPin(SWM_FIXED_ADC1_1);
#else
#warning "No ADC setup for this example"
#endif
/* Need to do a calibration after initialization and trim */
Chip_ADC_StartCalibration(LPC_ADC0);
Chip_ADC_StartCalibration(LPC_ADC1);
while (!(Chip_ADC_IsCalibrationDone(LPC_ADC0))) {}
while (!(Chip_ADC_IsCalibrationDone(LPC_ADC1))) {}
/* Setup threshold 0 low and high values to about 25% and 75% of max for
ADC1 only */
Chip_ADC_SetThrLowValue(LPC_ADC1, 0, ((1 * 0xFFF) / 4));
Chip_ADC_SetThrHighValue(LPC_ADC1, 0, ((3 * 0xFFF) / 4));
/* Clear all pending interrupts */
Chip_ADC_ClearFlags(LPC_ADC0, Chip_ADC_GetFlags(LPC_ADC0));
Chip_ADC_ClearFlags(LPC_ADC1, Chip_ADC_GetFlags(LPC_ADC1));
/* Enable sequence A completion interrupts for ADC0 */
Chip_ADC_EnableInt(LPC_ADC0, ADC_INTEN_SEQA_ENABLE);
/* Enable sequence A completion and threshold crossing interrupts for ADC1_1 */
Chip_ADC_EnableInt(LPC_ADC1, ADC_INTEN_SEQA_ENABLE |
ADC_INTEN_CMP_ENABLE(ADC_INTEN_CMP_CROSSTH, BOARD_ADC_CH));
/* Use threshold 0 for ADC channel and enable threshold interrupt mode for
channel as crossing */
Chip_ADC_SelectTH0Channels(LPC_ADC1, ADC_THRSEL_CHAN_SEL_THR1(BOARD_ADC_CH));
Chip_ADC_SetThresholdInt(LPC_ADC1, BOARD_ADC_CH, ADC_INTEN_THCMP_CROSSING);
/* Enable related ADC NVIC interrupts */
NVIC_EnableIRQ(ADC0_SEQA_IRQn);
NVIC_EnableIRQ(ADC1_SEQA_IRQn);
NVIC_EnableIRQ(ADC1_THCMP);
/* Enable sequencers */
Chip_ADC_EnableSequencer(LPC_ADC0, ADC_SEQA_IDX);
Chip_ADC_EnableSequencer(LPC_ADC1, ADC_SEQA_IDX);
/* This example uses the periodic sysTick to manually trigger the ADC,
but a periodic timer can be used in a match configuration to start
an ADC sequence without software intervention. */
SysTick_Config(Chip_Clock_GetSysTickClockRate() / TICKRATE_HZ);
/* Endless loop */
while (1) {
/* Sleep until something happens */
__WFI();
if (threshold1Crossed) {
threshold1Crossed = false;
DEBUGSTR("********ADC1 threshold event********\r\n");
}
/* Is a conversion sequence complete? */
if (sequence0Complete) {
showValudeADC(LPC_ADC0);
}
if (sequence1Complete) {
showValudeADC(LPC_ADC1);
}
程序运行的结果,暂时只是简单的使用,接下来要进一步开发:
LPC1500体验+开发环境的构建
LPC1500体验+驱动步进电机设计
LPC1500体验+led闪烁
LPC1500体验+之四_串口调试接收数据成功
LPC1500体验+之五_LCD1602驱动电路设计
LPC1500体验+之六_步进电机驱动设计