我在学习28335控制电机,想用28335的adc的双通道ADCINA0,ADCINA1同时采样2相电流,用ADCINA2采样电池电压,不知如何配置寄存器?
如下是我的程序,
SysCtrlRegs.HISPCP.all = 0x0003; //AdcClock = SYSCLKOUT/6 = 25MHZ
EALLOW; // Enable EALLOW
SysCtrlRegs.PCLKCR0.bit.ADCENCLK = 1; // Enable SYSCLKOUT to ADC
ADC_cal();
EDIS; // Disable EALLOW
EALLOW;
// 设置ADC的参考电压源
AdcRegs.ADCREFSEL.all=0;
//ADC模块上电
AdcRegs.ADCTRL3.all = 0x00E0; // ADC power-up
AdcRegs.ADCTRL1.bit.ACQ_PS = 0; AdcRegs.ADCTRL3.bit.ADCCLKPS = 0;
AdcRegs.ADCTRL1.bit.SEQ_CASC = 1; // Setup cascaded sequencer mode
AdcRegs.ADCTRL1.bit.CONT_RUN = 1; // Setup continuous run
AdcRegs.ADCTRL1.bit.SEQ_OVRD = 0; // Enable Sequencer override feature
AdcRegs.ADCMAXCONV.all = 0x0002; // 3 double conv's (16 total)
AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x0; // Setup conv from ADCINA0
AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 0x1; // Setup conv from ADCINA1
AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 0x2; // Setup conv from ADCINA2
AdcRegs.ADCTRL2.bit.EPWM_SOCA_SEQ1 = 1; // Enable SOCA from ePWM to start SEQ1
// Start SEQ1
AdcRegs.ADCTRL2.bit.SOC_SEQ1 = 1; // Start SEQ1
EDIS;
DELAY_US( ADC_usDELAY );
在pwm中断里里取adc值:
while (AdcRegs.ADCST.bit.INT_SEQ1== 0){}
AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1;
EPwm2Regs.ETCLR.bit.SOCA = 1;
ad1 = ((AdcRegs.ADCRESULT0)>>4 ;
ad2 = ((AdcRegs.ADCRESULT1)>>4 ;
ad3 = ((AdcRegs.ADCRESULT2)>>4);
请帮我解决纠错一下:多谢多谢!
PINRAN LIAO:
我记得它里面可以配置为同步采样模式吧!官方手册说的是可以将ADCA0和ADCB0配置为同步采样模式,但是在采样时先对A0进行采样,然后对B0进行采样
我在学习28335控制电机,想用28335的adc的双通道ADCINA0,ADCINA1同时采样2相电流,用ADCINA2采样电池电压,不知如何配置寄存器?
如下是我的程序,
SysCtrlRegs.HISPCP.all = 0x0003; //AdcClock = SYSCLKOUT/6 = 25MHZ
EALLOW; // Enable EALLOW
SysCtrlRegs.PCLKCR0.bit.ADCENCLK = 1; // Enable SYSCLKOUT to ADC
ADC_cal();
EDIS; // Disable EALLOW
EALLOW;
// 设置ADC的参考电压源
AdcRegs.ADCREFSEL.all=0;
//ADC模块上电
AdcRegs.ADCTRL3.all = 0x00E0; // ADC power-up
AdcRegs.ADCTRL1.bit.ACQ_PS = 0; AdcRegs.ADCTRL3.bit.ADCCLKPS = 0;
AdcRegs.ADCTRL1.bit.SEQ_CASC = 1; // Setup cascaded sequencer mode
AdcRegs.ADCTRL1.bit.CONT_RUN = 1; // Setup continuous run
AdcRegs.ADCTRL1.bit.SEQ_OVRD = 0; // Enable Sequencer override feature
AdcRegs.ADCMAXCONV.all = 0x0002; // 3 double conv's (16 total)
AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x0; // Setup conv from ADCINA0
AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 0x1; // Setup conv from ADCINA1
AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 0x2; // Setup conv from ADCINA2
AdcRegs.ADCTRL2.bit.EPWM_SOCA_SEQ1 = 1; // Enable SOCA from ePWM to start SEQ1
// Start SEQ1
AdcRegs.ADCTRL2.bit.SOC_SEQ1 = 1; // Start SEQ1
EDIS;
DELAY_US( ADC_usDELAY );
在pwm中断里里取adc值:
while (AdcRegs.ADCST.bit.INT_SEQ1== 0){}
AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1;
EPwm2Regs.ETCLR.bit.SOCA = 1;
ad1 = ((AdcRegs.ADCRESULT0)>>4 ;
ad2 = ((AdcRegs.ADCRESULT1)>>4 ;
ad3 = ((AdcRegs.ADCRESULT2)>>4);
请帮我解决纠错一下:多谢多谢!
mangui zhang:
串行采样的代码 你参考一下
// Specific ADC setup for this example: AdcRegs.ADCTRL1.bit.ACQ_PS = ADC_SHCLK; AdcRegs.ADCTRL3.bit.ADCCLKPS = ADC_CKPS; AdcRegs.ADCTRL1.bit.SEQ_CASC = 1; // 0 Non-Cascaded Mode; 1 Cascaded Mode AdcRegs.ADCTRL2.bit.INT_ENA_SEQ1 = 0x1; AdcRegs.ADCTRL2.bit.RST_SEQ1 = 0x1; AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x0; AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 0x1; AdcRegs.ADCCHSELSEQ1.bit.CONV02 = 0x2; AdcRegs.ADCCHSELSEQ1.bit.CONV03 = 0x3; AdcRegs.ADCCHSELSEQ2.bit.CONV04 = 0x4; AdcRegs.ADCCHSELSEQ2.bit.CONV05 = 0x5; AdcRegs.ADCCHSELSEQ2.bit.CONV06 = 0x6; AdcRegs.ADCCHSELSEQ2.bit.CONV07 = 0x7; AdcRegs.ADCCHSELSEQ3.bit.CONV08 = 0x8; AdcRegs.ADCCHSELSEQ3.bit.CONV09 = 0x9; AdcRegs.ADCCHSELSEQ3.bit.CONV10 = 0xA; AdcRegs.ADCCHSELSEQ3.bit.CONV11 = 0xB; AdcRegs.ADCCHSELSEQ4.bit.CONV12 = 0xC; AdcRegs.ADCCHSELSEQ4.bit.CONV13 = 0xD; AdcRegs.ADCCHSELSEQ4.bit.CONV14 = 0xE; AdcRegs.ADCCHSELSEQ4.bit.CONV15 = 0xF;
AdcRegs.ADCMAXCONV.bit.MAX_CONV1 = 15; // Set up ADC to perform 4 conversions for every SOC
我在学习28335控制电机,想用28335的adc的双通道ADCINA0,ADCINA1同时采样2相电流,用ADCINA2采样电池电压,不知如何配置寄存器?
如下是我的程序,
SysCtrlRegs.HISPCP.all = 0x0003; //AdcClock = SYSCLKOUT/6 = 25MHZ
EALLOW; // Enable EALLOW
SysCtrlRegs.PCLKCR0.bit.ADCENCLK = 1; // Enable SYSCLKOUT to ADC
ADC_cal();
EDIS; // Disable EALLOW
EALLOW;
// 设置ADC的参考电压源
AdcRegs.ADCREFSEL.all=0;
//ADC模块上电
AdcRegs.ADCTRL3.all = 0x00E0; // ADC power-up
AdcRegs.ADCTRL1.bit.ACQ_PS = 0; AdcRegs.ADCTRL3.bit.ADCCLKPS = 0;
AdcRegs.ADCTRL1.bit.SEQ_CASC = 1; // Setup cascaded sequencer mode
AdcRegs.ADCTRL1.bit.CONT_RUN = 1; // Setup continuous run
AdcRegs.ADCTRL1.bit.SEQ_OVRD = 0; // Enable Sequencer override feature
AdcRegs.ADCMAXCONV.all = 0x0002; // 3 double conv's (16 total)
AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x0; // Setup conv from ADCINA0
AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 0x1; // Setup conv from ADCINA1
AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 0x2; // Setup conv from ADCINA2
AdcRegs.ADCTRL2.bit.EPWM_SOCA_SEQ1 = 1; // Enable SOCA from ePWM to start SEQ1
// Start SEQ1
AdcRegs.ADCTRL2.bit.SOC_SEQ1 = 1; // Start SEQ1
EDIS;
DELAY_US( ADC_usDELAY );
在pwm中断里里取adc值:
while (AdcRegs.ADCST.bit.INT_SEQ1== 0){}
AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1;
EPwm2Regs.ETCLR.bit.SOCA = 1;
ad1 = ((AdcRegs.ADCRESULT0)>>4 ;
ad2 = ((AdcRegs.ADCRESULT1)>>4 ;
ad3 = ((AdcRegs.ADCRESULT2)>>4);
请帮我解决纠错一下:多谢多谢!
mangui zhang:
AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x0; // Setup conv from ADCINA0 AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 0x1; // Setup conv from ADCINA1 AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 0x2; // Setup conv from ADCINA2
我感觉你的AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 0x2; 设置不合理吧
我在学习28335控制电机,想用28335的adc的双通道ADCINA0,ADCINA1同时采样2相电流,用ADCINA2采样电池电压,不知如何配置寄存器?
如下是我的程序,
SysCtrlRegs.HISPCP.all = 0x0003; //AdcClock = SYSCLKOUT/6 = 25MHZ
EALLOW; // Enable EALLOW
SysCtrlRegs.PCLKCR0.bit.ADCENCLK = 1; // Enable SYSCLKOUT to ADC
ADC_cal();
EDIS; // Disable EALLOW
EALLOW;
// 设置ADC的参考电压源
AdcRegs.ADCREFSEL.all=0;
//ADC模块上电
AdcRegs.ADCTRL3.all = 0x00E0; // ADC power-up
AdcRegs.ADCTRL1.bit.ACQ_PS = 0; AdcRegs.ADCTRL3.bit.ADCCLKPS = 0;
AdcRegs.ADCTRL1.bit.SEQ_CASC = 1; // Setup cascaded sequencer mode
AdcRegs.ADCTRL1.bit.CONT_RUN = 1; // Setup continuous run
AdcRegs.ADCTRL1.bit.SEQ_OVRD = 0; // Enable Sequencer override feature
AdcRegs.ADCMAXCONV.all = 0x0002; // 3 double conv's (16 total)
AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x0; // Setup conv from ADCINA0
AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 0x1; // Setup conv from ADCINA1
AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 0x2; // Setup conv from ADCINA2
AdcRegs.ADCTRL2.bit.EPWM_SOCA_SEQ1 = 1; // Enable SOCA from ePWM to start SEQ1
// Start SEQ1
AdcRegs.ADCTRL2.bit.SOC_SEQ1 = 1; // Start SEQ1
EDIS;
DELAY_US( ADC_usDELAY );
在pwm中断里里取adc值:
while (AdcRegs.ADCST.bit.INT_SEQ1== 0){}
AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1;
EPwm2Regs.ETCLR.bit.SOCA = 1;
ad1 = ((AdcRegs.ADCRESULT0)>>4 ;
ad2 = ((AdcRegs.ADCRESULT1)>>4 ;
ad3 = ((AdcRegs.ADCRESULT2)>>4);
请帮我解决纠错一下:多谢多谢!
Gang Li7:
回复 mangui zhang:
谢谢答复!能否给我完整的ADC采样代码?
我在学习28335控制电机,想用28335的adc的双通道ADCINA0,ADCINA1同时采样2相电流,用ADCINA2采样电池电压,不知如何配置寄存器?
如下是我的程序,
SysCtrlRegs.HISPCP.all = 0x0003; //AdcClock = SYSCLKOUT/6 = 25MHZ
EALLOW; // Enable EALLOW
SysCtrlRegs.PCLKCR0.bit.ADCENCLK = 1; // Enable SYSCLKOUT to ADC
ADC_cal();
EDIS; // Disable EALLOW
EALLOW;
// 设置ADC的参考电压源
AdcRegs.ADCREFSEL.all=0;
//ADC模块上电
AdcRegs.ADCTRL3.all = 0x00E0; // ADC power-up
AdcRegs.ADCTRL1.bit.ACQ_PS = 0; AdcRegs.ADCTRL3.bit.ADCCLKPS = 0;
AdcRegs.ADCTRL1.bit.SEQ_CASC = 1; // Setup cascaded sequencer mode
AdcRegs.ADCTRL1.bit.CONT_RUN = 1; // Setup continuous run
AdcRegs.ADCTRL1.bit.SEQ_OVRD = 0; // Enable Sequencer override feature
AdcRegs.ADCMAXCONV.all = 0x0002; // 3 double conv's (16 total)
AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x0; // Setup conv from ADCINA0
AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 0x1; // Setup conv from ADCINA1
AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 0x2; // Setup conv from ADCINA2
AdcRegs.ADCTRL2.bit.EPWM_SOCA_SEQ1 = 1; // Enable SOCA from ePWM to start SEQ1
// Start SEQ1
AdcRegs.ADCTRL2.bit.SOC_SEQ1 = 1; // Start SEQ1
EDIS;
DELAY_US( ADC_usDELAY );
在pwm中断里里取adc值:
while (AdcRegs.ADCST.bit.INT_SEQ1== 0){}
AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1;
EPwm2Regs.ETCLR.bit.SOCA = 1;
ad1 = ((AdcRegs.ADCRESULT0)>>4 ;
ad2 = ((AdcRegs.ADCRESULT1)>>4 ;
ad3 = ((AdcRegs.ADCRESULT2)>>4);
请帮我解决纠错一下:多谢多谢!
Lucy Alexender:
回复 Gang Li7:
参考ti的controlsuite里的A/Dsoc例程,各个芯片的都有