No.60007 作者:liufengzhong 邮件:l_fz@sina.com ID:149522 登陆:12次 文章数:695篇 最后登陆IP:183.13.93.245 最后登陆:2015/6/16 17:02:27 注册:2014/7/29 21:51:15 财富:3671 发帖时间:2014/8/13 12:15:35 发贴者IP:111.221.200.181 标题:liufengzhong:[转帖]怎么样为模拟slicekit例子改变ADC的分辨率? 摘要:No.60007[转帖]怎么样为模拟slicekit例子改变ADC的分辨率? 在下面的例子我怎么样改变它读取12bit值而不是8位 我尝试改变 ADC_8_BPS 为 ADC_16_BPS; 我改变了所有的未签名的字符为未签名的int类型等,但我试图运行时获得一个异常信息。 任何指导我都感激。 我不需要PWM,只是想用操作杆在满res测试ADC 我知道这是早期开发板,但肯定希望有一些文档关于ADC库函数和它们如何与硬件工作。 #include <xscope.h> #include "analog_tile_support.h" #include "pwm_tutorial_example.h" #include "debug_print.h" #define PWM_PERIOD 200 // Set PWM period to 2us, 500KHz #define ADC_PERIOD 100000 // 1ms ADC trigger - Sample at 1KHz #define PRINT_PERIOD 10000000 // 100ms printing rate #define pwm_duty_calc(x) ((x * (PWM_PERIOD-2)) > > 8) //duty calc macro, 255 input = full scale //Port definitions //Note that these assume use of XP-SKC-A16 + XA-SK-MIXED-SIGNAL hardware on tile[0]: port trigger_port = PORT_ADC_TRIGGER; //XD70 Port P32A bit 19 on tile[0]: port pwm_dac_port = XS1_PORT_1G; //XD22 PWM2 on mixed signal slice void xscope_user_init(void) { xscope_register(2, XSCOPE_CONTINUOUS, "Joystick ADC2", XSCOPE_UINT, "8b value", XSCOPE_CONTINUOUS, "Header ADC4", XSCOPE_UINT, "8b value"); xscope_config_io(XSCOPE_IO_BASIC); } void adc_pwm_dac_example(chanend c_adc, chanend c_pwm_dac) { timer t_adc_timer, t_print_timer; unsigned int adc_time, print_time; unsigned data[2]; //Array for storing ADC results unsigned char joystick, header, header_old; //ADC values debug_printf("Analog loopback demo started.\n"); at_adc_config_t adc_config = {{ 0, 0, 0, 0, 0, 0, 0, 0 }, 0, 0, 0 }; //initialise all ADC to off adc_config.input_enable[2] = 1; //Input 2 is horizontal axis of the joystick adc_config.input_enable[4] = 1; //Input 4 is ADC4 analog input on header adc_config.bits_per_sample = ADC_8_BPS; adc_config.samples_per_packet = 2; //Allow both samples to be sent in one hit adc_config.calibration_mode = 0; //Normal ADC operation - disable self calibration at_adc_enable(analog_tile, c_adc, trigger_port, adc_config); c_pwm_dac <: PWM_PERIOD; //Set PWM period c_pwm_dac <: pwm_duty_calc(0); //Set initial duty cycle t_print_timer ......
>>返回讨论的主题
|