Flakpanzers and other vehicle mounted anti-aircraft guns were frequently used against ground targets, and this was in fact noted explicitly by the Military Intelligence Service in their periodic Intelligence Bulletins. The following is an excerpt they report as originating from a German anti-aircraft platoon commander:
c. Action During Attack
The antiaircraft-antitank troops support the advance of the infantry
and other arms. For this purpose the antiaircraft- antitank guns
should be sited to a flank, to exploit their range fully without
endangering the advancing German troops. The addition of 100 yards,
more or less, to a flank hardly interferes with the effectiveness of
the 20-mm gun, whereas it does affect the enemy's infantry weapons by
widening the target.1
The use of anti-aircraft weapons against infantry appears to be at very least an informal doctrine in the German military, as they also include in the same intelligence briefing this account cited as coming from a German newspaper:
The antiaircraft-antitank units (the platoon is the normal fighting
unit) are located in the column of march according to the prearranged
operation order. In case of surprise attack, fife is opened either
immediately from the tractor on which the gun is mounted, or else
sections (which are fully motorized) leave the column and occupy a
position on firm ground with a good field of fire, with the gun
dismounted. After fighting, the units catch up with their original
position in the line of march.2
There are also numerous first person accounts, for example this one from John Angier describing an action in Alsace-Lorraine in late 1944 when serving with the 100th Infantry Division:
At 0500, 9 December, the first of four hit and run flak-wagon attacks
came, with his 20-mm blasting away. Rumbled right up to the foxholes.
What a miserable helpless feeling that must be! Then two more attacks
came off on schedule. Both of them to feel us out and each time Jerry
would get a little bolder. When he saw that he was getting no return
fire from anti-tank guns or tanks, which we didn't have, then came the
real thing. Each time he rolled up, we tried in vain to knock him out
with a bazooka.3
Even more effective than the light calibre anti-aircraft guns were the eighty-eights, which were used against ground targets throughout the war. For example against the British and French during the Battle of France in 1940...
The resulting Battle of Arras achieved surprise and initial success
against German forces which were stretched, but it still failed.
Radio communication between tanks and infantry was poor and there was
little combined arms coordination as practiced by the Germans. In the
end, hastily set up German defences (including 88 mm (3.46 in) FlaK
guns and 105 mm (4.1 in) field guns) stopped the attack.4
...and in countless other engagements from North Africa to the Eastern Front.
As to your follow-up question, whether there was a different type of tank used to counter infantry, the obvious answer is that any tank is useful in countering infantry. That said, there were some purpose built mobile howitzers and assault guns such as the Sturmgeschütz III or the Wespe, but these were frequently pressed into anti-tank roles.
1 Military Intelligence Service, United State War Department, 1943-02 Intelligence Bulletin Vol 01 No 06, p 39
2 ibid. p 41
3 Angier, John C., A 4F Goes to War with the 100th Infantry Division, p 50
4 Smith, James, Western Front: The Second World War, p 84