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
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
What could help here ..?
Quite complex to describe, but I can help any further questions.