adc sync from pwm - bug? - ADC sync on 56F8013

cancel
Showing results for 
Search instead for 
Did you mean: 

adc sync from pwm - bug? - ADC sync on 56F8013

6,345 Views
Egal
Contributor I

Hi,

I want to sync the adc from pwm with a timer trigger source.

Since I have updated to CW 7.3 I get the following error message after configuring the beans.

+AD1
+ERROR: The 'PWM' would be selected in TMR channel 3 input item of the TMR4 or CPU bean because of synchronization from PWM device.
+AD1
+ERROR: There are errors in this bean, it is impossible to generate code

What`s wrong?

At the moment I am triggering the adc with a timer. But I think it works irregular. The adc do not sample with always the same interval.

What`s the trick to get samples from the adc in always the same interval?

Alban updated title

Message Edited by Alban on 2006-08-10 09:22 AM

Labels (1)
Tags (1)
0 Kudos
10 Replies

233 Views
Egal
Contributor I
Thank you for the full descripton.

But these steps are exactly the same I have already done.

The count direction is up; so I put "800" (32MHz/20kHz*0,5=800) into the "timer compare register 1", the load register is 0.
The output mode is set to "toggle OFLAG output on successful compare". Operation mode is "count mode". The timer device is TMR3, using a 56F8013VFAE dsp.

I put the following simple code into the OnEnd event:

...
SampleCounter += 1;
if (SampleCounter == 20000-1)
{
SampleCounter = 0;
LEDs_NegBit(3);
}
...


The led should flash every second. It does. But it gets irregular.
I am a newbie, but I think the adc do not sample with always the same interval.

What`s going wrong?

Many thanks.
0 Kudos

233 Views
ProcessorExpert
Senior Contributor III
There might be a problem that the ADC interrupt routine might be longer that the sampling cycle so there are some samples missed. Do you do something else in the OnEnd event?
It might be also other interrupt(s) that prevents the ADC interrupt to occur. In this case you can try to increase the priority of the ADC interrupt.
best regards
Petr Hradsky
Processor Expert Support Team
UNIS
0 Kudos

233 Views
Egal
Contributor I
I have tried to increase the priority of the adc interrupt - same problem.

Another timer controls another led every second. So, I can see a irregular flashing very easily.
I think there are some adc samples missed, because the flashing gets slower.

In addition to the above code in the OnEnd event, there is only a command to get the value from the adc.

That seems funny to me. I do not know the mistake. There is a trick, isn`t it?

Perhaps a secondary question.
IPBUs: 32 Mhz
max analog frequency: 10 kHz -> sample frequency: 20 kHz
How do I have to configure the timer registers? (load, compare)

32Mhz/20kHz/2 = 800

tnx
0 Kudos

233 Views
ProcessorExpert
Senior Contributor III
Please try to compare your project with the attached one. Tha attached project uses the 10kHz sampling - your value of the load register will be different: 800 instead of 1600.
I have tried it also configured to this way and it seems working correctly.
best regards
Petr Hradsky
Processor Expert Support Team
UNIS
0 Kudos

233 Views
Egal
Contributor I
Thank you for looking after my problem.

I have downloaded your file and added my simple code. But the problem always exists.
So, please have a look to the attached file - it is my test-code.

I am using the 56F8013 Demonstration Board with six on-board LEDs. Every second, two leds signal the measurement of 20000 samples and the sequence of another timer. The leds should flash synchronously, but after a minute they get irregular.

I have also compared the configuration of your project. But everything is correct.

Thanks a lot!
0 Kudos

233 Views
Egal
Contributor I
Well, no answer yet?
Perhaps it is a simple problem, but I do not know the answer to solve it. I would be very happy, if you can help me.

Tnx.
0 Kudos

233 Views
ProcessorExpert
Senior Contributor III
You are right, there is a small difference between the TimerInt period and the ADC sync period. I found the cause of this problem.
The triggering period is one tick longer than it should be. It's necessary to set the Timer Load register to the value one less than the number that's necessary to count. It's because the last pulse (number 0) that appears before the succesfull compare with the register reloads the counter is also counted to the interval.
For example when we need to count 800 pulses, it's necessary to set 799 instead of 800.
After adjusting the 'Timer Load register' to 799 instead of 800 in the TMR4 bean inspector the LEDs started to blink synchronously.
best regards
Petr Hradsky
Processor Expert Support Team
UNIS
0 Kudos

233 Views
Egal
Contributor I
Well, I have changed the "Timer Load register" to 799.

The first seconds the LEDs blink synchronously, but after about half a minute the LEDs start to blink irregular.

I have to secure that the adc samples with always the same time interval. It`s nothing special, isn`t it? Everbody who wants to sample an anlog signal have to do this. How do others solve it?
0 Kudos

233 Views
ProcessorExpert
Senior Contributor III
I'm sorry I forgot that I made one more fix to your project. There was an error in your software counters:
Your code was:
...
 SampleCounter += 1;
 if (SampleCounter == 20000-1) /* 20000 samples per second */  // in fact, 19999 only!
   { .....
But this code counts only 19999 pulses, since you are testing just after increasing the counter:
I changed it to:
....
 SampleCounter += 1;
 if (SampleCounter == 20000) /* 20000 samples per second */
   { .....
 
This problem was in both ADC OnEvent and TimerInt OnInterrupt and since you are counting different timer periods, the timing got un-synced after a while as well.
I was testing this projet for more that one hour and the LEDs were still synchronous. For sure, I attach the whole project to this message, you can try it.
best regards
Petr Hradsky
UNIS
0 Kudos

233 Views
ProcessorExpert
Senior Contributor III
Hello,
The ADC channel is internally connected to a specific timer channel which can be used for triggering. This channel has to be selected in the bean configuring the timer. Processor Expert automatically checks this - that's probably where the error comes from.

You can use the ADC synchronization configuration wizard in Processor Expert 2.97 in CodeWarrior 7.3. These stops show how to set it up:

- Add ADC bean into the project
- Configure the ADC bean channels, conversion time etc.
- Switch to the Expert mode of the Bean Inspector (using the Expert button)
- Then click on the '...' dialog button in the property 'Trigger
configuration wizard'
- Answer the wizard's questions.
- As the result a new bean is created and preset to synchronize the
ADC.
- Setup the 'Timer Load Register'.
This register controls the length of the period of the timer
output toggling.

E.g. for prescaler 1 and IPBus freq. 32MHZ, it will be: 32 MHz / 10kHz = 3200.
We need to divide this by two because the output has to toggle twice within
one period. So the time will be 1600 IPBUs ticks.

- Generate code and place a code reading the value into the OnEnd event code
of the ADC bean.

- In the main() function, the synchronization has to be enabled by calling
AD1_EnableIntTrigger(); method of ADC bean in the beginning of the main routine.

I hope that this will help.
There are also some information on hardware background in the following application note: http://www.freescale.com/files/product/doc/AN1933.pdf

best regards
Petr Hradsky
Processor Expert Support Team
UNIS
0 Kudos