完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
电子发烧友论坛|
您好,我有AN8 POLEBDCM和3个霍尔效应位置传感器在定子上,它们彼此间隔120度,霍尔效应的分辨率为15度。因此,需要6个换向状态来实现一个电循环。4个电循环相当于一个完整的旋转。我已经成功地通过配置6个状态切换来实现对速度的控制,这实现了梯形换流。我想知道是否已经使用了一个霍尔效应传感器来测量转子的速度。我基本上希望能够读取一个传感器的速度,并通过UART发送它来显示一个RPM值。这意味着PIC来计算16位值,然后它可以被转换成正确的速度。我对PIC的编程是比较新的,但是我在不断地开发和建立更多的知识。我不太确定如何测量霍尔传感器的速度以实现输出。是否有任何代码示例说明如何实现这一点?我当前代码的一个例子如下:
以上来自于百度翻译 以下为原文 Hello, I have an 8-pole BDCM with 3 Hall-effect position sensors stationed on across the stator which are 120 degrees apart from each other. The resolution of the Hall-effect sensors is 15 degrees. So it takes 6 commutation states to achieve one electrical cycle. 4 electrical cycles equate to one full revolution. I have managed to achieve control of the speed by configuring 6 state switching which achieves trapezoidal commutation. I was wondering if any techniques have been achieved to measure the speed of the rotor using one of the hall effect sensors. I basically want to be able to read the speed of one sensor and send it over UART to display an RPM value. I need the PIC to compute the 16-bit value which can then be converted to the right speed. I am relatively new to programming PIC's but I am continually developing and building more knowledge. I wasn't quite sure how to tackle measuring the Hall-sensors speed in order to achieve an output. Are there any code examples of how this can be achieved? An example of my current code is below: halla= PORTDbits.RD0; /* Input Port register that reads Hall Sensor Blue Wire */ hallb = PORTDbits.RD1; /* Input Port register that reads Hall Sensor Green Wire */ hallc = PORTEbits.RE8; /* Input Port register that reads Hall Sensor White Wire */ /* define angle variable for 6 states of hall effect sensor positioning */ if (halla == 1 && hallb == 1 && hallc == 0) { angles = 0; a = 1 + b; } if (halla == 1 && hallb == 0 && hallc == 0) { angles = 15; b = 1 + c; } if (halla == 1 && hallb == 0 && hallc == 1) { angles = 30; c = 1 + d; } if (halla == 0 && hallb == 0 && hallc == 1) { angles = 45; d = 1 + e; } if (halla == 0 && hallb == 1 && hallc == 1) { angles = 60; e = 1 + f; } if (halla == 0 && hallb == 1 && hallc == 0) { angles = 75; f = 1 + a; } void InitADC(void) { /* Tcy=67.8ns, ADCS=7, Tad=(67.8ns x 8)/2 = 271.37ns */ TRISBbits.TRISB4 = 1; /* Port B4 (AN4) is input */ ADPCFGbits.PCFG4 = 0; /* Port B4 is analogue mode */ TRISBbits.TRISB3 = 1; /* Port B3 (AN3) is input */ ADPCFGbits.PCFG3 = 0; /* Port B3 is analogue mode */ TRISBbits.TRISB2 = 1; /* Port B2 (AN2) is input */ ADPCFGbits.PCFG2 = 0; /* Port B2 is analogue mode */ TRISBbits.TRISB1 = 1; /* Port B1 (AN1) is input */ ADPCFGbits.PCFG1 = 0; /* Port B1 is analogue mode */ TRISBbits.TRISB0 = 1; /* Port B0 (AN0) is input */ ADPCFGbits.PCFG0 = 0; /* Port B0 is analogue mode */ ADCON3bits.SAMC = 1; /* 1TAD */ ADCON3bits.ADCS = 7; /* Clock conversion bits @ x8 PLL */ ADCON2bits.VCFG = 0; /* Voltage reference source Avdd, Avss */ ADCON2bits.CHPS = 2; /* CH0, CH1, CH2, CH3 */ ADCON2bits.BUFM = 0; /* one word buffer */ ADCON2bits.ALTS = 0; /* mux a only */ ADCON2bits.CSCNA = 0; /* do not scan inputs */ ADCON2bits.SMPI = 0; /* interrupt on 1st sample */ ADCHSbits.CH0SA = 4; /* channel 0 positive input is AN4 */ ADCHSbits.CH0NA = 0; /* channel 0 negative input is vref- */ ADCHSbits.CH123SA = 0; /* 1=AN0(CA0), 2=AN1(CL1), 3=AN2(CL2) */ ADCHSbits.CH123NA = 0; /* CH1, CH2, CH3 negative input is vref- */ ADCON1bits.SIMSAM = 1; /* simultaneous sample */ ADCON1bits.FORM = 0; /* integer output */ ADCON1bits.SSRC = 3; /* motor control PWM triggers conversion */ ADCON1bits.ASAM = 1; /* Sampling auto-start on */ IPC2bits.ADIP = 4; /* ADC interrupt priority 4 (1=lowest) */ IFS0bits.ADIF = 0; /* clear ADC int status flag */ IEC0bits.ADIE = 1; /* enable ADC int */ ADCON1bits.ADON = 1; /* turn ADC on */ } void InitUART(void) { U1BRG = 47; /* 19200 baud @ x8 PLL */ U1MODEbits.STSEL = 0; /* 1 stop bit */ U1MODEbits.PDSEL = 00; /* 8 data bits, no parity */ U1MODEbits.ALTIO = 1; /* Alternate I/O used */ IPC2bits.U1RXIP = 1; /* uart 1 rx interrupt priority 1 (1=lowest) */ IFS0bits.U1RXIF = 0; /* clear uart 1 rx int status flag */ IEC0bits.U1RXIE = 1; /* enable uart 1 rx int */ U1STAbits.URXISEL = 1; /* Rx interrupt enabled when character received */ U1MODEbits.UARTEN = 1; /* Uart enabled */ U1STAbits.UTXEN = 1; /* TX enabled */ } void InitPWM(void) { /* 6 PWM channels used in 3 complimentary pairs */ PTPER = 73; /* 368 set for 20kHz (50us) PWM period, 737 set for 10Khz (100uS) PWM period, up/down mode (x 8 PLL) */ SEVTCMPbits.SEVTCMP = 0; /* Special Event Compare */ SEVTCMPbits.SEVTDIR = 1; /* Special Event Direction (countdown) */ PTCONbits.PTMOD = 2; /* up/down counting mode */ PWMCON2bits.SEVOPS = 0; /* PWM special event trigger postscale (trigger for ADC conversion) */ PWMCON1bits.PEN1H = 1; /* 1H pin enabled */ PWMCON1bits.PEN1L = 1; /* 1L pin enabled */ PWMCON1bits.PEN2H = 1; /* 2H pin enabled */ PWMCON1bits.PEN2L = 1; /* 2L pin enabled */ PWMCON1bits.PEN3H = 1; /* 3H pin enabled */ PWMCON1bits.PEN3L = 1; /* 3L pin enabled */ PTCONbits.PTEN = 1; /* PWM timebase is ON */ } void InitPORT(void) { TRISBbits.TRISB4 = 1; /* set input for pot */ ADPCFGbits.PCFG4 = 0; /* AN4/RB4 to analog mode (is by default anyway) */ TRISBbits.TRISB5 = 0; /* set as output for ISR test */ //TRISBbits.TRISB5 = 1; /* set as input for switch button functionality on FIB */ ADPCFGbits.PCFG5 = 1; /* AN5/RB5 to digital mode as by default it is set to analog */ TRISCbits.TRISC15 = 1; /* set input for nFAULT */ TRISDbits.TRISD0 = 1; /* set input for H2 (Green Hall Sensor) */ TRISDbits.TRISD1 = 1; /* set input for H3 (White Hall Sensor) */ TRISEbits.TRISE8 = 1; /* set input for H1 (Blue Hall Sensor) */ TRISEbits.TRISE8 = 1; /* set input for H1 (Blue Hall Sensor) */ } void InitCAPTURE(void) { IC1CONbits.ICM = 0; /* turn off capture module */ IC1CONbits.ICTMR = 0; /* use timer 3 */ IC1CONbits.ICI = 1; /* interrupt on every 2nd capture */ IC1CONbits.ICM = 2; /* capture every falling edge on IC1 */ IPC0bits.IC1IP = 3; /* IC1 interrupt priority 3 (1=lowest) */ IFS0bits.IC1IF = 0; /* clear IC1 int status flag */ IEC0bits.IC1IE = 1; /* enable IC1 int */ } void InitTimer1(void) { /* Timer 1 (Type-A) used to generate interrupt every 0.284 seconds for UART TX Where interrupt time = Tcy x prescale x period reg Tcy = 1 / (Fcy/4) x 8 (x8 PLL) e.g. 0.284seconds = 67.8ns x 64 x 65535 */ TMR1 = 0x0000; /* clear timer register */ PR1 = 0xffff; /* load period register */ IPC0bits.T1IP = 2; /* timer 1 interrupt priority 2 (1=lowest) */ IFS0bits.T1IF = 0; /* clear timer 1 int status flag */ IEC0bits.T1IE = 1; /* enable timer 1 int */ T1CONbits.TCKPS = 2; /* 1:64 prescale */ T1CONbits.TON = 1; /* start timer 1 */ } void InitTimer3(void) { /* Timer 3 (Type-C) used by Input Capture Port 1 Where time = Tcy x prescale Tcy = 1 / (Fcy/4) x 8 (x8 PLL) e.g. 67.8ns = 67.8ns x 1 */ TMR3 = 0x0000; /* clear timer register */ PR3 = 0xffff; /* load period register */ T3CONbits.TCKPS = 0; /* 1:1 prescale */ T3CONbits.TON = 1; /* start timer 3 */ } void InitInterrupts(void) /* Added code */ { IPC0 = 0x1000; /* Timer 1 Interrupt = Priority 1 (low) */ IPC2 = 0x6450; /* Analogue to Digital = 6, Serial Transmit = 4, Receive = 5; */ IPC9 = 0x7000; /* PWM = = 7 (highest priority) */ /* Turn on the desired Interrupts */ IEC2bits.PWMIE = 1; /* PWM interrupt */ IEC0bits.ADIE = 1; /* A/D interrupt */ IEC0bits.T1IE = 1; /* enable timer 1 int */ IEC0bits.T2IE = 1; /* enable timer 2 int */ } |
|
相关推荐
2个回答
|
|
|
嗯,BDCM?描述听起来有点像无刷直流电动机,也许更像是描述了无刷直流电动机,这样的电动机可能在转子中有永磁体,或者可以是一个类似于鼠笼式电动机的感应电动机。如果有永磁体,那么它是一个同步电动机,而不是真的NE。通过霍尔效应传感器来了解RPM,您可以只计算已经执行的换向次数。霍尔效应传感器本身是一个需要偏置电流和模拟信号处理的模拟设备。这可能是,或者可能不与传感器芯片集成在电机中。用示波器或伏特计观察传感器发出的信号?如果它是一个干净的数字信号,你可以把它输入一个数字输入引脚并计数脉冲。如果它是一个小的模拟信号,你可以把它馈送到一个模拟比较器,但是在你的微控制器中没有这样的IN,然后在计数器模式中使用一个定时器。或者将模拟信号连接到ADC。如果没有信号,你可能需要给传感器供电或偏置电流,可能需要一个运算放大器来对信号进行整形。然后将信号输入到一个定时器输入。通过这样的信号,您将能够检查电机实际上是根据换向运行的。如果不是,电机可能已经停顿并失去同步。这种霍尔传感器已经与原始驱动电子设备一起使用。电机,以了解正确的换向时机。您可以使用这些信号连同换向控制,以了解电机是否落后,需要更多的驱动电流,或者如果它运行轻,并可能能够跟上更少的驱动器或加速,如果需要的话。迈西尔
以上来自于百度翻译 以下为原文 Hmm, BDCM? description sound somewhat like Brushless DC Motor, maybe more commonly be described like BLDC Motor. Such a motor may have permanent magnets in the rotor, or may be an induction motor like a squirrel cage motor. If there are permanent magnets, then it is a synchronous motor, and you do not really need the Hall effect sensors to know the RPM, you may just count the number of commutations that have been performed. The Hall effect sensor itself, is a analog device that need some bias current and analog signal processing. This may, or may not be integrated with the sensor chip in the motor. Do you have oscilloscope or voltmeter to observe the signal from the sensor? If it is a clean digital signal, you may feed it to a digital input pin and count the pulses. If it is a small analog signal, you may feed it to a Analog comparator, but there are no such in in your microcontroller, and then to a Timer to be used in Counter mode. Or connect the analog signal to a ADC input, and sample it there If there is no signal, you may need to feed power or bias current to the sensor, and maybe need a Operation Amplifier to shape the signal. Then feed the signal to a Timer input. With such a signal you will be able to check that the motor is actually running according to the commutations. If Not, the motor may have stalled and lost synchronization. Such hall sensors have been used in connection with the original drive electronics for the motor, to know the correct timing for commutations. You may use these signals together with your commutation control, to know if the motor is lagging behind, and need more drive current, or if it is running lightly, and may be able to keep up with less drive or accelerate if that is wanted. Mysil |
|
|
|
|
|
Mysil,是的,它是一个无刷直流电机,具有六个可能的霍尔传感器状态,并提供一个干净的数字信号输入到PIC。机械角度霍尔传感器,霍尔传感器B霍尔传感器C 0°- 15°1,0,1°15°-30°10 0 0 30°-45°45°°°,°°°α=α°°。TH极= 0(0V数字低),我试图计数时钟周期上升和下降的一个霍尔传感器的边缘。我的代码当前使用:我正在尝试从计数器中获得一个计数值,用于IC1BUF的下降和上升沿。我曾尝试使用无符号整数实现这一点。所描述的代码不适用于在范围内测量的值,并且该值作为无符号整数超载——不可能在源代码中声明变量AS静默UIT32或静态UTI16吗?Test= 67.8NS
以上来自于百度翻译 以下为原文 Hi Mysil, Yes it is a Brushless DC motor with six possible Hall-sensor states and provides a clean digital signal input to PIC. Mechanical Angle Hall-sensor A Hall-sensor B Hall-sensor C 0°-15° 1 0 1 15°-30° 1 0 0 30°-45° 1 1 0 45°-60° 0 1 1 75°-90° 0 0 1 North Pole = 1 (5V digital high) South Pole = 0 (0V digital low) I am trying to count the clock cycles on the rising and falling edge of one of the Hall sensors. My code is currently using: void _ISR _IC1Interrupt(void) { /* This function services the Input Capture Port 1 (IC1) interrupt. Timer 3 value is stored on every falling edge presented to IC1. The time difference is then calculated between the time of the first falling edge and the time of the second falling edge. This time difference represents the pulse period of the Hall-effect Position Sensors from which the rpm of the motor can be calculated. */ unsigned int t2, t1; t1 = IC1BUF; /* get 1st falling edge time from FIFO */ t2 = IC1BUF; /* get 2nd falling edge time from FIFO */ if(t2 > t1) rpm = t2 - t1; else rpm = (PR3 - t1) + t2; IFS0bits.IC1IF = 0; /* clear IC1 int status flag */ } I am trying to achieve a count value from the counter for the falling and rising edge of IC1BUF. I have tried achieving this using an unsigned integer. The code described does not work against what is measured in the scope and the value overruns as an unsigned integer - Is it not possible to declare the variable as static uint32 or static uint16 in source code? Tcy = 67.8ns |
|
|
|
|
只有小组成员才能发言,加入小组>>
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
503 浏览 0 评论
5812 浏览 9 评论
2350 浏览 8 评论
2237 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3544 浏览 3 评论
1161浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
1122浏览 1评论
我是Microchip 的代理商,有PIC16F1829T-I/SS 技术问题可以咨询我,微信:A-chip-Ti
890浏览 1评论
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
508浏览 0评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-14 12:52 , Processed in 0.788603 second(s), Total 75, Slave 59 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
4407