#define led LATE5_bit
void InitMain() {
//ADPCFG = 0xFFFF; // Configure AN pins as digital I/O
TRISB = 0x0000; // configureall ports as Output
TRISD = 0x0000;
TRISF = 0x0000;
TRISG = 0x0000;
TRISE = 0x0000;
LATE5_bit = 0x00;
//TRISC = 0x0000;
Unlock_IOLOCK();
PPS_Mapping_NoLock(0, _OUTPUT, _OC1); // Sets pin 0 to be Output
Lock_IOLOCK();
}
int current_duty,maxi,chanel;
void main() {
InitMain();
current_duty = 5000; //16 bit pwm
chanel = 1;
PWM_Init(100,chanel,0,0);
PWM_Start(chanel); //Start pwm1
maxi = 65536;
PWM_Set_Duty(maxi, chanel); // Set current duty for PWM1
while(1){
while(current_duty < maxi){
PWM_Set_Duty(current_duty,chanel);
current_duty++;
led = !led;
delay_ms(100);
}
current_duty = 0;
}
}
i can't find whats wrong with my coding
Really? Where is the main loop?
//this is from MikroC for PIC, I don't have the 16-bit version installed on this machine.
//PIC24 should be similar
void PWM1_Init(long freq);
// For Enhanced Mid-Range Core 145x/150x MCUs
void PWM1_Init(unsigned long PWM_Freq, unsigned int timer_prescaler);
Without a main loop the PC will just increase until it overflows and starts over at 0x0000, this is the best scenario assuming that an erased flash will contain what will be executed as nops, worst case, it will be random junk and you can't understand what the micro is doing.
And what would go in it?
L_end_main:
0x002C 0xD7FF BRA $+0
Nothing. Absolutely nothing.
And that's the point of it.
- Check your re mappable I/O ( something like "PPS_Mapping_NoLock(0, _OUTPUT, _OC1);" makes no sense - where is the remappable pin number? Is it 0? Your comment says 5)
- Check your timer/PWM configuration. (Did you initialize before start?)
timer initialization
#include "pps.h"
...
//Set serial console pins
PPSUnLock;
PPSOutput( PPS_RP21, PPS_U2TX ); //hardcoded
PPSInput( PPS_U2RX, PPS_RP26 ); //todo - make less cryptic
PPSLock;
#define led LATE5_bit
void InitMain() {
//ADPCFG = 0xFFFF; // Configure AN pins as digital I/O
TRISB = 0x0000; // configureall ports as Output
TRISD = 0x0000;
TRISF = 0x0000;
TRISG = 0x0000;
TRISE = 0x0000;
LATE5_bit = 0x00;
//TRISC = 0x0000;
Unlock_IOLOCK();
PPS_Mapping_NoLock(0, _OUTPUT, _OC1); // Sets pin 0 to be Output
Lock_IOLOCK();
}
int current_duty,maxi,chanel;
void main() {
InitMain();
current_duty = 5000; //16 bit pwm
chanel = 1;
PWM_Init(100,chanel,0,0);
PWM_Start(chanel); //Start pwm1
maxi = 65536;
PWM_Set_Duty(maxi, chanel); // Set current duty for PWM1
while(1){
while(current_duty < maxi){
PWM_Set_Duty(current_duty,chanel);
current_duty++;
led = !led;
delay_ms(100);
}
current_duty = 0;
}
}
while(current_duty < maxi){
PWM_Set_Duty(current_duty,chanel);
current_duty++;
led = !led;
delay_ms(100);
}
current_duty = 0;maxi = 65536;