CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

PIC16F15223 stops functioning for no apparent reason

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
randy.shaffer



Joined: 21 Mar 2018
Posts: 51

View user's profile Send private message

PIC16F15223 stops functioning for no apparent reason
PostPosted: Fri Feb 03, 2023 3:06 pm     Reply with quote

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.
gaugeguy



Joined: 05 Apr 2011
Posts: 303

View user's profile Send private message

PostPosted: Fri Feb 03, 2023 3:38 pm     Reply with quote

Your notes mention a motor so I am going to go with conductor and/or radiated EMI.
temtronic



Joined: 01 Jul 2010
Posts: 9226
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Feb 03, 2023 3:53 pm     Reply with quote

as gg says, probably EMO from motor...
does the program work 'forever' if motor power is disconnected ?
randy.shaffer



Joined: 21 Mar 2018
Posts: 51

View user's profile Send private message

PostPosted: Fri Feb 03, 2023 4:05 pm     Reply with quote

I'll disconnect the motor and see. Thank you both for the advice.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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