Hello,
I try to evaluate S12ZVL.
And , I want to use ADC for S12ZVL.
But, the ADC module in the S12ZVL is different from S12 MCU for example S12VR.
Is there ADC sample code for S12ZVL ?
Best regards.
Okuoka.
hi i am deepak ,
controller -s12zvl32 48 pin .
i am trying to use internal temperature sensor and battery sensing but i didn't get any result i have try your last post code didn't work
if you have any example code for adc please upload .
best regards
deepak
Hi Martin-san,
I'm sorry for late reply.
I succeeded in coding with ADC thanks to your advice.
Thank you very much !
Best regards.
Okuoka.
Hi,
Indeed the S12Z MCU's use the List Based Architecture (LBA) provides flexible conversion sequence definition as well as flexible oversampling.
The order of channels to be converted can be freely defined. Also, multiple instantiations of the module can be triggered simultaneously (matching sampling point across multiple module
instantiations).
There are four register bits which control the conversion flow (please refer to the description of register ADCFLWCTL).
The four conversion flow control bits of register ADCFLWCTL can be modified in two different ways:
• Via data bus accesses
• Via internal interface Signals (Trigger, Restart, LoadOK, and Seq_Abort; see also Figure 9-2).
Each Interface Signal is associated with one conversion flow control bit.
The ADCFLWCTL register can be controlled via internal interface only or via data bus only or by both depending on the register access configuration bits ACC_CFG[1:0].
For more information check the MC912ZVL Family Reference Manual
I will attach basic ADC code for the TRK-S12ZVL.
http://www.freescale.com/webapp/sps/site/prod_summary.jsp?code=TRK-S12ZVL
Varying the potentiometer connected to AN0 pin, you will see how the RGB LED changes its color.
So far see below the functions for the ADC0 module:
void ADC_init(void){
adc0_cmdlist[0] = CMD_SEL(0)+INTFLG_SEL(1)+VRH_SEL(1)+VRL_SEL(1)+CH_SEL(12);
// CMD_SEL(0) -> Normal Conversion
// INTFLG_SEL(1) -> Conversion Interrupt Flag Select [1]
// VRH_SEL(1) -> VRH_1 input selected as high voltage reference.
// VRL_SEL(1) -> VRL_1 input selected as low voltage reference.
// CH_SEL() -> ADC Internal4 Channel Select VSUP 001100
adc0_cmdlist[1] = CMD_SEL(3)+INTFLG_SEL(2)+VRH_SEL(1)+VRL_SEL(1)+CH_SEL(16);
// CMD_SEL(1) -> End Of List
// INTFLG_SEL(1) -> Conversion Interrupt Flag Select [2]
// VRH_SEL(1) -> VRH_1 input selected as high voltage reference.
// VRL_SEL() -> VRL_1 input selected as low voltage reference.
// CH_SEL() -> ADC0 Input Channel Select
// Clear ADC results list -----------------------------------------------------------
for (index = 0; index < 2; index++){
adc0_results[index] = 0;
}
// Configure ADC0 control -----------------------------------------------------------
ADC0CTL_0_ACC_CFG = 3; // set dual-access mode */
ADC0CTL_0_MOD_CFG = 1; // select "Trigger Mode" */
ADC0CTL_1 = 0x00; // single CSL & RVL buffers, Normal access, No Auto-Restart after exit from STOP */
ADC0STS = 0x00; // select CSL 0 and RVL 0
ADC0TIM = 0x05; // f_ATDCLK = 32Mhz/(2 x (ADC0TIM_PRS+1)) = 4Mhz
// Configure pointers to ADC0 CSL & RVL ----------------------------------------------
ADC0CBP = adc0_cmdlist;
ADC0RBP = adc0_results;
// Configure 10-bit resolution and right data justification */
ADC0FMT = 0x82;
// Configure BATS Module (BATE) ---------------------------------------------------
BATE_BSUAE = 1; // BATS VSUP ADC Connection Enable
// Start conversion -- ADC0 ---------------------------------------------------------
ADC0CTL_0_ADC_EN = 1; // Enable the ADC
ADC0FLWCTL_RSTA = 1; // Restart from top of active Sequence Command List.
while(0x07 != ADC0CONIF){} // wait until conversion is complete
ADC0CONIF = ADC0CONIF; // clear flag
}
void ADC_read(void){
ADC0FLWCTL_TRIG = 1; // trigger conversion
while(0x07 != ADC0CONIF){} // wait until conversion is complete
VSUP = adc0_results[0]; // Read results ADC Internal Channel VSUP
ADCPOT = adc0_results[1]; // Read results ADC Internal Channel AN0_0
ADC0CONIF = ADC0CONIF; // clear flag
if(ADCPOT < 171)
PTP = LED_OFF; // LED OFF
else if(ADCPOT >= 171 && ADCPOT <= 340)
PTP = LED_G; // LED Green
else if(ADCPOT >= 340 && ADCPOT <= 512)
PTP = LED_Y; // LED Yellow
else if(ADCPOT >= 512 && ADCPOT <= 682)
PTP = LED_B; // LED Blue
else if(ADCPOT >= 682 && ADCPOT <= 853)
PTP = LED_P; // LED Purple
else if(ADCPOT >= 853 && ADCPOT <= 1023)
PTP = LED_R; // LED Red
}