opt: rename ADC_SetClockPrescaler()

This commit is contained in:
IOsetting 2022-01-08 23:58:12 +08:00
parent 2e14c6415d
commit 470b0ec2f9
5 changed files with 15 additions and 9 deletions

View File

@ -50,7 +50,7 @@ void main(void)
// Channel: ADC1 // Channel: ADC1
ADC_SetChannel(0x01); ADC_SetChannel(0x01);
// ADC Clock = SYSCLK / 2 / (1+15) = SYSCLK / 32 // ADC Clock = SYSCLK / 2 / (1+15) = SYSCLK / 32
ADC_SetSpeed(0x0F); ADC_SetClockPrescaler(0x0F);
// Right alignment, high 2-bit in ADC_RES, low 8-bit in ADC_RESL // Right alignment, high 2-bit in ADC_RES, low 8-bit in ADC_RESL
ADC_SetResultAlignmentRight(); ADC_SetResultAlignmentRight();
// Enable interrupts // Enable interrupts

View File

@ -68,7 +68,7 @@ void main(void)
// Channel: ADC1 // Channel: ADC1
ADC_SetChannel(0x01); ADC_SetChannel(0x01);
// ADC Clock = SYSCLK / 2 / (1+15) = SYSCLK / 32 // ADC Clock = SYSCLK / 2 / (1+15) = SYSCLK / 32
ADC_SetSpeed(0x0F); ADC_SetClockPrescaler(0x0F);
// Right alignment, high 2-bit in ADC_RES, low 8-bit in ADC_RESL // Right alignment, high 2-bit in ADC_RES, low 8-bit in ADC_RESL
ADC_SetResultAlignmentRight(); ADC_SetResultAlignmentRight();
// Enable interrupts // Enable interrupts

View File

@ -40,7 +40,7 @@ void main(void)
// Channel: ADC1 // Channel: ADC1
ADC_SetChannel(0x01); ADC_SetChannel(0x01);
// ADC Clock = SYSCLK / 2 / (1+1) = SYSCLK / 4 // ADC Clock = SYSCLK / 2 / (1+1) = SYSCLK / 4
ADC_SetSpeed(0x01); ADC_SetClockPrescaler(0x01);
// Right alignment, high 2-bit/4-bit in ADC_RES, low 8-bit in ADC_RESL // Right alignment, high 2-bit/4-bit in ADC_RES, low 8-bit in ADC_RESL
ADC_SetResultAlignmentRight(); ADC_SetResultAlignmentRight();
// Turn on ADC power // Turn on ADC power

View File

@ -40,7 +40,7 @@ void main(void)
// Channel: ADC1 // Channel: ADC1
ADC_SetChannel(0x01); ADC_SetChannel(0x01);
// ADC Clock = SYSCLK / 2 / (1+1) = SYSCLK / 4 // ADC Clock = SYSCLK / 2 / (1+1) = SYSCLK / 4
ADC_SetSpeed(0x01); ADC_SetClockPrescaler(0x01);
// Left alignment, high 8-bit in ADC_RES // Left alignment, high 8-bit in ADC_RES
ADC_SetResultAlignmentLeft(); ADC_SetResultAlignmentLeft();
// Turn on ADC power // Turn on ADC power

View File

@ -59,14 +59,20 @@
#define ADC_SetResultAlignmentRight() SFR_SET(ADCCFG, 5) #define ADC_SetResultAlignmentRight() SFR_SET(ADCCFG, 5)
/** /**
* ADC conversion speed calculation: * Time of one complete ADC conversion:
* 10-bit ADC Frequency SYSCLK / 2 / (SPEED + 1) / [(Switch + 1) + (Hold + 1) + (Sample + 1) + 10] * 10-bit ADC: (Switch + 1) + (Hold + 1) + (Sample + 1) + 10
* 12-bit ADC Frequency SYSCLK / 2 / (SPEED + 1) / [(Switch + 1) + (Hold + 1) + (Sample + 1) + 12] * 12-bit ADC: (Switch + 1) + (Hold + 1) + (Sample + 1) + 12
*
* ADC conversion frequency:
* 10-bit ADC Frequency SYSCLK / 2 / (__PRESCALER__ + 1) / [(Switch + 1) + (Hold + 1) + (Sample + 1) + 10]
* 12-bit ADC Frequency SYSCLK / 2 / (__PRESCALER__ + 1) / [(Switch + 1) + (Hold + 1) + (Sample + 1) + 12]
*
*/ */
/** /**
* ADC clock = SYSclk/2/(SPEED+1) * ADC clock = SYSclk/2/(__PRESCALER__+1)
*/ */
#define ADC_SetSpeed(__SPEED__) (ADCCFG = ADCCFG & ~0x0F | ((__SPEED__) << 0)) #define ADC_SetClockPrescaler(__PRESCALER__) (ADCCFG = ADCCFG & ~0x0F | ((__PRESCALER__) << 0))
/** /**
* Channel switch time, * Channel switch time,