This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] MSP430FR2355:从SAC内部驱动ADC信道,同时使用相关引脚进行I/O

Guru**** 654100 points
Other Parts Discussed in Thread: MSP430FR2355
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/1089034/msp430fr2355-internally-drive-adc-channel-from-sac-whilst-at-same-time-using-associated-pin-for-i-o

部件号:MSP430FR2355

有关SA如何与ADC输入互连的文档似乎不完整或至少令人困惑!

请参阅6.10 17交叉芯片互联(msp430fr2355.pdf的第83页),
我们看到SAC0 OA输出(OA0O)在绘图左侧显示一个带有X的正方形。
该处被标记为1.1 ,OA0O,0.1 ,A1

6.11 1端口P1输入/输出(同一文档的第95页)在左上角显示一行(到或从?) ... A1,... OA...,COMP0...和端口P1引脚。

以下第96页建议将“OA0O,0.1 ,A1”的P1SELx设置为11。
在同一页上,它指出,如果要将WFP的1.1 用于I/O,则P1SELx应设置为0 (大概是此处为00?),同时设置P1DIR以定义输入还是输出。

文件没有表明可以同时将输出内部路由到A1,同时使用WFP 1.1 进行I/O操作!
同样,它也没有指明如果确实可能的话,P1SELx和P1DIR的适当设置是什么(因为我的实验似乎表明是这样)。

我的目标是使用SAC0 (例如,在相关引脚上有一个输入信号,即WFP 1.2 和WFP 1.3),将输出路由到内部A1,以测量信号。
同时,我想将WFP插脚1.1 用于其他目的,即I/O
(这样就可以获得一个'免费'的额外引脚! 我的设计缺少针脚...)

(SAC1的输出可以在内部路由到A5,这同样适用于SAC1。)

我已使用以下代码或多或少地回答了我自己的问题。

对于"OA0O,0.1 ,A1",我将P1SELx设置为11。

我不使用P1DIR做任何事情-因此它的默认值为0,即引脚1.1 在理论上是输入。
尽管如此,我还是能够驱动代码中的针脚H和L来使LED闪烁!

因此,虽然我可能已经用“是的,这似乎是可能的”回答了我的问题,但我有一些担心,我可能会以某种方式滥用MSP430?

可能是使用了WFP 1.1 作为输出(尽管P1DIR为0!) 是否会对其驱动器功能产生影响?
或者是否会对A1产生影响(换用WFP 1.1 时产生的噪音峰值等)?

我还测试了P1DIR,如我的评论所述:
;无论是否使用以下行,功能都是相同的!!!
;BIS.b #BIT1,&P1DIR; WFP 1.1 作为输出(用于驱动外部LED)

我还没有测试过是否可以将WFP 1.1 用作输入。
(假设如果可以,P1DIR将保持其默认设置0?)
[是否与P1OUT和P1IN发生冲突?!!]

总之,请检查我所做的事情是否正常,而不会导致任何潜在的问题...
(对驱动器功能的影响,P1OUT和P1IN之间的冲突,对ADC转换性能的影响...?)

此外,请考虑改进相关文档。

这是我的代码,用于尝试调查正在发生的情况:

SAC0生成一个斜坡信号,该信号在内部路由到A1。
启动板上的绿色和红色LED指示信号测量值分别低于或高于2V。
在主环路中,我会闪存一个由WFP 1.1 驱动的外部LED指示灯,以证明当SAC0驱动ADC的A1时,该引脚可用于输出。

;-------------------------------------------------------------------------------
;
;  Attempt to use P1.1 for I/O at same time as SAC OA0O drives A1 ADC
;  Starting point was: (my project Asm_SAC_L3_05)
;  MSP430FR235x Demo - SAC-L3, DAC Buffer Mode
;
;  Description: Configure SAC-L3 for DAC Buffer Mode.
;  Use the 12 bit DAC to output positive ramp.
;  The OA is set in buffer mode to improve DAC output drive strength.
;  Internal 2.5V reference is selected as DAC reference.
;  Observe the output of OA0O pin with oscilloscope.
;  ACLK = n/a, MCLK = SMCLK = default DCODIV ~1MHz.
;
;  Note: period of ramp measures as 504.5 msec (need to check SMCLK freq. and study the timer theory!)
;
;                MSP430FR235x
;             -------------------
;         /|\|                   |
;          | |                   |
;          --|RST     DAC12->OA0O|--> oscilloscope
;            |                   |
;            |                   |
;            |                   |
;            |                   |
;            |                   |
;
;   Darren Lu, TI
;   + own additions ...
;
;-------------------------------------------------------------------------------
            .cdecls C,LIST,"msp430.h"       ; Include device header file
            
;-------------------------------------------------------------------------------
            .def    RESET                   ; Export program entry-point to
                                            ; make it known to linker.
;-------------------------------------------------------------------------------
            .text                           ; Assemble into program memory.
            .retain                         ; Override ELF conditional linking
                                            ; and retain current section.
            .retainrefs                     ; And retain any sections that have
                                            ; references to current section.

            .global	ADC_Value				; This is necessary to have ADC_Value recognised in the Expressions window!
			.data
			.bss ADC_Value, 2
			.text

;-------------------------------------------------------------------------------
RESET       mov.w   #__STACK_END,SP         ; Initialiwe stackpointer
StopWDT     mov.w   #WDTPW|WDTHOLD,&WDTCTL  ; Stop watchdog timer

            ; Disable the GPIO power-on default high-impedance mode
            ; to activate previously configured port settings
            bic.w   #LOCKLPM5,&PM5CTL0      ; (Turn off digital I/O)

            mov.b   #PMMPW_H,&PMMCTL0_H     ; Unlock the PMM registers
            mov.w   #INTREFEN+REFVSEL_2,&PMMCTL2; Enable internal 2.5V reference
PollRef     bit.w   #REFGENRDY,&PMMCTL2     ; Poll till internal reference settles
            jz      PollRef                 ;

; Despite the following settings for P1SEL0 and P1SEL1, I am still also able to use P1.1 as an independent output!
SetPin      bis.b   #BIT1,&P1SEL0           ; Select P1.1 as OA0O function
            bis.b   #BIT1,&P1SEL1           ; OA is used as buffer for DAC.

            mov.w   #DACSREF_1+DACLSEL_2+DACIE,&SAC0DAC; Select (2.5V, defined above) int Vref as DAC ref,
            								; DAC always loads data from DACDAT at the +ve edge of TB2.1B signal,
            								; Enable DAC interrupt
            ;mov.w   #0,R13
            ;clr.w   R13
            ;mov.w   R13,&SAC0DAT            ; Initial DAC data
            clr.w   &SAC0DAT                ; Initial DAC data=0 (DHBR simplification not involving use of R13)
            bis.w   #DACEN,&SAC0DAC         ; Enable DAC

            mov.w   #NMUXEN+PMUXEN+PSEL_1+NSEL_1,&SAC0OA; Enable negative (follower) and positive (DAC) input
            bis.w   #OAPM,&SAC0OA           ; Select low speed and low power mode
            mov.w   #MSEL_1,&SAC0PGA        ; Set OA as buffer mode
            bis.w   #SACEN+OAEN,&SAC0OA     ; Enable SAC and OA

            ; Use TB2.1B as DAC hardware trigger
            mov.w   #0x63,&TB2CCR0          ; PWM Period/2
            mov.w   #OUTMOD_6,&TB2CCTL1;    ; TBCCR1 toggle/set
            mov.w   #0x32,&TB2CCR1          ; TBCCR1 PWM duty cycle
            mov.w   #TBSSEL__SMCLK+MC_1+TBCLR,&TB2CTL ; SMCLK, up mode, clear TB2R

; -- Configure ports for LEDs (based on code from Asm_ADC_Sampling_P1.2_LPM)
			;bic.b	#BIT0, &P1OUT           ; LED1 (red) = 0 (Off)
			bis.b	#BIT0, &P1DIR			; Configure LED1 (red) as output
			;bic.b	#BIT6, &P6OUT           ; LED2 (green) = 0 (Off)
			bis.b	#BIT6, &P6DIR			; Configure LED2 (green) as output

			; Functionality is the same whether or not following line is used!!!
			;bis.b	#BIT1, &P1DIR			; P1.1 as output (to drive external LED)

 			bic.b	#LOCKLPM5, &PM5CTL0		; Turn on digital I/O

; -- setup ADC (based on code from Asm_ADC_Sampling_P1.2_LPM)
           	bic.w	#ADCSHT0, &ADCCTL0		; Clear bit 0 (bit 8 of register) of default ADCSHT=01
			bis.w	#ADCSHT1, &ADCCTL0		; Conversion = 16 ADCCLK cycles (0010b)
			;mov.w   #ADCSHT_2|ADCON, &ADCCTL0 ; Conversion = 16 ADCCLK cycles (0010b).  Hao uses instead of the above two lines.
			bis.w	#ADCON, &ADCCTL0		; Turn ADC on

			bis.w	#ADCSSEL_3, &ADCCTL1	; ADC clock signal = SMCLK (1MHz).  Hao uses the default MODOSC (MODCLK).  msp430fr2355 page 68: 3.8MHz +/- 21%
			bis.w	#ADCSHP_1, &ADCCTL1		; SAMPCON signal is sourced from the sampling timer

			bic.w	#ADCRES0, &ADCCTL2		;
			bis.w	#ADCRES_2, &ADCCTL2		; Resolution = 12-bit (ADRED=10)

			bis.w	#ADCINCH_1, &ADCMCTL0	; ADC input channel A1 (P1.1) (hoping to be able to use P1.1 also for I/O?!)

			bis.w	#ADCIE0, &ADCIE			; Enable ADC conversion complete IRQ

			bis.w	#ADCENC|ADCSC, &ADCCTL0 ; Enable and start ADC conversion

            ;nop
            ;bis.w   #LPM3+GIE,SR            ; Enter LPM3, Enable Interrupt  For Lu (and here) code will sit here, with interrupts continuing to be serviced.
            ;nop

            nop
            bis.w   #GIE,SR            		; Enable global interrupts
            nop

main:
			bis.w   #LPM3,SR            	; Enter LPM3

			bis.w	#ADCENC|ADCSC, &ADCCTL0 ; Enable and start ADC conversion

			clr.w	R4
DelayLoop   inc.w	R4				; Based on Davies page 95 (approx 0.7 sec)
			cmp.w   #50000,R4
			jne		DelayLoop
            xor.b	#BIT1, &P1OUT   ; toggle LED


			jmp		main

;-------------------------------------------------------------------------------
; ISR for SAC0 (note that shares same vector as for SAC2)
;-------------------------------------------------------------------------------
SAC0_ISR:   add.w   &SAC0IV,PC
            reti                            ; Vector  0: No interrupt
            reti                            ; Vector  2: (reserved)
            ;jmp     SACDACMODE              ; Vector  4: SAC DAC Interrupt (other vectors are reserved)
;SACDACMODE
			;add.w  #1,R13                   ;
            ;and.w  #0xFFF,R13               ;
            ;mov.w  R13,&SAC0DAT             ; DAC12 output positive ramp
            inc.w  &SAC0DAT					; DAC12 output positive ramp (DHBR simplification not involving use of R13)
            bic.w	#LPM3, 0(SP)			; Cancel LPM3 on exit. i.e., return to active mode
            reti


; Code would be more robust if check ADCIV register.
; There could be other interrupts for overflows, etc.
; Hao code does this.  Note that, with his code, other types of interrupt will not result in exit from LPM0.  That is okay/ correct!
ADC_ISR:
            ;mov.w   &ADCIV, PC				; Add offset to PC and clear the associated interrupt
            ; ...
			mov.w   &ADCMEM0, ADC_Value     ; No need for own variable!  Could use &ADCMEM0 in following (but would flag be cleared?)!  Or R4.
			;mov.w   &ADCMEM0, R4
			cmp.w   #2482, ADC_Value
			;cmp.w   #1000, ADC_Value
			;cmp.w   #1000, R4
			jhs     ge2V
		    bic.b	#BIT0, &P1OUT			; For A2 < 2V: LED1 (red) OFF
		    bis.b	#BIT6, &P6OUT			; 			   LED2 (green) ON
			jmp		ADC_ISR_end
ge2V:		bis.b	#BIT0, &P1OUT			; For A2 >= 2V: LED1 (red) ON
		    bic.b	#BIT6, &P6OUT			; 				LED2 (green) OFF
ADC_ISR_end:
			;;bic.w	#CPUOFF, SR         	; For video 15.2(d).  Exit LPM0 on return.  bic.w	#CPUOFF, 0(SR) used by Hao in 12976 code.
;			bic.w	#CPUOFF, 0(SP)          ; As used by Hao in 12976 code.  Refer also Davies page 203 to 205.
			;bic.w	#LPM0, 0(SP)          ; (same as #CPMOFF)
			reti

;-------------------------------------------------------------------------------
; Stack Pointer definition
;-------------------------------------------------------------------------------
            .global __STACK_END
            .sect   .stack
            
;-------------------------------------------------------------------------------
; Interrupt Vectors
;-------------------------------------------------------------------------------
            .sect   ".reset"                ; MSP430 RESET Vector
            ;.sect   RESET_VECTOR            ; Variant used by Lu
            .short  RESET
            
            ;.sect   SAC0_SAC2_VECTOR  ; Lu (this is the C definition)
            .sect   ".int27"		  ; LaMeres
            .short  SAC0_ISR

			.sect   ".int29"
			.short	ADC_ISR

            .end

非常感谢您的帮助!

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    另一种/附加原理图可在数据表(SLASEC4D)图6-4中找到,这更清楚地表明,模拟(OA/ADC/COMP)始终可以看到引脚- PSEL位不会对信号进行门控。

    PSEL=3做的最重要的事情是关闭施密特触发器。 只要它们处于啮合状态,您的所有ADC都将看到0或0xFFF。

    因此,您可以将引脚同时用作GPIO (PSEL=0),但您的模拟输入将会无聊。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好,Bruce:

    您写道:
    >因此,您可以将引脚同时用作GPIO (PSEL=0),但模拟输入将会无聊。

    但我的示例代码表明,生成0到2.5V斜坡信号的DAC (SAC0的)正在到达ADC A1,因此它不是“无聊”!
    ADC ISR测试的电压大于2V;与启动板上的绿色LED相比,红色LED指示灯亮起的时间相对较长,在测试电压为2V的0至2.5V斜坡上也是如此。
    请注意,SAC0仅用于缓冲DAC -不存在对WFP 1.2 或WFP 1.3 的模拟输入。
    在我的实际申请中,我会将WFP 1.2 和/或WFP 1.3 作为OA的输入,然后作为A1的缓冲区。

    无论P1DIR的第1位设置为H还是L,都将出现上述情况
    对于这两种情况,我还可以同时驱动WFP 1.1 上的外部LED,同时A1接收来自SAC0的DAC的非镗孔信号(通过其输出OA0O)。

    我正在使用PSEL=3进行所有测试。 我没有尝试PSEL=0,大概这只允许使用WFP 1.1 来进行I/O

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好Douglas:

    对于具有智能模拟组合(SAC)的设备,与ADC的连接是内部连接,但它们使用引脚进行此类连接。 因此,尽管您不必将两个引脚的输出路由在一起,但它仍然占用单个引脚资源。

    因此,例如,如果要按照交叉芯片连接图中的指示将SAC0的输出连接到ADC通道A1,则需要为相应的模拟模式设置引脚。 这样,销钉就不能用于其他功能,也不应在外部驱动/影响,否则会影响您的结果。

    请参阅以下代码示例,该示例演示了如何使用两个SAC作为 多级放大器至ADC输入。 https://dev.ti.com/tirex/explore/node?node=AK6ZWSA8R1sxWtrY6VvbVg__IOGqZri__LATEST 

    详情请参阅以下网页: https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/71.0384万/msp430fr2355-sac-internal-external-routing</s>2355 

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好,Jace:

    我已经研究过msp430fr2355-sac-internall-external线程,并同意该线程中的所有内容。

    您写道:
    >...但他们使用PIN来建立这样的连接。
    >因此,虽然您不必将两个引脚的输出路由在一起,但它仍然占用单个引脚资源。

    我的示例似乎是'活的证据',表明引脚未被占用-我的代码能够驱动引脚1.1 H或L (切换外部LED),同时A1读取来自SAC0输出的输入。

    [...这样做是否"会影响您的结果"是我的问题/疑虑的一个方面!]

    顺便说一下,我的ISR中的注释错误地显示A2 -应为A1。 (代码中未使用A2。)

    我没有研究您提到的示例代码-但希望在第二天或第二天学习。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好Douglas:

    在ISR中时,您应该仔细检查P1SL位的寄存器设置。 (寄存器的调试视图)理论上,您可以对输出功能或模拟输入传感之间的引脚的使用进行时间分片,但从应用角度来看,这一点不是很推荐,因为它可能会影响/扭曲模拟读数。 您可能会遇到输入/输出冲突,或您已经描述的一些噪音问题。  

    如数据表中的表6-63所示,设置引脚用于模拟功能,并能够同时将其用作GPIO是不可能的。 如果您以某种方式实现此目标,则这不是此零件的预期配置或设计。 因此,您超出了引脚配置的规格,无法保证数据表参数。  

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    我已详细研究过这个问题,现在发觉我混淆了'原因和影响':-(

    "my code is able to drive the pin 1.1 H or L (toggling an external LED)춬 时A1读取SAC0输出的输入"语句不正确。
    这是不可能的。

    我以为我的XOR.b #BIT1,&P1OUT正在切换外部LED指示灯(连接到WFP 1.1)。
    但是,实际上是SAC0的DAC发出的斜坡信号导致LED指示灯在视觉上显示为闪烁。
    实际上,LED仅监控发送至A1的信号(在该过程中略高于额定1mA输出!)。

    bis.b #BIT1,&P1OUT或bis.b #BIT1,&P1OUT也会出现相同的情况;换句话说,不能将端口用于I/O

    这大概意味着不应该与WFP 1.1 连接。

    非常感谢您的帮助。