ADC transfer from 12F675 to 12F683

Discussion on projects that are created by users and posted on mikroElektronika website.
Post Reply
Author
Message
el.patron
Posts: 11
Joined: 21 Dec 2012 14:21

ADC transfer from 12F675 to 12F683

#1 Post by el.patron » 17 Jun 2023 22:43

I have a strange problem.
Some time ago I set up a steering wheel interface with an 12F675, see viewtopic.php?f=147&t=64697

Years later I changed the radio to a more modern one, but now would need a PWM module, to interface that new radio. as the 12F675 misses PWM I picked the 12F683.

Transfering the code is quite straight forward, but I have a strange problem.

I use the ADC to read the voltage from a resistor network connected to the steering wheel buttons. Works fine, and brings 6 values in a quite nice row within the 10 bits of the ADC.

In the imlementation with the 12F675 I used the ADC value to shrink it down to an index [0 .. 10], with that I access a vector for picking up further data. With the new radio I want to use the values to drive the PWM output. Looks like:

Code: Select all

     temp = ADC_Read(ANS2);          // ADC conversion
     state = ((temp+40)*3)>>8 ;       // scaling to an index
     PWM1_Set_Duty(pwmv[state]);  // use the index to pick up an element of pwmv for correct duty cycle corresponding to the respective button
Getting the index called state works perfectly on the 12F675, but brings strange results on the 12F683. Hard to debug and hard to describe, but the bit shifting to the right does not get the correct index.
When fitting the ADC result directly back to PWM, this somehow reveals the correct ADC-value

Code: Select all

    temp = ADC_Read(ANS2);        // ADC conversion
    PWM1_Set_Duty(temp/4);       // directly fit to PWM
but shifting the ADC output to an index I'm not getting to work. Also dividing instead of shifting does not help :(

What could help here ..?

Quite complex to describe, but I can help any further questions.

el.patron
Posts: 11
Joined: 21 Dec 2012 14:21

Re: ADC transfer from 12F675 to 12F683

#2 Post by el.patron » 18 Jun 2023 20:21

o.k. got it. Is really strange. Here are some reads from the ADC:

Code: Select all

0000000011111101
0000000101010110
0000000110101110
0011111000001011
0011111001100111
0011111011000001
0011111101011111
Only the right 10 bits are valid from the ADC. Why there are 1's on the left side mixed in? I guess a bug in the PIC or the Compiler. The only way to get rid of this I came up with is per type cast:

Code: Select all

      state = (unsigned short)((temp+40)>>2);
      state = ((state >>2)*3)>>4;
Shift the 10bit ADC value by 2 bits to the right, so that it fits in one byte, type cast to unsigned short, and continue from there. Quite tricky compared to the 12F675...

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: ADC transfer from 12F675 to 12F683

#3 Post by filip » 21 Jun 2023 08:18

Hi,

Have you tried bypassing the ADC library functions, i.e. implementing your own ADC readings just to narrow down the problem ?

Regards,
Filip.

el.patron
Posts: 11
Joined: 21 Dec 2012 14:21

Re: ADC transfer from 12F675 to 12F683

#4 Post by el.patron » 21 Jun 2023 20:23

I did not investigate further, as it worked as I described. I could give it a try, if you have some easy to use hints how to accomplish 😉

el.patron
Posts: 11
Joined: 21 Dec 2012 14:21

Re: ADC transfer from 12F675 to 12F683

#5 Post by el.patron » 22 Jun 2023 19:01

after call to the library function ADC_Read, I read out the ADRESH and ADRESL bytes, and the effect is also there. Is that enough for any conclusion?

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: ADC transfer from 12F675 to 12F683

#6 Post by filip » 29 Jun 2023 09:15

Hi,

I will check what is going on.

Regards,
Filip.

Post Reply

Return to “User Projects”