好久也没跑例程了。原因是板子坏了,怎么好得请看:SAM4N XPLAINED pro出现 No device detect性ed. Error 4109的解决办法
今天跑的是ADC例程:
在Atmel Studio6.2环境下插上SAM4N板子,就直接有打开新例程,那一项。然后打开ADC的那个例程,截图如下:
其中ADC软出管脚定义如下:
#ifndef CONF_DACC_SINEWAVE_EXAMPLE_H_INCLUDED
#define CONF_DACC_SINEWAVE_EXAMPLE_H_INCLUDED
//! DAC channel used for test (PB13)
#define DACC_CHANNEL 0
//! DAC register base for test
#define DACC_BASE DACC
//! DAC ID for test
#define DACC_ID ID_DACC
#endif /* CONF_DACC_SINEWAVE_EXAMPLE_H_INCLUDED */
也就是说用的是DAC通道0即第PB13脚输出。
而该程可以允许用户输入频率的大小,及幅度的大小,当然在一定范围内。其值的改变是在时钟中断里实现的
void SysTick_Handler(void)
{
uint32_t status;
uint32_t dac_val;
status = dacc_get_interrupt_status(DACC_BASE);
/* If ready for new data */
if ((status & DACC_ISR_TXRDY) == DACC_ISR_TXRDY) {
g_ul_index_sample++;
if (g_ul_index_sample >= SAMPLES) {
g_ul_index_sample = 0;
}
dac_val = g_uc_wave_sel ?
((g_ul_index_sample > SAMPLES / 2) ? 0 : MAX_AMPLITUDE)
: wave_to_dacc(gc_us_sine_data[g_ul_index_sample],
g_l_amplitude,
MAX_DIGITAL * 2, MAX_AMPLITUDE);
dacc_write_conversion_data(DACC_BASE, dac_val);
}
}
而主程序负责同用户交互:
while (1) {
usart_serial_getchar((Usart *)CONSOLE_UART, &uc_key);
switch (uc_key) {
case '0':
printf("Frequency:\t");
ul_freq = get_input_value(MIN_FREQUENCY, MAX_FREQUENCY);
printf("\r\n");
if (ul_freq != VAL_INVALID) {
printf("Set frequency to : %luHz\n\r", (unsigned long)ul_freq);
SysTick_Config(sysclk_get_cpu_hz() / (ul_freq * SAMPLES));
g_ul_frequency = ul_freq;
}
break;
case '1':
printf("Amplitude:\t");
ul_amp = get_input_value(MIN_AMPLITUDE, MAX_AMPLITUDE);
printf("\r\n");
if (ul_amp != VAL_INVALID) {
printf("Set amplitude to : %lu\n\r", (unsigned long)ul_amp);
g_l_amplitude = ul_amp;
}
break;
case 'i':
case 'I':
printf("-I- Frequency : %lu Hz Amplitude : %ld\n\r",
(unsigned long)g_ul_frequency, (long)g_l_amplitude);
break;
case 'w':
case 'W':
printf("-I- Switch wave to : %s\n\r", g_uc_wave_sel ?
"SINE" : "Full Amplitude SQUARE");
g_uc_wave_sel = (g_uc_wave_sel + 1) & 1;
break;
case 'm':
case 'M':
display_menu();
break;
}
puts("Press \'m\' or \'M\' to display the main menu again!\r");
}
以下是运行的载图:有关输出示波器的照片明天再发,今天手机没有拿。
|