Squirrels have fuzzy tails.
0 Members and 1 Guest are viewing this topic.
#include <16F877A.h>#device ADC=10#fuses HS,NOWDT,NOPROTECT,NOLVP#use delay(clock=20000000)#use rs232(baud=19200,xmit=PIN_C6,rcv=PIN_C7)#use fast_io(C)#use fast_io(D)#use fast_io(B)#org 0x1F00,0X1FFF {}#opt 9void ss_disp(int num) { byte const ssData[16]={123,80,103,117,92,61,63,120,127,125,126,31,7,87,47,46}; if(num<16) { output_c((SSData[num]&240)>>1); output_d(SSData[num]&15); };}void main () { long adval; set_tris_c(128); set_tris_d(0); set_tris_b(0b00111111); output_c(0); output_d(0); setup_ccp1(CCP_PWM); setup_timer_2(T2_DIV_BY_2,255,1); setup_port_a(AN0); setup_adc(ADC_CLOCK_DIV_2); set_adc_channel(0); while(TRUE) { delay_us(200); adval=read_ADC(); set_pwm1_duty(adval); ss_disp(adval>>6); if(input(pin_b1)) { if(input(pin_b0)) { output_high(pin_b7); output_low(pin_b6); } else if(!input(pin_b0)) { output_low(pin_b7); output_high(pin_b6); } } else if(!input(pin_b1)) { output_low(pin_b7); output_low(pin_b6); } }}
Go read the data sheet.Pay attention to Equation 11-1 and Table 11-1.
I'm confused....if the code didn't compile then how could the motor run?Have you looked at the PIC's PWM output on a scope?Did you run the code in a simulator or a debugger and see what the PWM frequency and duty cycle is?Is set_pwm1_duty(adval); expecting a value of type long?What value is the read_ADC() returning?You could have the RMW (Read-Modify-Write) issue on RB6 & 7. Check the data sheet section 4.1 and this thread on the Microchip support forum.http://www.microchip.com/forums/tm.aspx?m=287664&mpage=1&key=RMW񆎾