Performance of ATMega vs PIC Microcontrollers.

Thread Starter

Manu Sisko

Joined Sep 24, 2018
10
Hello. I'm currently developing my thesis project for which I'm using a PIC 18f2550 to do some things:
- Sample 2 signals, one at 1.6kHz and the other at 3.2kHz, both with the TIMER0.
- Communicate with my PC via the USB, receive commands and reply data at 1.6kHz. Done with TIMER1.
- Control valves, and pumps with PWM. Duty Cycle is calculated from the information present in the sampled signals. I'm doing this with TIMER0 also.
However I'm facing a difficulty. If I try to speed up the PWM modulation a bit it hinders my analog sampling. If I use the PWM sequence more often it starts doing some funny stuff with my analog samples (increases noise, modifies offsets and such). No matter what I do I cannot seem to enhance the pic's performance. RIght now I'm using CCS to program and the PIC is at it's maximum 12 MIPS. And I cannot use the CCP module as at this clock frequency the minimum PWM frequency is rather high for my application requirements.

My question is: I've seen AtMega chips can handle 20 MIPS, and I've been experiencing funny unreliable ADC behaviour for a while with my PIC. Is it worth changing to an AtMega or even an assembled arduino? What's AVR's performance like compared to PICs in general?
 

Thread Starter

Manu Sisko

Joined Sep 24, 2018
10
Use a chip with hardware PWM's - Microchip has many with multiple hardware PWM engines.
Doing it in software is always painful.
Thanks, I wasn't aware of Hardware PWM! That seems like a beautiful solution.

By heart, the 18F4431 is full of possibilities to do PWM with lots of variations. Sure much more than you seem to need.
That one chip doesn't appear to have a USB module, as far as I can tell. Is there any other similar to 18f2550 with HW PWM? or if you know of a nice tool to find PICs from it's requirements that'd be very helpful-
 

AlbertHall

Joined Jun 4, 2014
12,619
For PICs you have a simulator and debugger to allow you to set breakpoints, view and change variables and registers etc.
You have none of this for arduino. The best you can do is to serial port messages back to the PC.
 

atferrari

Joined Jan 6, 2004
5,002
Thanks, I wasn't aware of Hardware PWM! That seems like a beautiful solution.



That one chip doesn't appear to have a USB module, as far as I can tell. Is there any other similar to 18f2550 with HW PWM? or if you know of a nice tool to find PICs from it's requirements that'd be very helpful-
Sorry, I overlooked that. And also the fact that the very 18F2550 has 2, IIRC, hardware PWM peripherals staring at you. RTFM...:)

Buena suerte.
 

Thread Starter

Manu Sisko

Joined Sep 24, 2018
10
Sorry, I overlooked that. And also the fact that the very 18F2550 has 2, IIRC, hardware PWM peripherals staring at you. RTFM...:)

Buena suerte.
Haha yeah they do, but they work with the CCP modules. I'm not sure if other hardware PWM modules work in the same fashion but in this case, as I stated, the CCP module uses Timer2 and due to the prescaler values available and my clock frequency of 48Mhz, the CCP module can generate a minimum PWM frequency of 1700 Hz (ish, long time since I had made the calculation), and it would have a terrible duty cycle resoluton at this level. I would need to fiddle with the Timer2 register in order to increase the prescaler by software, which at that point it would be simpler to manipulate the PWM myself altogether.

EDIT: I'm driving GNC car electrovalves with this PWM, they require quite a large current (4 amp max), and if I toggle them too fast, the solenoids put too much stress on the MOSFETs that drive them. Hence, my need for a low frequency pwm with decent duty cycle resolution.
 
Last edited:

atferrari

Joined Jan 6, 2004
5,002
Haha yeah they do, but they work with the CCP modules. I'm not sure if other hardware PWM modules work in the same fashion but in this case, as I stated, the CCP module uses Timer2 and due to the prescaler values available and my clock frequency of 48Mhz, the CCP module can generate a minimum PWM frequency of 1700 Hz (ish, long time since I had made the calculation), and it would have a terrible duty cycle resoluton at this level. I would need to fiddle with the Timer2 register in order to increase the prescaler by software, which at that point it would be simpler to manipulate the PWM myself altogether.

EDIT: I'm driving GNC car electrovalves with this PWM, they require quite a large current (4 amp max), and if I toggle them too fast, the solenoids put too much stress on the MOSFETs that drive them. Hence, my need for a low frequency pwm with decent duty cycle resolution.
Pity, because a wider range, the proposed F4431 has it. But then, had I to solve this, I would try to go by tweaking the existing HW via the timer, (if possible of course) prior resorting to a software solution.

Sorry but leaving to Patagonia tomorrow I cannot revise my own software.
 
Top