romel_emperado
Advanced Member level 2
- Joined
- Jul 23, 2009
- Messages
- 606
- Helped
- 45
- Reputation
- 132
- Reaction score
- 65
- Trophy points
- 1,318
- Location
- philippines
- Activity points
- 6,061
unsigned int adc_read()
{
unsigned int adc_result;
ADCON0 = 0x00;
ADCON0bits.ADON = 1; //turn on adc
ADCON0bits.GO_DONE = 1; //start converstion
while(GO_DONE); //wait for converstion to finish
ADCON0bits.ADON = 0; //turn off adc
adc_result = ADRESH;
adc_result = (adc_result << 2) | (ADRESL>>6);
return adc_result;
}
any bit that is not 1 in ADRESL or ADRESH will be set to 0 in adc_result
how about if the value of my ADRESH is 0b11111111 then we do like this
adc_reault = ADRESH<<2;
Is this line not discarding the MSB of ADRESH since it is only 8bit size? im confused..
---------- Post added at 15:13 ---------- Previous post was at 15:12 ----------
does the adc_result still received the 0b11111111 value from ADRESH??
I shift my ADC result 2 times to feed my 8bit CCPR1L.Since you're bit-shifting your ADC reading 2 times right,
It's just that I want to read all the 10bit for future applications since I knew how to read when i need only 8bit result..why read a 10-bit at all?
It is also unnecessary to turn the ADC off and then turn it on again.
if you see my code i have placed (unsigned int) in front of the ADRESH and this is telling the compiler to treat it as a 16bit variable and then do the shifting, this way there is no change for the MSB to be lost.
By using right-justification, you only need to carry out bit-shift once.
adc_result = ADRES;
adc_result = (ADRESH << 8) + ADRESL;
adc_result = (ADRESH << 8) | ADRESL;
No problem. You can use left-justification and get 10-bit value. The justification is just a representative method for displaying the results. But the result is the same if left or right justification is used, only the way it is presented is different. I think you already know this.
Hope this helps.
Tahmid.
No problem. You can use left-justification and get 10-bit value. The justification is just a representative method for displaying the results. But the result is the same if left or right justification is used, only the way it is presented is different. I think you already know this.
Hope this helps.
Tahmid.
PWM output: PWM resolution is 1 to 10-bit
Hi what does this mean
where I can get that 10bit resolution? in the microcontroller physical pins? sorry Im confused..
15.4.2 PWM DUTY CYCLE
The PWM duty cycle is specified by writing to the
CCPRxL register and to the CCPxCON<5:4> bits. Up
to 10-bit resolution is available. The CCPRxL contains
the eight MSbs and the CCPxCON<5:4> bits contain
the two LSbs. This 10-bit value is represented by
CCPRxL:CCPxCON<5:4>. The following equation is
used to calculate the PWM duty cycle in time:
The 10-bits of resolution refers to the duty cycle of the PWM and is formed by the concatenation of both the CCPRxL register and to the CCPxCON<5:4> bits.
I assume we're still discussing the 18F4550.
Reference PIC18F2455/2550/4455/4550 Data Sheet, pg. 148, 15.4.2 PWM DUTY CYCLE
Has anyone discussed the meaning of the term "resolution" with you? Or do you already understand the term?
so meaning the Input of my PWM range from 0 to 1023?The 10-bits of resolution refers to the duty cycle of the PWM
yes I understand about reso..
so meaning the Input of my PWM range from 0 to 1023?
still unclear to me.. CCPR1L is the 8bits MSB register of my PWM then the remaining two bits is in the CCPxCON<5:4> register then for example let's have this scenario
CCPR1L(8bits) + CCPxCON<5:4>(2bits) = 10bit resolution right?
so If Im going to put a 3 value for my duty cycle where do I put that? in CCPR1L which is the MSB or in the CCPxCON<5:4> which is the LSB ?
if you are going to ask me hehe since the value is 3 then I can place that to the LSB or in CCPxCON<5:4>... that confuses me If Im correct... hehe
yes I read about this but I dont know how to apply.. heheIf you want to take full advantage of the 10-bits of resolution, you would set both the CCPxCON<5:4> bits,
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?