Undefined switch-cse function problem???
Posted: 20 Jun 2021 14:06
Hi there, I'm new to this forum and relatively new to programming in general since my primary work was in RF.
I bought mikroC licence two years ago and got quite into PIC series chips projects, building about 20 different projects in that time, mostly in field of automatics and industrial control (temperature, pressure, DC servo motor drivers and stuff like that). But here is my new problem, and the one I could not solve.
I'm designing PID temperature controller for 5kW induction crucible (also of my design). Since I have 10-11 16F877 obsolete controllers laying around, but the design is not demanding at all, and I need to build seven crucibles, I opted for designing simple controller with PIC16F877, HD44780 4x20 LCD display, MAX31855 K-type probe temperature reader and one CP2102 UART-USB converter so I could simply send commands and receive back parameters from controller. Only non-uart controls are simple rotary encoder for setting the temperature, and two pushbuttons for start and stop of heating. I'm also using the pushbutton on the encoder connected to RB0 interrupt for saving set temperature to EEPROM. All functions in code I wrote, and the only one from mikroC library I'm using is the LCD one. Also I'm using 8 digital inputs (for reading possible faults in induction crucible) and 7 outputs (for turning on/off high frequency generator, AC and softstart relays, cooling FAN and alarm buzzer, and two lamps inside START and STOP pushbuttons).
Here's the main idea. Interrupt handler is handling 4 interrupts. RBIF interrupt for encoder reading (A and B inputs connected to RB4 and RB7 pins), INTF interrupt for reading the encoder button (it saves set temperature value to EEPROM) and timer1 interrupt generating precize 50ms ticker I'm using for timing MAX31855 reading (on every 20th tick), PID routine (on every 200th tick), and also simple generation of 10sec periode PWM with 0...200 input for turning on and off the high frequency generator. Also there is RCIF interrupt for UART reception.
So every second I read MAX31855 and display the temperature value on the LCD. Every 10th second I find error, sum error and difference error for my PID routine and also initiate one, in the same time i refresh duty cycle value to the new PID value. And all of this is working like charm. But there is a problem with UART control of the system.
Idea is quite simple, to send to controller different commands via UART and got it to do stuff, here is the manual:
1. send "P?" (CRLF) and controller returns value of Kp (via UART) in form long vlaue from 00000 to 99999.
2.sned "P=xxxxx" (CRLF) [xxxxx is a number from 00000 to 99999] and controller reads send number saves it to EEPROM, change Kp to new value and returns "OK" via UART.
3. same for I
4. same for D
5. send "RY"(CRLF), activates UART returning temperature value on every MAX31855 read (every second, controlled via timer interrupt as I mentioned above), and saves activation bit for that function to EEPROM, also returns "Activated" via UART.
6. send "RN"(CRLF), terminates UART returning temperature value, saves the activation bit value to EEPROM and returns "Terminated" via UART.
So, RCIF interrupt activates the function that receives 7 bytes of information and if those are followed by CRLF saves those 7 to array 'receive[0...7]' and sets 'rcv' bit. Next in while(1) loop where I'm rolling my code again and again I have if statement where I check 'rcv' bit and if it is high I start 'work_prim()' function and resets te rcv bit.
And finally I got to my problem, I wrote work_prim() function as stacked switch case, and I'm sending you here the code that is actually working but I have strange problem. So ccode works as it supposed to everything is fine before I add the piece you are about to see in attached text file with the function. If someone has the idea why is that please help me since I've tried everything and after simple adding 'default:' to third switch case statement code fails. Also I have to mention here that the same code is working perfectly fine with this piece added if I rewrote it to MPLab IDE version 2.30, and compile it via XC8 version 1.34, but in mikroC it compiles, but fails working.
I bought mikroC licence two years ago and got quite into PIC series chips projects, building about 20 different projects in that time, mostly in field of automatics and industrial control (temperature, pressure, DC servo motor drivers and stuff like that). But here is my new problem, and the one I could not solve.
I'm designing PID temperature controller for 5kW induction crucible (also of my design). Since I have 10-11 16F877 obsolete controllers laying around, but the design is not demanding at all, and I need to build seven crucibles, I opted for designing simple controller with PIC16F877, HD44780 4x20 LCD display, MAX31855 K-type probe temperature reader and one CP2102 UART-USB converter so I could simply send commands and receive back parameters from controller. Only non-uart controls are simple rotary encoder for setting the temperature, and two pushbuttons for start and stop of heating. I'm also using the pushbutton on the encoder connected to RB0 interrupt for saving set temperature to EEPROM. All functions in code I wrote, and the only one from mikroC library I'm using is the LCD one. Also I'm using 8 digital inputs (for reading possible faults in induction crucible) and 7 outputs (for turning on/off high frequency generator, AC and softstart relays, cooling FAN and alarm buzzer, and two lamps inside START and STOP pushbuttons).
Here's the main idea. Interrupt handler is handling 4 interrupts. RBIF interrupt for encoder reading (A and B inputs connected to RB4 and RB7 pins), INTF interrupt for reading the encoder button (it saves set temperature value to EEPROM) and timer1 interrupt generating precize 50ms ticker I'm using for timing MAX31855 reading (on every 20th tick), PID routine (on every 200th tick), and also simple generation of 10sec periode PWM with 0...200 input for turning on and off the high frequency generator. Also there is RCIF interrupt for UART reception.
So every second I read MAX31855 and display the temperature value on the LCD. Every 10th second I find error, sum error and difference error for my PID routine and also initiate one, in the same time i refresh duty cycle value to the new PID value. And all of this is working like charm. But there is a problem with UART control of the system.
Idea is quite simple, to send to controller different commands via UART and got it to do stuff, here is the manual:
1. send "P?" (CRLF) and controller returns value of Kp (via UART) in form long vlaue from 00000 to 99999.
2.sned "P=xxxxx" (CRLF) [xxxxx is a number from 00000 to 99999] and controller reads send number saves it to EEPROM, change Kp to new value and returns "OK" via UART.
3. same for I
4. same for D
5. send "RY"(CRLF), activates UART returning temperature value on every MAX31855 read (every second, controlled via timer interrupt as I mentioned above), and saves activation bit for that function to EEPROM, also returns "Activated" via UART.
6. send "RN"(CRLF), terminates UART returning temperature value, saves the activation bit value to EEPROM and returns "Terminated" via UART.
So, RCIF interrupt activates the function that receives 7 bytes of information and if those are followed by CRLF saves those 7 to array 'receive[0...7]' and sets 'rcv' bit. Next in while(1) loop where I'm rolling my code again and again I have if statement where I check 'rcv' bit and if it is high I start 'work_prim()' function and resets te rcv bit.
And finally I got to my problem, I wrote work_prim() function as stacked switch case, and I'm sending you here the code that is actually working but I have strange problem. So ccode works as it supposed to everything is fine before I add the piece you are about to see in attached text file with the function. If someone has the idea why is that please help me since I've tried everything and after simple adding 'default:' to third switch case statement code fails. Also I have to mention here that the same code is working perfectly fine with this piece added if I rewrote it to MPLab IDE version 2.30, and compile it via XC8 version 1.34, but in mikroC it compiles, but fails working.