• Forums
• Posts
Latest Posts
Active Posts
Recently Visited
Search Results
• Page Extras
• Forum Themes
• AVR Freaks

### Newbie: controlling duty cycle of PWM set up with MCC

Page: << < ..678910.. > >> Showing page 6 of 14
Author
SGK
Senior Member
• Total Posts : 158
• Reward points : 0
• Joined: 2018/05/14 13:55:08
• Location: 0
• Status: offline
Re: Newbie: controlling duty cycle of PWM set up with MCC 2018/05/24 06:19:06 (permalink)
0
General question about variable lengths (bits) and memory.  I recognise that integer accuracy is enough for my temp calculations. But I have no shortage of data memory. I am right up against max program memory however. My presumption is that going through and trimming things to integers (or even unsigned short int) doesn't really gain me much (other than perhaps a lesson in more efficient data memory practices). Incorrect?

Thanks PSTechPaul.  I can see many helpful tips in the code you posted and will look through it vs mine today.
SGK
Senior Member
• Total Posts : 158
• Reward points : 0
• Joined: 2018/05/14 13:55:08
• Location: 0
• Status: offline
Re: Newbie: controlling duty cycle of PWM set up with MCC 2018/05/24 09:55:51 (permalink)
0
Doesn't ptr = strtok(Command, " "); extract to ptr those characters in front of the space delimiter? So if command = B 1234 then ptr = B. I'm looking at the example provided here. We need to strtok again to get the numbers, no?

In any event, according to the XC8 C Compiler User's Guide  atoi scans a string for ACSII representation of decimal numbers. Is it not the case then that the B and space above are ignored and so atoi(command) = 1234 without any further adjustment? Following your advice, "S 1234" could be truncated to "S 12" with command[4]=0; and so atoi(command) = 12?

Please can you explain the +2 in the atoi function?

A 'problem' with your code is that X may not be at Command[0].  I wrote so that the entry "123X" should cause a quit.

I'm puzzled by your use of NOP(). If X do nothing then break - why not just remove X from the list of cases?  And the other two?

PStechPaul
Super Member
• Total Posts : 3046
• Reward points : 0
• Joined: 2006/06/27 16:11:32
• Location: Cockeysville, MD, USA
• Status: offline
Re: Newbie: controlling duty cycle of PWM set up with MCC 2018/05/24 14:51:44 (permalink)
0
I used a bit of "pointer magic", where in this case "ptr" is a pointer, or address, in memory. So if ptr=strtok(Command, " "), it uses the address of the first substring of Command, which is "B". The string Command is now {'B','\0','1','2','3','4','\0'}. So, the string starting at ptr+2 is "0123". I just realized that the strtok() function is not really needed, and I was able to simply use NTC_Beta=atoi( Command+2 ).

I used the NOP() as a placeholder so I could set a breakpoint there for debugging.

The loop which reads the EUSART has a check that handles the 'X' the same as '\r', with a break, so it immediately falls through to the switch(Command[0]). You could check for Input_Char=='X' and perform the error processing or whatever else is needed.

I think it would be better to allow any number of numeric characters for any of the commands, and then allow only a particular range of values before updating the variables such as MaxTempC.

The atoi() function will abort and return 0 if you try to read the raw Command. It stops parsing when it encounters the 'B'. But it does return a correct conversion if the Command string has leading spaces, so you can use NTC_Beta = atoi(Command+1). This will work correctly for command strings of "B 1234" as well as "B1234".

The strtok function would be handy if you wanted to accept user input such as "1234 56 789" or using other separators for multiple values. This is handy for reading a CSV file which uses commas, and can be handled by Excel and other spreadsheets.
post edited by PStechPaul - 2018/05/24 15:06:08

SGK
Senior Member
• Total Posts : 158
• Reward points : 0
• Joined: 2018/05/14 13:55:08
• Location: 0
• Status: offline
Re: Newbie: controlling duty cycle of PWM set up with MCC 2018/05/24 19:06:23 (permalink)
0
Thanks.  I will study up tomorrow. Here is a first cut at the overall schematic. I don't think I need the 5V connection to the "serial" connector and will remove it and the associated cap.
PStechPaul
Super Member
• Total Posts : 3046
• Reward points : 0
• Joined: 2006/06/27 16:11:32
• Location: Cockeysville, MD, USA
• Status: offline
Re: Newbie: controlling duty cycle of PWM set up with MCC 2018/05/24 22:11:00 (permalink)
0
I suggest adding a 5 pin connector for the PICkit3, for in-circuit programming and debugging.

Also, you might make the serial connector directly compatible with a cheap Bluetooth HC-5 module, which is:

1. State
2. RxD
3. TxD
4. GND
5. +5V
6. EN

You only need 2,3,4, and 5.

It is very easy to pair the module with the Bluetooth radio in your computer or tablet, and use a terminal program like TeraTerm Pro to send commands and receive communications.

SGK
Senior Member
• Total Posts : 158
• Reward points : 0
• Joined: 2018/05/14 13:55:08
• Location: 0
• Status: offline
Re: Newbie: controlling duty cycle of PWM set up with MCC 2018/05/25 06:38:25 (permalink)
0
You mean one of these?
Intersting. So I leave my 5V connection and add another (female) header to accept the breakout board (just leaving pins 1 and 6 unconnected). Easier than plugging in via my USB to serial adaptor.  I'll add provision for one in the board in any event.
SGK
Senior Member
• Total Posts : 158
• Reward points : 0
• Joined: 2018/05/14 13:55:08
• Location: 0
• Status: offline
Re: Newbie: controlling duty cycle of PWM set up with MCC 2018/05/25 06:43:16 (permalink)
0
Can't even edit post to fix a spelling mistake.  Just because I have a URL link. Grrhh!

PS change "(female) header" to "socket"

I don't think I need a socket for the Pickit3 as I should be able to do any Pickit3 work with the PIC in my universal programming seat. Adding the Bluetooth module might make it a lot easier for serial communication when the PIC is installed in the annealer. (I assume I need to cross-wire Rx and TX i.e Rx on PIC to pin Tx on breakout board and vice versa.)
post edited by SGK - 2018/05/25 07:02:42
PStechPaul
Super Member
• Total Posts : 3046
• Reward points : 0
• Joined: 2006/06/27 16:11:32
• Location: Cockeysville, MD, USA
• Status: offline
Re: Newbie: controlling duty cycle of PWM set up with MCC 2018/05/25 12:56:40 (permalink)
0
The socket for the PICkit3 will be useful if you want to do debugging on the target. All you need is a 5 or 6 pin header. Even just the holes can be used with male-to-male jumpers or a header just loosely placed on the PCB. It also becomes necessary if you use surface mount PICs.

SGK
Senior Member
• Total Posts : 158
• Reward points : 0
• Joined: 2018/05/14 13:55:08
• Location: 0
• Status: offline
Re: Newbie: controlling duty cycle of PWM set up with MCC 2018/05/25 20:24:03 (permalink)
0
Ok let me think about it. In the first instance I can debug with the Picket 3 and the PIC16F1829 in the universal seat. Of course if the PIC wasn't through hole this would not be possible. I have not used the debug features of MPLAB. I have only flashed PICs with the Pickit 3. Do I have it correct that for this PIC PGD needs to connect to pin 19, PGO  to pin 18 and MCLR to pin 4 (Vdd and and Vss are obvious)? What if MCLR pin 4 is configured as digital input? (I've not used it for anything but it is configured as such.)

(I prefer to use a socket and through-hole PIC for this project in case I have to send a flashed PIC to someone.)

I still need to work through your code...
PStechPaul
Super Member
• Total Posts : 3046
• Reward points : 0
• Joined: 2006/06/27 16:11:32
• Location: Cockeysville, MD, USA
• Status: offline
Re: Newbie: controlling duty cycle of PWM set up with MCC 2018/05/25 21:17:50 (permalink)
0
The universal programming adapter is fine for flashing PICs in DIP packages, and you can do limited debugging like reading a switch or lighting an LED, but it gets awkward for much more than that. In-circuit debugging allows you to use actual hardware and code, and stop execution at breakpoints and examine registers. The PICkit3 is limited to only two or three breakpoints, but that's usually enough. You can single step or run to cursor and have one breakpoint on a specific part of code you want to debug.

If you are running out of code space, you might try using the look-up table to derive temperature from the ADC reading. The same algorithm for piecewise linear interpolation can also work for floating point values, and you can optimize it by choosing different increments of ADCvalue. However, that would make it more difficult to change the curve for different thermistors. But it can be done, using a series of values separated by spaces or commas.

qɥb
Monolothic Member
• Total Posts : 3332
• Reward points : 0
• Joined: 2017/09/09 05:07:30
• Location: Jupiter
• Status: offline
Re: Newbie: controlling duty cycle of PWM set up with MCC 2018/05/25 23:28:01 (permalink)
+1 (1)
PStechPaul
...
The PICkit3 is limited to only two or three breakpoints, but that's usually enough.

The limit is in the debug hardware built into each PIC, not in the PK3 itself.
Old PIC16F devices only have a single breakpoint. Many newer ones have 3.

This forum is mis-configured so it only works correctly if you access it via https protocol.
The Microchip website links to it using http protocol. Will they ever catch on?
PicForum "it just works"
PStechPaul
Super Member
• Total Posts : 3046
• Reward points : 0
• Joined: 2006/06/27 16:11:32
• Location: Cockeysville, MD, USA
• Status: offline
Re: Newbie: controlling duty cycle of PWM set up with MCC 2018/05/26 02:23:28 (permalink)
0
I didn't know that. I searched the datasheet for the PIC16F1825/9 and could not find anything that specified the number of hardware breakpoints supported. It only showed that they are available internally as well as via a header (I/H). A little more searching and I found this:

However, it is still not very definitive and the information seems outdated (2011), as it shows no software breakpoints for PIC16 or less.

http://microchipdeveloper.com/tls0201:hardware-breakpoints

https://microchipfae.com/2012/04/19/hardware-breakpoints-stopping-on-a-dime-or-two/

SGK
Senior Member
• Total Posts : 158
• Reward points : 0
• Joined: 2018/05/14 13:55:08
• Location: 0
• Status: offline
Re: Newbie: controlling duty cycle of PWM set up with MCC 2018/05/26 07:26:29 (permalink)
0
Ok.  I will add the pins if only to learn debugging via Picket en situe. If I use jumper wires I can use the existing serial header for Vdd and Vss. I need to be certain of the pin connections required.

Do I have it correct that for this PIC PGD needs to connect to pin 19, PGO  to pin 18 and MCLR to pin 4 (Vdd and and Vss are obvious)? What if MCLR pin 4 is configured as digital input? (I've not used it for anything but it is configured as such.)

On code space, I'm at 99% but apart from looking at your pointer stuff and maybe streamlining there I think I'm done. The logical next step in this sort of project would be to replace the external Sestos B3S timer, by adding a couple of relays and a user interface for setting annealing time and saving presets etc. That would require more program memory. But I am not going to do that. That would be a step too far for this first project and too much torture for you guys!
SGK
Senior Member
• Total Posts : 158
• Reward points : 0
• Joined: 2018/05/14 13:55:08
• Location: 0
• Status: offline
Re: Newbie: controlling duty cycle of PWM set up with MCC 2018/05/29 09:50:59 (permalink)
0
PStechPaul
I just realized that the strtok() function is not really needed, and I was able to simply use NTC_Beta=atoi( Command+2 ).

PStechPaulThe atoi() function will abort and return 0 if you try to read the raw Command. It stops parsing when it encounters the 'B'. But it does return a correct conversion if the Command string has leading spaces, so you can use NTC_Beta = atoi(Command+1). This will work correctly for command strings of "B 1234" as well as "B1234".

I'm still slow on this and want to make sure I have it right. So case 'B': Command[6]=0;  truncates Command to the first 6 characters and then atoi(Command +1); says extract the integer value from Command ignoring the first character and naturally skipping leading spaces?

So then this should be ok:

`//Program key constantsvoid Program_Constants(void){ Send_Programming_String(); char Cmd[]="000000"; int i=0; char Input_Char = '£';  while (Input_Char != 'X') { //Process multiple commands until X while (Input_Char != 'X' && i < 6 && Input_Char != '\r'){ //Read up to 6 characters only and stop early if X or \r.  Input_Char = EUSART_Read(); Cmd[i] = Input_Char; i++; } i=0; if (Input_Char != 'X') { //Examine and process command. Skip if X was entered. if ((Cmd[0] == 'B' || Cmd[0] == 'S' || Cmd[0] == 'F') && (Cmd[1] == ' ')){ //Check command for input errors. switch (Cmd[0]) { case 'B':  NTC_Beta = atoi(Cmd+1); break; case 'S':  Cmd[4]=0; Over_Temp = atoi(Cmd+1); break; case 'F':  Cmd[4]=0; DC50_Limit = atoi(Cmd+1); break;  } Send_Programming_String(); } else { printf("INPUT ERROR\n\n"); Send_Programming_String(); } }   } }`

SGK
Senior Member
• Total Posts : 158
• Reward points : 0
• Joined: 2018/05/14 13:55:08
• Location: 0
• Status: offline
Re: Newbie: controlling duty cycle of PWM set up with MCC 2018/05/29 13:12:46 (permalink)
0
Hmmm. So I tried to program my PIC16F1829 and things seemed to program ok. See first lot of text below from the Pickit3 output window. I then tried to connect to it via a USB-Serial cable I have used before. Coolterm was used to connect to the PIC.  A connection was established but the PIC did not provide the welcome message or respond to keyboard entry e.g. 'P'.  So I tried to program it again.  I now get the error below. Have I smoked the PIC or something?

*****************************************************
Connecting to MPLAB PICkit 3...
Currently loaded firmware on PICkit 3
Firmware Suite Version.....01.51.08
Firmware type..............Enhanced Midrange
Programmer to target power is enabled - VDD = 5.000000 volts.
Target device PIC16F1829 found.
Device ID Revision = 4
Device Erased...
Programming...
The following memory area(s) will be programmed:
configuration memory
EEData memory
Programming/Verify complete
*****************************************************
Connecting to MPLAB PICkit 3...
Currently loaded firmware on PICkit 3
Firmware Suite Version.....01.51.08
Firmware type..............Enhanced Midrange
PICkit 3 is trying to supply 5.000000 volts from the USB port, but the target VDD is measured to be 4.750000 volts. This could be due to the USB port power capabilities or the target circuitry affecting the measured VDD.
The target circuit may require more power than the debug tool can provide. An external power supply might be necessary.
Connection Failed.

*****************************************************
qɥb
Monolothic Member
• Total Posts : 3332
• Reward points : 0
• Joined: 2017/09/09 05:07:30
• Location: Jupiter
• Status: offline
Re: Newbie: controlling duty cycle of PWM set up with MCC 2018/05/29 13:20:51 (permalink)
+1 (1)
No, it is saying that you have told the PK3 to provide power to the PIC, and specified the power should be 5.0 volts, but the PK3 is not getting enough voltage from your USB port to do that.
Change the PK3 settings to reduce the voltage it tries to supply down to 4.75V and try again.

This forum is mis-configured so it only works correctly if you access it via https protocol.
The Microchip website links to it using http protocol. Will they ever catch on?
PicForum "it just works"
PStechPaul
Super Member
• Total Posts : 3046
• Reward points : 0
• Joined: 2006/06/27 16:11:32
• Location: Cockeysville, MD, USA
• Status: offline
Re: Newbie: controlling duty cycle of PWM set up with MCC 2018/05/29 13:38:44 (permalink)
0
I have also seen something like that when the USB cable is substandard, having several ohms resistance through the power and ground lines, or bad connections. It also happens when there is a 7805 type regulator on the target board and its output is on the low side. It also could happen if there is a large capacitor or other load on the 5V circuit.

SGK
Senior Member
• Total Posts : 158
• Reward points : 0
• Joined: 2018/05/14 13:55:08
• Location: 0
• Status: offline
Re: Newbie: controlling duty cycle of PWM set up with MCC 2018/05/29 13:41:04 (permalink)
0
Ok.  Odd that it didn't have that problem in the first place. I have successfully (I think) programmed the PIC again, albeit with the same code. I am selecting the  "Make and Program Device" button.  See output below.  I now need to find out why I don't even get the welcome string when I connect to it via a USB-Serial cable.  (Cable connections: red +5V to pin 1, black GND to pin 20, white Rxd to PIC TX 10, and green Txd to PIC RX 5.)  Nothing else is connected to the PIC.  My idea was to at least test my menus.

*****************************************************
Connecting to MPLAB PICkit 3...
Currently loaded firmware on PICkit 3
Firmware Suite Version.....01.51.08
Firmware type..............Enhanced Midrange
Programmer to target power is enabled - VDD = 4.750000 volts.
Target device PIC16F1829 found.
Device ID Revision = 4
Device Erased...
Programming...
The following memory area(s) will be programmed:
configuration memory
EEData memory
Programming/Verify complete
post edited by SGK - 2018/05/29 13:42:26
SGK
Senior Member
• Total Posts : 158
• Reward points : 0
• Joined: 2018/05/14 13:55:08
• Location: 0
• Status: offline
Re: Newbie: controlling duty cycle of PWM set up with MCC 2018/05/29 14:12:51 (permalink)
0
BTW one issue I found with MCC was that I can't go back and fully undo the enabling of EUSART interrupts. Recall that I had mistakenly enabled these.  So in the Interrupt Module EUSART RCI and TXI interrupt is enabled and in the EUSART module Enable EUSART Interrupts is check. If I uncheck these and Generate again I get an error when I compile that certain items aren't available when they are expected by adc.p1. So I have left these checked but not enabled the Interrupts in my main (void) code.

`  #include "mcc_generated_files/mcc.h"#include <math.h>#include <stdio.h>#include <string.h>#include <stdlib.h>/* MAIN APPLICATION *///DEFINE GLOBAL CONSTANTS ETC#define NO_CASE (IRswitch_GetValue()==HIGH) //IR beam not blocked#define CASE (IRswitch_GetValue()==LOW) //IR beam blocked #define NTC_Balance_Resistor 4700 //Balance resistor used in NTC voltage divider#define Max_ADC 1023.0 //10 bit DAC#define Room_TempK 298.15 //25C in Kelvin x 100#define Res_Room_Temp 10000 //NTC resistance at 25C from data sheet #define Not_Over_Heating (High_Temp_Fan1 < Over_Temp || High_Temp_Fan2 < Over_Temp)eeprom int NTC_Beta = 3435; //NTC beta from data sheeteeprom int Over_Temp = 70; //Temperature limit for shutdowneeprom int DC50_Limit = 30; //Temperature limit for 50% duty cycle operationvoid main(void){ // initialize the device SYSTEM_Initialize();  // When using interrupts, you need to set the Global and Peripheral Interrupt Enable bits // Use the following macros to:// Enable the Global Interrupts //INTERRUPT_GlobalInterruptEnable();// Enable the Peripheral Interrupts //INTERRUPT_PeripheralInterruptEnable();// Disable the Global Interrupts //INTERRUPT_GlobalInterruptDisable();// Disable the Peripheral Interrupts //INTERRUPT_PeripheralInterruptDisable();  IRswitch_SetDigitalInput(); //Set up PIC pins and initial conditions TimerStart_SetDigitalOutput(); OvrTmpLED_SetDigitalOutput(); TimerStart_SetLow(); OvrTmpLED_SetLow();  char Switch_Cleared = 'N'; float Temp_NTC1=25; float Temp_NTC2=25; float Temp_NTC3=25; float Temp_NTC4=25; char Keyboard_Input; int Fan1_DC; int Fan2_DC;  float readNTC(adc_channel_t channel); //Declare functions int Set_Duty_Cycle(int Fan_Num, float Fan_Temp); void Send_String(const char *x); void Send_Welcome(void); void Send_Programming_String(void); void Send_Temps_DC(float Temp1, float Temp2, float Temp3, float Temp4, int DC1, int DC2); void Program_Constants(void);    while (1) //MAIN LOOP {  Temp_NTC1=readNTC(NTC1); //Read temperatures Temp_NTC2=readNTC(NTC2); Temp_NTC3=readNTC(NTC3); Temp_NTC4=readNTC(NTC4);  float High_Temp_Fan1=0; //Calculate max temp of NTC pairs if (Temp_NTC1>=Temp_NTC2){ High_Temp_Fan1=Temp_NTC1;} else High_Temp_Fan1=Temp_NTC2;  float High_Temp_Fan2=0; if (Temp_NTC3>=Temp_NTC4){ High_Temp_Fan2=Temp_NTC3;} else High_Temp_Fan2=Temp_NTC4;  Fan1_DC = Set_Duty_Cycle(1,High_Temp_Fan1); //Set duty cycle CCPR values and return duty cycles  Fan2_DC = Set_Duty_Cycle(2,High_Temp_Fan2);  Send_Welcome(); //Send welcome to RS232 connected PC Keyboard_Input=EUSART_Read(); //Monitor for keyboard instructions switch(Keyboard_Input){ case 'T': Send_Temps_DC(Temp_NTC1, Temp_NTC2, Temp_NTC3, Temp_NTC4, Fan1_DC, Fan2_DC); break; case 'P': Program_Constants(); break; }  if (Not_Over_Heating) //Maintain normal operation of optical switch and timer management {  OvrTmpLED_SetLow(); //Make sure Over-Temp LED is off if (CASE && (Switch_Cleared=='Y')) { for (int countDelay=0; countDelay <200; countDelay ++)__delay_ms(5); //Delay 1s for case to settle if (CASE) { TimerStart_SetHigh(); for (unsigned char countDelay=0; countDelay <20; countDelay ++)__delay_ms(5); TimerStart_SetLow(); } } else { if (NO_CASE) Switch_Cleared='Y';  }  } else //Overheating. Blink LED. Operation can't commence until no longer overheating. { OvrTmpLED_Toggle(); for (int countdelay=0; countdelay<20; countdelay++)__delay_ms(10); }} }//FUNCTIONS:  //Calculate temp at an NTC in degrees Celsiusfloat readNTC(adc_channel_t channel){ int ADC_value = ADC_GetConversion(channel); float rNTC1 = NTC_Balance_Resistor * ((Max_ADC / ADC_value)-1); float Temp = ((NTC_Beta * (Room_TempK)) /  (NTC_Beta + ((Room_TempK) * log(rNTC1 / Res_Room_Temp)))) - 273.15; return Temp;}//Set CCPR value for duty cycle and return Duty Cycleint Set_Duty_Cycle(int Fan_Num, float Fan_Temp){ float Temp_Increment = ((Over_Temp -10 - DC50_Limit)/10); float Adj_Temp = ((Fan_Temp - DC50_Limit)/Temp_Increment); int CCPR_Val=9; int Duty_Cycle; int Round_Adj_Temp = round(Adj_Temp); float Residual = (Adj_Temp-Round_Adj_Temp); if (Residual < 0) {CCPR_Val = (Round_Adj_Temp+9);}  else {CCPR_Val = (Round_Adj_Temp + 10);}  switch (Fan_Num){  case '1': PWM4_LoadDutyValue(CCPR_Val); break; case '2': PWM3_LoadDutyValue(CCPR_Val); break; }  Duty_Cycle = (19 - CCPR_Val)*5; return (Duty_Cycle);}//Send Stringvoid Send_String(const char *x){ while (*x) EUSART_Write(*x++);}//Send Welcome Stringvoid Send_Welcome(void){ Send_String("GinaErick Annealer software by SGK ver 1.0 May 20, 2018\n" "Copyright (c) protected. Non-commercial use only.\n"); Send_String("Type T to display NTC temperatures and fan duty cycles.\n"); Send_String("Type P to enter program mode.\n");}//Send Temperatures and Duty Cyclesvoid Send_Temps_DC(float Temp1, float Temp2, float Temp3, float Temp4, int DC1, int DC2){ Send_String("Temperatures in degrees Celsius)\n"); char buffer [10]; printf("NTC1 %.1f\n", Temp1); printf("NTC2 %.1f\n", Temp2); printf("NTC3 %.1f\n", Temp3); printf("NTC4 %.1f\n\n", Temp4); Send_String("Duty cycles in per cent.\n"); printf("Fan 1 %d\n", DC1); printf("Fan 2 %d\n", DC2); Send_String("\n\n"); Send_Welcome();}//Send Programming Stringvoid Send_Programming_String(void) { Send_String("Programming mode.\n"); printf("B for NTC beta = %d\n", NTC_Beta); printf("S for thermal protection limit degC = %d\n", Over_Temp); printf("F for temp limit for 50 per cent duty cycle fan operation = %d\n", DC50_Limit); Send_String("X to exit and return to normal operation.\n Integer values only, 2 digits for temps and 4 for beta.\n" "Fan duty cycle is 0-step linear progression from 50 up to the 50 per cent duty cycle limit\n" "to 100 per cent 10 degrees below the thermal protection limit.\n\n" "To change a constant: <Constant Code><Space><New Value><Return> \n\n"); }//Program key constantsvoid Program_Constants(void){ Send_Programming_String(); char Cmd[]="000000"; int i=0; char Input_Char = '£';  while (Input_Char != 'X') { //Process multiple commands until X while (Input_Char != 'X' && i < 6 && Input_Char != '\r'){ //Read up to 6 characters only and stop early if X or \r.  Input_Char = EUSART_Read(); Cmd[i] = Input_Char; i++; } i=0; if (Input_Char != 'X') { //Examine and process command. Skip if X was entered. if ((Cmd[0] == 'B' || Cmd[0] == 'S' || Cmd[0] == 'F') && (Cmd[1] == ' ')){ //Check command for input errors. switch (Cmd[0]) { case 'B':  NTC_Beta = atoi(Cmd+1); break; case 'S':  Cmd[4]=0; Over_Temp = atoi(Cmd+1); break; case 'F':  Cmd[4]=0; DC50_Limit = atoi(Cmd+1); break;  } Send_Programming_String(); } else { printf("INPUT ERROR\n\n"); Send_Programming_String(); } }   } }/** End of File*/`

PStechPaul
Super Member
• Total Posts : 3046
• Reward points : 0
• Joined: 2006/06/27 16:11:32
• Location: Cockeysville, MD, USA
• Status: offline
Re: Newbie: controlling duty cycle of PWM set up with MCC 2018/05/29 23:10:46 (permalink)
0
I see a few things that might cause problems. Here, there are two strings in the Send_String() function:
`Send_String("GinaErick Annealer software by SGK ver 1.0 May 20, 2018\n" "Copyright (c) protected. Non-commercial use only.\n");`

Also, you are using printf(), which might not be sending characters to the serial port.

I strongly suggest that you use the debug capability of the PICkit3 to trace execution.

Also, you should make a very simple project that does nothing more than send "Hello World" to the PC serial port and respond to a <CR> or any keyboard character. You can also test the menus by simulating serial input as I have shown.

Maybe some problems here:
`float rNTC1 = NTC_Balance_Resistor * ((Max_ADC / ADC_value)-1); float Temp = ((NTC_Beta * (Room_TempK)) /  (NTC_Beta + ((Room_TempK) * log(rNTC1 / Res_Room_Temp)))) - 273.15;`

This is what I have for temperature:

TdegC = T0DegK * B / ( T0DegK * LN( ( ADC * Rser ) / ( R0 * ( 2 ^ Bits ) - ADC ) ) ) + B ) - 273

post edited by PStechPaul - 2018/05/29 23:34:18

Page: << < ..678910.. > >> Showing page 6 of 14