Newbie needs help on triggering ADC from SCT - LPC1549 - LPCExpresso board

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Newbie needs help on triggering ADC from SCT - LPC1549 - LPCExpresso board

1,327 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by colin.burn@trelleborg.com on Wed May 18 04:26:32 MST 2016
Hello.
As a hardware engineer in a small company, I'm new to LPCExpresso, new to microcontrollers and new to programming in C. (Cue steep learnings curves!) So please forgive me if I'm asking simplistic questions!
I have a requirement to digitise telephony at 8kHz sampling rate and direct it through a serial port. Using the pre-installed example code, I've somehow (!) managed to get this working, along with a looped-back serial connection linked to the DAC. So audio in ends up as audio out.
My trouble is that the example ADC code uses a slow rate SysTick clock which can't go to 8kHz.
So I want to use one of the SCTs to trigger the ADC.
Having spent days trying to understand the sample SCT codes, I've got nowhere.
Can anyone suggest some simple code to persuade an SCT to trigger the ADC?
I stress that I'm new to C and therefore struggling to follow the highly nested example code. There seems to be a dislocation between the chip's user manual and the example code which doesn't help.
I'm using the LPCExpresso dev board with LPC1549 chip.

BTW, if anyone running this forum reads this, may I suggest adding a more advanced search factility. The ablity to use logical functions such as AND, OR, NOT in the search would *really" save time.
标签 (1)
0 项奖励
回复
2 回复数

1,066 次查看
lpcware
NXP Employee
NXP Employee
bump
0 项奖励
回复

1,066 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Wed May 18 09:48:20 MST 2016

Quote: colin.burn@trelleborg.com
Having spent days trying to understand the sample SCT codes...



Days   :quest:   You are lost 


Quote: colin.burn@trelleborg.com
Can anyone suggest some simple code to persuade an SCT to trigger the ADC?



There's no simple SCT code, SCT code is never simple 

This sample below should do what you are trying to do. It's not necessary to enable both interrupts. I've done this here so you can use your oscilloscope...

/*
===============================================================================
 Name        : main.c
 Author      : $(author)
 Version     :
 Copyright   : $(copyright)
 Description : main definition
===============================================================================
*/

#include "board.h"
#include <cr_section_macros.h>

#define ADC_RATE (8000)

volatile uint32_t sct_counter;//count sct events
volatile uint32_t adc_counter;//count adc events

#ifdef __cplusplus
extern "C" {
#endif

//SCT0 is triggering ADC
void SCT0_IRQHandler(void)
{
 if (LPC_SCT0->EVFLAG & SCT_EVT_0)
 {
  LPC_SCT0->EVFLAG = SCT_EVT_0;
  Board_LED_Toggle(0);
  sct_counter++;
 }
}

void ADC0A_IRQHandler(void)
{
uint32_t pending;
/* Get pending interrupts */
pending = Chip_ADC_GetFlags(LPC_ADC0);
/* Sequence A completion interrupt */
if (pending & ADC_FLAGS_SEQA_INT_MASK) {
adc_counter++;
}
Board_LED_Toggle(1);
/* Clear any pending interrupts */
Chip_ADC_ClearFlags(LPC_ADC0, pending);
}
#ifdef __cplusplus
}
#endif

void SCT0_init(void)
{
 Chip_SCT_Init(LPC_SCT0); /* The match/capture REGMODE defaults to match mode */
 Chip_SCT_Config(LPC_SCT0, (SCT_CONFIG_32BIT_COUNTER | SCT_CONFIG_CLKMODE_BUSCLK)); /* Configure the SCT as a 32bit counter using the bus clock */
 Chip_SCT_SetMatchCount(LPC_SCT0, SCT_MATCH_0, (SystemCoreClock/(ADC_RATE*2))-1); /* Set the match count for match register 0 */
 Chip_SCT_SetMatchReload(LPC_SCT0, SCT_MATCH_0,(SystemCoreClock/(ADC_RATE*2))-1); /* Set the match reload value */
 LPC_SCT0->STATE = 0;
 LPC_SCT0->EVENT[0].STATE  = (SCT_EVT_0);// events
 LPC_SCT0->EVENT[0].CTRL = (0 << 0)  |  // use match register
       (1 << 12) |  // COMBMODE[13:12] = match condition
                           (1 << 14) |  // STATELD[14]   = STATEV is loaded
                           (0 << 15);   // STATEV[19:15] =
 LPC_SCT0->LIMIT = (1<<0);//limiting match register

 LPC_SCT0->OUT[7].SET    = (1 << 0);   //set SCT0_OUTn with event
 LPC_SCT0->OUT[7].CLR    = (1 << 0);   //clear SCT0_OUTn with event
 LPC_SCT0->RES           = (3 << (7<<1));   //conflict: toggle
 Chip_SCT_EnableEventInt(LPC_SCT0,SCT_EVT_0); /* Enable an Interrupt on the Match Event */
 NVIC_EnableIRQ(SCT0_IRQn);
 Chip_SCT_ClearControl(LPC_SCT0, SCT_CTRL_HALT_L | SCT_CTRL_HALT_H);//and start
}

void ADC_init(void)
{
 //PIN setup
 //set PIO1.0 to ADC0.8
 Chip_IOCON_PinMuxSet(LPC_IOCON, 1, 0, IOCON_MODE_INACT);
 Chip_SWM_EnableFixedPin(SWM_FIXED_ADC0_8);
 LPC_IOCON->PIO[1][0] = IOCON_MODE_INACT;
 /* Setup ADC for 12-bit mode and normal power */
 Chip_ADC_Init(LPC_ADC0, 0);
/* For ADC0, sequencer A will be used without threshold events.
   It will be triggered by SCT0 out7 */
 Chip_ADC_SetupSequencer(LPC_ADC0, ADC_SEQA_IDX, (ADC_SEQ_CTRL_CHANSEL(8) |
 ADC0_SEQ_CTRL_HWTRIG_SCT0_OUT7  | ADC_SEQ_CTRL_MODE_EOS));
 /* Use higher voltage trim for both ADCs */
 Chip_ADC_SetTrim(LPC_ADC0, ADC_TRIM_VRANGE_HIGHV);
 /* Need to do a calibration after initialization and trim */
 Chip_ADC_StartCalibration(LPC_ADC0);
 while (!(Chip_ADC_IsCalibrationDone(LPC_ADC0))) {}
 /* Setup for maximum ADC clock rate */
 Chip_ADC_SetClockRate(LPC_ADC0, ADC_MAX_SAMPLE_RATE);
 /* Clear all pending interrupts */
 Chip_ADC_ClearFlags(LPC_ADC0, Chip_ADC_GetFlags(LPC_ADC0));
 /* Enable sequence A completion interrupts for ADC0 */
 Chip_ADC_EnableInt(LPC_ADC0, ADC_INTEN_SEQA_ENABLE);
 /* Enable related ADC NVIC interrupts */
 NVIC_EnableIRQ(ADC0_SEQA_IRQn);
 /* Enable sequencers */
 Chip_ADC_EnableSequencer(LPC_ADC0, ADC_SEQA_IDX);
}

int main(void)
{
 SystemCoreClockUpdate();
 Board_Init();
 Board_LED_Set(0, true);
 SCT0_init();
 ADC_init();
 while(1)
 {
 }
 return 0 ;
}


Sample...
0 项奖励
回复