shredder001
New Member
Hello! This is my first post. I am currently planning to be able to control a motor from a PWM input. Since I am very new to C programing, I am going in steps at a time and using LED's to test. Here is what I have so far:
#include <pic.h>
__CONFIG(FCMDIS & IESODIS & INTIO & MCLRDIS & WDTDIS & UNPROTECT);
//Initialize
unsigned char TIMER_COUNT_LOW; // Holding register for TMR0 low byte
unsigned char TIMER_COUNT_HIGH; // Holding register for TMR0 high byte
main()
{
OSCCON = 0b00000001; // Internal oscillator for system clock
PORTC = 0x00;
CMCON0 = 0b00000111;
ANSEL = 0x00;
TRISC = 0b00111100;
PR2 = 0b11111111; //Set the PWM period by loading the PR2 register
CCPR1L = 0x00;
T2CON = 0b01011000;
TMR2IF = 0; //clear bit for timer2 module interupt flag
while(TMR2IF == 0) //Wait until timer2 overflows then continue
{
;
}
TRISC = 0x00;
ECCPASE = 1; // for future part of program
PORTA = 0x00;
CMCON0 = 0b00000111; // comperators off
ANSEL = 0x00; //digital
TRISA = 0b00101000;
T1CON = 0b00010101;
while(1==1) // Start MainLoop
{
while(RA5 == 1) //Wait until RA5 goes low then continue
{
;
}
while(RA5 == 0) //Wait until RA5 goes high then continue
{
;
}
TMR1H = 0x00;
TMR1L = 0x00;
while(RA5 == 1) //Wait until RA5 goes low again
{
;
}
PORTC = TMR1L;
}
}
It starts timer1, then waits untill a low signal on RA5 (PWM input), then a high one, then it initializes timer1 and wait for a low signal. imediatly after that, it puts the timer1 value into a variable and the displays it on PORTC (LED array). I compiled and programmed it succesfully, but it does not seem to be displaying the value, any thoughts? Thanks!!
#include <pic.h>
__CONFIG(FCMDIS & IESODIS & INTIO & MCLRDIS & WDTDIS & UNPROTECT);
//Initialize
unsigned char TIMER_COUNT_LOW; // Holding register for TMR0 low byte
unsigned char TIMER_COUNT_HIGH; // Holding register for TMR0 high byte
main()
{
OSCCON = 0b00000001; // Internal oscillator for system clock
PORTC = 0x00;
CMCON0 = 0b00000111;
ANSEL = 0x00;
TRISC = 0b00111100;
PR2 = 0b11111111; //Set the PWM period by loading the PR2 register
CCPR1L = 0x00;
T2CON = 0b01011000;
TMR2IF = 0; //clear bit for timer2 module interupt flag
while(TMR2IF == 0) //Wait until timer2 overflows then continue
{
;
}
TRISC = 0x00;
ECCPASE = 1; // for future part of program
PORTA = 0x00;
CMCON0 = 0b00000111; // comperators off
ANSEL = 0x00; //digital
TRISA = 0b00101000;
T1CON = 0b00010101;
while(1==1) // Start MainLoop
{
while(RA5 == 1) //Wait until RA5 goes low then continue
{
;
}
while(RA5 == 0) //Wait until RA5 goes high then continue
{
;
}
TMR1H = 0x00;
TMR1L = 0x00;
while(RA5 == 1) //Wait until RA5 goes low again
{
;
}
PORTC = TMR1L;
}
}
It starts timer1, then waits untill a low signal on RA5 (PWM input), then a high one, then it initializes timer1 and wait for a low signal. imediatly after that, it puts the timer1 value into a variable and the displays it on PORTC (LED array). I compiled and programmed it succesfully, but it does not seem to be displaying the value, any thoughts? Thanks!!