adel85
Joined: 17 May 2011 Posts: 1 Location: Mexico
|
PWM, induction Motor, with PIC18F1230 |
Posted: Tue May 17, 2011 12:42 pm |
|
|
HI, I'm new on the world of the pics and pwm too, i take the pic18f1230 because have 6 PWM outputs and i thinks i can control the speed of a induction motor, the problem is that i don't know how, I use an example of CCS and modify change the duty cycle of each pwm module with a for, but when i simulated the change of cycle is too slow, i put the code that i use. the example of CCS was with 18f2431 and only with one PWM output, the problem that i think i have is that i manipulate the 3 pwm modules like independent and i need to control a Full bridge of mosfets but i don't know how to program it. I appreciate your help and sorry by my english :S
Code: | #include <18F1230.h>
//#include <18f2431.h>
#device adc=10
//#fuses HS,NOWDT,NOPROTECT
#use delay(clock=20000000)
// #use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
void main()
{
long int adc_val, period,X,i,p;
period = 1024;
setup_power_pwm_pins(PWM_COMPLEMENTARY,PWM_COMPLEMENTARY,PWM_COMPLEMENTARY,PWM_OFF);
//PPWM channels 0 and 1 are both on and always opposite values
setup_power_pwm(PWM_FREE_RUN,1,0,period,0,1,0);
//add dead time for reactive loads
setup_adc_ports(AN0); //continuously sample and sync with PPWM
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(0);
while(true)
{
X = read_adc(); //connect to pot to adjust duty cycle
// X=adc_val;
for (i=1;i<4;++i)
{
if (i==1){
set_power_pwm0_duty(2047+X);
set_power_pwm2_duty(2047-X);
set_power_pwm4_duty(2047-X);
}
else if (i==2){
set_power_pwm0_duty(2047-X);
set_power_pwm2_duty(2047+X);
set_power_pwm4_duty(2047-X);
}
else {
set_power_pwm0_duty(2047-X);
set_power_pwm2_duty(2047-X);
set_power_pwm4_duty(2047+X);
}
}
//max duty cycle is (period+1)*4-1
//basically the same as max_adc * period/256
}
} |
|
|