Thanks JS,
The Code does not make any calibration, No matter what I put in startup code, I have done all the possible combinations!
That's very strange, let's investigate.
First check: Please check that you use latest "pfs173.h"
You can verify when you look in pfs173.h and find the following lines:
//set calibration macros
#define EASY_PDK_CALIBRATE_IHRC(frequency,millivolt) EASY_PDK_CALIBRATE_RC_M( EASY_PDK_CALTYPE_IHRC, 0x0B, frequency, millivolt )
Next check: Do you use the latest version of easypdk prog?
You can check by adding the -v option to easypdkprog command line:
easypdkprog -v --icname=PFS173 write build/lvrstartup.ihx
Searching programmer... found: /dev/tty.usbmodem1234567855AA1
FREE-PDK EASY PROG - HW:1.2 SW:1.3 PROTO:1.3
Erasing IC... done.
Blank check IC... done.
Writing IC (1592 words)... done.
Verifiying IC... done.
Calibrating IC
* IHRC SYSCLK=8000000Hz @ 5.00V ... calibration result: 8021146Hz (0x80) done.I also found a mistake in the _sdcc_external_startup code.
* MISCLVR is set to trigger <= 4.5V
* calibration is done at 4000 mV = 4.0 V
==> this means calibration can not be done (should give an ERROR)
==> change calibration voltage to your target system voltage of 5V:
unsigned char _sdcc_external_startup(void)
{
MISCLVR = MISCLVR_4V;
EASY_PDK_INIT_SYSCLOCK_8MHZ(); //use 8MHz sysclock
EASY_PDK_CALIBRATE_IHRC(8000000,5000); //tune SYSCLK to 8MHz @ 5.000V
EASY_PDK_USE_FACTORY_BGTR(); //use factory BandGap tuning value (tuned @ 5.0V)
return 0; //perform normal initialization
}I also made some experiments:
- when setting SYSCLOCK to 8MHz you need to have >=4.0V
- when you power the system with external power supply and slowly increase voltage from 0V to 5V the IC *WILL HANG* (that's why the LVR should be added)
- adding the LVR setup just in front of the EASY_PDK_INIT_SYSCLOCK is enough to get a stable startup even when you slowly increase voltage from 0V to >=4.0V
unsigned char _sdcc_external_startup(void) {
MISCLVR = MISCLVR_4V; //set minimum voltage for 8MHz sysclock (lower voltage will reset IC)
EASY_PDK_INIT_SYSCLOCK_8MHZ(); //use 8MHz sysclock
EASY_PDK_CALIBRATE_IHRC(8000000,5000); //tune SYSCLK to 8MHz @ 5.000V
return 0; //perform normal initialization
}
Now I'm thinking if we should add setting LVR to the INIT_SYSCLOCK macro...
JS