![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
randy.shaffer
Joined: 21 Mar 2018 Posts: 50
|
PIC16F15223 stops functioning for no apparent reason |
Posted: Fri Feb 03, 2023 3:06 pm |
|
|
Code: | #include <16F15223.h> // device file
#include <stdint.h> // to use uint16_t, etc.
#fuses PUT_16MS, NOWDT
#device adc = 10 // 10-bit A2D
#use delay(internal = 32MHZ)
#use pwm(FREQUENCY = 31.25kHz, PWM_OFF, STREAM = IN1, output=PIN_A4)
#use pwm(FREQUENCY = 31.25kHz, PWM_OFF, STREAM = IN2, output=PIN_A5)
void main(void)
{
uint16_t HALL_VALUE = 0;
set_tris_a(0b00001011); // X: A7,A6. Inputs: A3,A1,A0. Outputs: A5,A4,A2.
set_tris_c(0b00001100); // X: C7,C6. Inputs: C3,C2. Outputs: C5,C4,C1,C0.
setup_vref(VREF_ON|VREF_ADC_2v048); // Set Vref = 2.048 V for ADC
setup_adc(ADC_CLOCK_DIV_32); // ADC clock = 32/32 = 1 MHz
setup_adc_ports(sAN18 | sAN19, VSS_FVR); // ADC channel 18 using Vref
while(TRUE)
{
PWM_set_duty_percent(IN2, FALSE); // IN2 = 0
PWM_on(IN2);
PWM_set_duty_percent(IN1, 500);
PWM_on(IN1); // IN1 = PWM
while(HALL_VALUE < 350)
{// move inhibitor away from motor until unlock limit exceeded
set_adc_channel(18); // enable selected channel
delay_us(10); // wait 10us for ADC to settle
HALL_VALUE = read_adc(); // get ADC value
}
PWM_off(IN1); // IN1 = 0
PWM_off(IN2); // IN2 = 0
delay_ms(2000);
PWM_set_duty_percent(IN1, FALSE); // IN1 = 0
PWM_on(IN1);
PWM_set_duty_percent(IN2, 500);
PWM_on(IN2); // IN2 = PWM
while(HALL_VALUE > 25)
{// move inhibitor toward motor
set_adc_channel(18); // enable selected channel
delay_us(10); // wait 10us for ADC to settle
HALL_VALUE = read_adc(); // get ADC value
}
PWM_off(IN1); // IN1 = 0
PWM_off(IN2); // IN2 = 0
delay_ms(2000);
}
} // end main |
After running properly for a while, sometimes a short while, the PIC hangs up and I have to cycle power to restart. If I try to re-program after a hang up, it will not start up. Am I missing an important fuse? Compiler is 5.114. PIC is a 16-QFN. |
|
![](templates/subSilver/images/spacer.gif) |
gaugeguy
Joined: 05 Apr 2011 Posts: 296
|
|
Posted: Fri Feb 03, 2023 3:38 pm |
|
|
Your notes mention a motor so I am going to go with conductor and/or radiated EMI. |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9171 Location: Greensville,Ontario
|
|
Posted: Fri Feb 03, 2023 3:53 pm |
|
|
as gg says, probably EMO from motor...
does the program work 'forever' if motor power is disconnected ? |
|
![](templates/subSilver/images/spacer.gif) |
randy.shaffer
Joined: 21 Mar 2018 Posts: 50
|
|
Posted: Fri Feb 03, 2023 4:05 pm |
|
|
I'll disconnect the motor and see. Thank you both for the advice. |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|