|
|
View previous topic :: View next topic |
Author |
Message |
af19
Joined: 21 Aug 2014 Posts: 15
|
|
Posted: Mon Feb 02, 2015 2:24 am |
|
|
I put the micro controller on breadboard and there is still a 2.5 V on the PIN B11!!
I think there is a problem with fuse bits.
What do you think is the problem? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Mon Feb 02, 2015 3:38 am |
|
|
Pull both pin 14, and pin 15 high externally.
On this chip, the fault inputs wake up enabled, with _pull down_ resistors on them (so they default to the fault condition).
Haven't got this chip, but running it up in MPLAB, I'm seeing the fault condition being permanently triggered, and it won't clear without the pin being driven high before you try to program the PWM. The pin has to be taken high, then the fault condition cleared, and then you can enable the PWM and have it work. I added an external stimulus to take then pins high, and then added code to clear the fault bits, and then programmed the PWM, and it appears the to work. |
|
|
af19
Joined: 21 Aug 2014 Posts: 15
|
|
Posted: Mon Feb 02, 2015 8:33 am |
|
|
Ttelmah wrote: | Pull both pin 14, and pin 15 high externally.
On this chip, the fault inputs wake up enabled, with _pull down_ resistors on them (so they default to the fault condition).
Haven't got this chip, but running it up in MPLAB, I'm seeing the fault condition being permanently triggered, and it won't clear without the pin being driven high before you try to program the PWM. The pin has to be taken high, then the fault condition cleared, and then you can enable the PWM and have it work. I added an external stimulus to take then pins high, and then added code to clear the fault bits, and then programmed the PWM, and it appears the to work. |
Thanks for the reply.
I checked P1FLTACON and P1FLTBCON with Watch, before setting RB5 and RB4 high, and then i set these pins high with simulus(after resetting the program to start from the first line) but the value didn't change, it was 0X0080. it seems faults are not triggered (Based on the value of registers).
Am I checking the wrong register?
What should i add to my code to clear the fault bits? ( I think i can clear the bit with bit_clear(); which bit should i clear?)
Can i use set_pullup(TRUE,PIN_B5) in my code to internally pull up these pins for programming? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Tue Feb 03, 2015 3:23 am |
|
|
Several things.
You can't just use an async stimulus. It has to be seen as an 'external' stimulus.
Use the 'clock stimulus' tab, and select RB6, 'initial' HIGH 'begin' At start, 'End' never. Do the same on the next line for RB5. Then the pins are seen to be taken high as soon as the processor starts, and held high.
However with the code below, it works even if the fault pins are not taken high.
Then I've gone 'OTT', but it works:
Code: |
//start of main:
void main()
{
setup_motor_pwm(1,MPWM_DISABLED,1,1,199); //ensure PWM is off
set_motor_unit(1,1,MPWM_ENABLE | MPWM_FAULT_NO_CHANGE,4,4);
set_motor_unit(1,2,MPWM_ENABLE | MPWM_FAULT_NO_CHANGE,4,4);
set_motor_unit(1,3,MPWM_ENABLE | MPWM_FAULT_NO_CHANGE,4,4);
//now disable fault behaviour
#bit FLTAM=getenv("BIT:FLTAM")
#bit FLTBM=getenv("BIT:FLTBM")
FLTAM=FALSE;
FLTBM=FALSE;
clear_interrupt(INT_FAULTA);
clear_interrupt(INT_FAULTA); //now clear all the fault flags and interrupts
setup_motor_pwm(1,MPWM_FREE_RUN,1,1,199); //and start the PWM
OUTPUT_HIGH(PIN_A0);
enable_interrupts(INT_PWM1);
enable_interrupts(INTR_GLOBAL);
while(TRUE)
{
Temp1 = i;
Temp2 = Temp1 + PHASE_SHIFT_120;
Temp3 = Temp1 + PHASE_SHIFT_240;
Phase1 = Temp1;
Phase2 = Temp2;
Phase3 = Temp3;
set_motor_pwm_duty(1,1,SineTable[Phase1]+199);
set_motor_pwm_duty(1,2,SineTable[Phase2]+199);
set_motor_pwm_duty(1,3,SineTable[Phase3]+199);
while (Temp1==i)
; //wait for interrupt
}
}
|
Now this waits for the interrupt to occur before trying to update the PWM registers. Currently you are updating them repeatedly and only the last update will be seen. As soon as 'i' changes, this code advances and updates the new PWM values.
Now, with all the errors cleared, this starts working, merrily updating all three pairs of pins in the simulator at least. |
|
|
af19
Joined: 21 Aug 2014 Posts: 15
|
|
Posted: Tue Feb 03, 2015 2:09 pm |
|
|
Ttelmah wrote: | Several things.
You can't just use an async stimulus. It has to be seen as an 'external' stimulus.
Use the 'clock stimulus' tab, and select RB6, 'initial' HIGH 'begin' At start, 'End' never. Do the same on the next line for RB5. Then the pins are seen to be taken high as soon as the processor starts, and held high.
However with the code below, it works even if the fault pins are not taken high.
Then I've gone 'OTT', but it works:
Code: |
//start of main:
void main()
{
setup_motor_pwm(1,MPWM_DISABLED,1,1,199); //ensure PWM is off
set_motor_unit(1,1,MPWM_ENABLE | MPWM_FAULT_NO_CHANGE,4,4);
set_motor_unit(1,2,MPWM_ENABLE | MPWM_FAULT_NO_CHANGE,4,4);
set_motor_unit(1,3,MPWM_ENABLE | MPWM_FAULT_NO_CHANGE,4,4);
//now disable fault behaviour
#bit FLTAM=getenv("BIT:FLTAM")
#bit FLTBM=getenv("BIT:FLTBM")
FLTAM=FALSE;
FLTBM=FALSE;
clear_interrupt(INT_FAULTA);
clear_interrupt(INT_FAULTA); //now clear all the fault flags and interrupts
setup_motor_pwm(1,MPWM_FREE_RUN,1,1,199); //and start the PWM
OUTPUT_HIGH(PIN_A0);
enable_interrupts(INT_PWM1);
enable_interrupts(INTR_GLOBAL);
while(TRUE)
{
Temp1 = i;
Temp2 = Temp1 + PHASE_SHIFT_120;
Temp3 = Temp1 + PHASE_SHIFT_240;
Phase1 = Temp1;
Phase2 = Temp2;
Phase3 = Temp3;
set_motor_pwm_duty(1,1,SineTable[Phase1]+199);
set_motor_pwm_duty(1,2,SineTable[Phase2]+199);
set_motor_pwm_duty(1,3,SineTable[Phase3]+199);
while (Temp1==i)
; //wait for interrupt
}
}
|
Now this waits for the interrupt to occur before trying to update the PWM registers. Currently you are updating them repeatedly and only the last update will be seen. As soon as 'i' changes, this code advances and updates the new PWM values.
Now, with all the errors cleared, this starts working, merrily updating all three pairs of pins in the simulator at least. |
I added and then my problem solved.
I will try your code.
I really appreciate your help.
Thank you very much. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Tue Feb 03, 2015 2:16 pm |
|
|
Yes, I had that in my code, forgot to include it or point this out.... |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|