Hello! i made a psu with digital control by pic 16f886, i made the code and it worked great, until i wanted to put a rotary encoder as the controller.
i first did it with buttons and it worked great!, but when i implemented the encoder code, it started to beheave weird. the pwm doesnt respond as how it sould, like slow, and the lcd crashes and starts to show wierd characters. when i test the encoder code alone without the lcd and adc convertion, it works fine, the pwm increases and decreases as how it should, but when i put the lcd code back everything crashes as soon as i move the encoder, what is going on here? im usking mikro C and the frecuency is 16mhz
here is the code:
sbit LCD_RS at RB0_bit;
sbit LCD_EN at RB1_bit;
sbit LCD_D4 at RB2_bit;
sbit LCD_D5 at RB3_bit;
sbit LCD_D6 at RB4_bit;
sbit LCD_D7 at RB5_bit;
sbit LCD_RS_Direction at TRISB0_bit;
sbit LCD_EN_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB2_bit;
sbit LCD_D5_Direction at TRISB3_bit;
sbit LCD_D6_Direction at TRISB4_bit;
sbit LCD_D7_Direction at TRISB5_bit;
float duty;
float v;
char volt [12];
char amp [12];
float a;
void main() {
TRISA = 1;
PORTA = 0;
TRISB = 0;
TRISC = 0;
PORTC = 0;
C1ON_bit = 0;
C2ON_bit = 0;
ANSEL = 0b00000011;
ANSELH = 0;
PWM1_init(2000);
Pwm1_start();
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
duty = 0;
while(1){
if(ra2_bit == 1){
if(ra3_bit == 1){
duty = duty+10.66;
}
}
if(ra3_bit == 1){
if(ra2_bit == 1){
duty = duty-10.66;
}
}
v = adc_read(0)*0.02725;
a = adc_read(1)*7.35;
floatToStr(v,volt);
floatToStr(a,amp);
lcd_out(1,1,"V:");
lcd_out(1,4,volt);
lcd_out(2,1,"mA:");
lcd_out(2,4,amp);
pwm1_set_duty(duty);
}
}
thanks for your time