![]() |
![]() |
![]() |
|
|
|||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
|
|
Thread Tools | Display Modes |
|
|
(permalink) |
|
I'm desperately seeking help using the PIC18F452 with the CCS C Compiler.
Heres my code: Code:
#include <18F452.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#bit TMR2IF=0xF9E.1
void main(void)
{
output_high(PIN_A0);
SET_TRIS_C(0b00000000);
SETUP_TIMER_2(T2_DIV_BY_1,128,1);
SET_PWM1_DUTY(0);
SETUP_CCP1(CCP_PWM); // PUT THE CCP1 PORT INTO PWM MODE
TMR2IF=0;
while (TRUE) {
set_pwm1_duty(120);
while (TMR2IF==0);
}
}
I've tried everything but I can't get it to run continuously. I have the MCLR pin tied to high through a 10k resistor. I've also tried directly tieing it to high, but no luck. Please help, thank you!! |
|
|
|
|
|
|
(permalink) |
|
Code:
output_high(PIN_A0); SET_TRIS_C(0b00000000); SETUP_TIMER_2(T2_DIV_BY_1,128,1); SET_PWM1_DUTY(0); SETUP_CCP1(CCP_PWM); // PUT THE CCP1 PORT INTO PWM MODE sorry I'm not really helping with your problem, I don't use CCS as you can tell, but I would highly suggest you take a look at some of the other compilers, especially BoostC. at least when you are using standard C operators and functions, and not compiler-specific, arbitrary, hidden routines people with knowledge of C but without knowledge of your specific compiler will be able to provide a little assistance.
__________________
EEgeek.net |
|
|
|
|
|
|
(permalink) |
|
Never used BoostC. HiTech's PICC18 and Microchip's own MCC18 are good. MCC18 has a free version, though not fully optimized like their pay version.
CCS strongly encourages proprietary functions, and sadly forgot to implement all of ANSI C functionality along the way. Including some very important stuff. IMHO there's no reason whatsoever to use it once free MCC18 came out. I share evandude's sentiments on proprietary functions. Direct code is SO much more practical. I'm not sure what you're trying to do. Rewriting the PWM period is unnecessary and can introduce glitches. This code is bad: Code:
TMR2IF=0;
while (TRUE) {
set_pwm1_duty(120);
while (TMR2IF==0);
}
Code:
set_pwm1_duty(120); while(TRUE); I would first suspect your system is being reset after getting screwed by electrical motor noise. Make sure you have a ceramic cap right on the Vdd to Vcc pins. Put a cap on the motor's supply. Try to isolate the motor's supply from the chip's supply (like powering it off the +5v reg may be a problem for noise).
__________________
I thought what I'd do was I'd pretend I was one of those deaf-mutes. |
|
|
|
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|