View previous topic :: View next topic |
Author |
Message |
Charles Francês
Joined: 29 Feb 2020 Posts: 7
|
Control motor brushless ccs c |
Posted: Sat Feb 29, 2020 3:01 pm |
|
|
Hello guys from CCS C How are you? I'm studying brushless motors and I'm having trouble understanding this code. Could someone explain to me how this code works on bldc motors with hall sensor? and if possible I would like to control your vocation!
I have a hard time understanding because I'm new.
Code: |
// Controle de motor BLDC detectado por CD-ROM com código CIC PIC16F877A CCS
//
#include <16F877A.h>
#fuses SH, NOWDT, NOPROTECT, NOLVP
#device ADC = 10
#use atraso (relógio = 8000000)
#use fast_io (B)
#use fast_io (D)
int8 hall;
int8 MoveTable[8] = {0, 33, 6, 36, 24, 9, 18, 0};
int16 value;
#INT_RB // RB port interrupt on change
void rb_isr(void){
hall = (input_b() >> 4) & 7;
output_d(MoveTable[hall]);
clear_interrupt(INT_RB);
}
void main(){
output_b(0); // PORTB initial state
set_tris_b(0xF3);
port_b_pullups(TRUE); // Enable PORTB internal pull-ups
output_d(0);
set_tris_d(0);
setup_adc(ADC_CLOCK_DIV_16); // Set ADC conversion time to 16Tosc
setup_adc_ports(AN0); // Configure AN0 as analog
set_adc_channel(0); // Select channel 0 input
setup_timer_2(T2_DIV_BY_16, 250, 1); // Set PWM frequency to 500Hz
setup_ccp1(CCP_OFF); // CCP1 OFF
enable_interrupts(GLOBAL);
delay_ms(100); // Wait 100ms
while(TRUE){
if(!input(PIN_B0)){ // If RB0 button pressed
if(input(PIN_B2)){ // Check if motor is already running
disable_interrupts(INT_RB);
output_d(0);
setup_ccp1(CCP_OFF); // CCP1 OFF
output_low(PIN_B2); // RB2 LED OFF
}
}
if(!input(PIN_B1)){ // If RB1 button pressed
if(!input(PIN_B2)){ // Check if motor is already running
output_high(PIN_B2); // RB2 LED ON
clear_interrupt(INT_RB); // Clear RB IOC flag bit
enable_interrupts(INT_RB); // Enable PORTB IOC
setup_ccp1(CCP_PWM); // Configure CCP1 as a PWM
hall = (input_b() >> 4) & 7;
output_d (MoveTable [hall]);
}
}
if (input (PIN_B2)) {
read_adc (ADC_START_ONLY);
while (! adc_done ()); // Aguarde até a conversão concluir o
valor = read_adc (ADC_READ_ONLY); // Leia o valor ADC
set_pwm1_duty (value); // Definir ciclo de trabalho PWM
}
}
} |
|
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9176 Location: Greensville,Ontario
|
|
Posted: Sat Feb 29, 2020 5:23 pm |
|
|
this is a problem...
valor = read_adc (ADC_READ_ONLY); // Leia o valor ADC
set_pwm1_duty (value); // Definir ciclo de trabalho PWM
I think 'valor' is 'vaue' in another language ?
I believe that's a 'stepper' motor that is being controlled by port D of the PIC. You need to decode which port pins are controlling the 4 winding and hopefully there is a transistor buffer between the PIC and the motor ! |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19375
|
|
Posted: Sun Mar 01, 2020 12:53 am |
|
|
and (of course), a 'stepper' motor, and a BLDC motor are very similar things.
The BLDC is analogous to a 3 phase stepper motor, where the PWM being
fed to the phases is modulated to give a smooth motion instead of moving
in 'steps'. They are optimised for smooth motion, instead of step 'accuracy'.
The waveforms required are very similar. You can actually drive a
BLDC like a stepper, and a stepper like a BLDC. However efficiency will
plummet..... |
|
![](templates/subSilver/images/spacer.gif) |
Charles Francês
Joined: 29 Feb 2020 Posts: 7
|
|
Posted: Sun Mar 01, 2020 10:07 am |
|
|
Thanks! Charles |
|
![](templates/subSilver/images/spacer.gif) |
|